Skip to content

Commit

Permalink
Adding caching to streamlit demos (#14232)
Browse files Browse the repository at this point in the history
* Delete examples/demos/streamlit/CLIPForZeroShotClassification/inputs directory

* Add files via upload

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Update streamlit_app.py

* Delete examples/demos/streamlit/run_demos.ipynb

* Add files via upload
  • Loading branch information
AbdullahMubeenAnwar authored May 24, 2024
1 parent e0e28e8 commit 262b802
Show file tree
Hide file tree
Showing 50 changed files with 60 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model, labels):

image_assembler = ImageAssembler() \
Expand Down Expand Up @@ -121,4 +122,4 @@ def save_uploadedfile(uploadedfile):
Pipeline = create_pipeline(model, lables)
output = fit_data(Pipeline, selected_image)

st.markdown(f'This document has been classified as : **{output}**')
st.markdown(f'This document has been classified as : **{output}**')
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
document_assembler = DocumentAssembler()\
.setInputCol("text")\
Expand Down Expand Up @@ -100,4 +101,4 @@ def fit_data(pipeline, data):
output = fit_data(Pipeline, selected_text)

st.subheader('Prediction')
st.write(output)
st.write(output)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
document_assembler = DocumentAssembler()\
.setInputCol("text")\
Expand Down Expand Up @@ -101,4 +102,4 @@ def fit_data(pipeline, data):
output = fit_data(Pipeline, selected_text)

st.subheader('Prediction')
st.write(output)
st.write(output)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
documenter = DocumentAssembler()\
.setInputCol("text")\
Expand Down
1 change: 1 addition & 0 deletions examples/demos/streamlit/Sentence Grammer/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
documentAssembler = DocumentAssembler() \
.setInputCol("text") \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
document_assembler = DocumentAssembler()
document_assembler.setInputCol('text')
Expand Down Expand Up @@ -150,4 +151,4 @@ def get_similarity(light_pipeline, input_list):
else:
similarity_str = "not similar"
st.markdown(f'Detected similarity: **{similarity}%**')
st.markdown(f'These sentences are **{similarity_str}**.')
st.markdown(f'These sentences are **{similarity_str}**.')
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
documentAssembler = DocumentAssembler()\
.setInputCol("text")\
Expand Down Expand Up @@ -104,4 +105,4 @@ def fit_data(pipeline, data):
if output.lower() in ['neutral', 'normal']:
st.markdown("""<h3>This seems like a <span style="color: green">{}</span> tweet. <span style="font-size:35px;">&#128515;</span></h3>""".format(output), unsafe_allow_html=True)
elif output.lower() in ['racism', 'sexism']:
st.markdown("""<h3>This seems like a <span style="color: #B64434">{}</span> tweet. <span style="font-size:35px;">&#129324;</span></h3>""".format(output), unsafe_allow_html=True)
st.markdown("""<h3>This seems like a <span style="color: #B64434">{}</span> tweet. <span style="font-size:35px;">&#129324;</span></h3>""".format(output), unsafe_allow_html=True)
1 change: 1 addition & 0 deletions examples/demos/streamlit/Sentiment DA/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
document = DocumentAssembler()\
.setInputCol("text")\
Expand Down
1 change: 1 addition & 0 deletions examples/demos/streamlit/Sentiment DE/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
document = DocumentAssembler()\
.setInputCol("text")\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
documentAssembler = DocumentAssembler()\
.setInputCol("text")\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
document = DocumentAssembler()\
.setInputCol("text")\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
documentAssembler = DocumentAssembler()\
.setInputCol("text")\
Expand Down Expand Up @@ -101,4 +102,4 @@ def fit_data(pipeline, data):
if output in ['neutral', 'normal']:
st.markdown("""<h3>This seems like <span style="color: #209DDC">{}</span> news. <span style="font-size:35px;">&#128578;</span></h3>""".format(output), unsafe_allow_html=True)
elif output == 'sarcasm':
st.markdown("""<h3>This seems like a <span style="color: #B64434">{}</span> tweet. <span style="font-size:35px;">&#128579;</span></h3>""".format('sarcastic'), unsafe_allow_html=True)
st.markdown("""<h3>This seems like a <span style="color: #B64434">{}</span> tweet. <span style="font-size:35px;">&#128579;</span></h3>""".format('sarcastic'), unsafe_allow_html=True)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
documentAssembler = DocumentAssembler() \
.setInputCol("text") \
Expand Down
1 change: 1 addition & 0 deletions examples/demos/streamlit/Sentiment EN/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
documentAssembler = DocumentAssembler()\
.setInputCol("text")\
Expand Down
1 change: 1 addition & 0 deletions examples/demos/streamlit/Sentiment FR/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
document = DocumentAssembler()\
.setInputCol("text")\
Expand Down
1 change: 1 addition & 0 deletions examples/demos/streamlit/Sentiment SW/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
document_assembler = DocumentAssembler() \
.setInputCol("text") \
Expand Down
1 change: 1 addition & 0 deletions examples/demos/streamlit/Sentiment TR/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
document = DocumentAssembler()\
.setInputCol("text")\
Expand Down
1 change: 1 addition & 0 deletions examples/demos/streamlit/Sentiment UR/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
document_assembler = DocumentAssembler()\
.setInputCol("text")\
Expand Down
1 change: 1 addition & 0 deletions examples/demos/streamlit/Sentiment VI/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
document = DocumentAssembler()\
.setInputCol("text")\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):

audio_assembler = AudioAssembler() \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):

audio_assembler = AudioAssembler() \
Expand Down
1 change: 1 addition & 0 deletions examples/demos/streamlit/Spell Checker EN/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline():

document_assembler = DocumentAssembler()\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model, language):

documentAssembler = DocumentAssembler() \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model, language):

documentAssembler = DocumentAssembler() \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model, language):

documentAssembler = DocumentAssembler() \
Expand Down
1 change: 1 addition & 0 deletions examples/demos/streamlit/StopWords Indian/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
documenter = DocumentAssembler()\
.setInputCol("text")\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model, language):

documentAssembler = DocumentAssembler() \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model, task):
documentAssembler = DocumentAssembler() \
.setInputCol("text") \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model, task):
documentAssembler = DocumentAssembler() \
.setInputCol("text") \
Expand Down
1 change: 1 addition & 0 deletions examples/demos/streamlit/T5 Grammer/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
documentAssembler = DocumentAssembler() \
.setInputCol("text") \
Expand Down
1 change: 1 addition & 0 deletions examples/demos/streamlit/T5 Linguistic/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
documentAssembler = DocumentAssembler() \
.setInputCol("text") \
Expand Down
1 change: 1 addition & 0 deletions examples/demos/streamlit/T5 SQL/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
documentAssembler = DocumentAssembler() \
.setInputCol("text") \
Expand Down
1 change: 1 addition & 0 deletions examples/demos/streamlit/Text Finder EN/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model, matches):
documentAssembler = DocumentAssembler()\
.setInputCol("text")\
Expand Down
3 changes: 2 additions & 1 deletion examples/demos/streamlit/Text Preprocessing/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model, language):

documentAssembler = DocumentAssembler()\
Expand Down Expand Up @@ -171,4 +172,4 @@ def fit_data(pipeline, data):
if selected_models[5] is True:
tcol_arr = np.asarray(df['removed_stopwords'].values[0])[:,3]
st.subheader("Tokens after removing Stop Words:")
st.dataframe(pd.DataFrame({'removed_stopwords':tcol_arr}))
st.dataframe(pd.DataFrame({'removed_stopwords':tcol_arr}))
3 changes: 2 additions & 1 deletion examples/demos/streamlit/Text Summarization/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
document_assembler = DocumentAssembler()\
.setInputCol("text")\
Expand Down Expand Up @@ -98,4 +99,4 @@ def fit_data(pipeline, data):

Pipeline = create_pipeline(model)
output = fit_data(Pipeline, selected_text)
st.write(output)
st.write(output)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model, max_out_length):
document_assembler = DocumentAssembler()\
.setInputCol("text")\
Expand Down Expand Up @@ -103,4 +104,4 @@ def fit_data(pipeline, data):

Pipeline = create_pipeline(model, max_out_length)
output = fit_data(Pipeline, selected_text)
st.write(output)
st.write(output)
3 changes: 2 additions & 1 deletion examples/demos/streamlit/Translation Marian/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):
documentAssembler = DocumentAssembler()\
.setInputCol("text")\
Expand Down Expand Up @@ -122,4 +123,4 @@ def fit_data(pipeline, data):

Pipeline = create_pipeline(selected_model)
output = fit_data(Pipeline, selected_text)
st.write(output)
st.write(output)
1 change: 1 addition & 0 deletions examples/demos/streamlit/Typo Detector/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline():

documentAssembler = DocumentAssembler()\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

spark = sparknlp.start()

@st.cache_resource
def create_pipeline(model):

image_assembler = ImageAssembler() \
Expand Down Expand Up @@ -113,4 +114,4 @@ def save_uploadedfile(uploadedfile):
Pipeline = create_pipeline(model)
output = fit_data(Pipeline, selected_image)

st.markdown(f'This document has been classified as : **{output}**')
st.markdown(f'This document has been classified as : **{output}**')
Loading

0 comments on commit 262b802

Please sign in to comment.