Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def multilingualmodel():
|
| 8 |
+
st.markdown("# multilingual model 🎈")
|
| 9 |
+
st.sidebar.markdown("# nlptown/bert-base-multilingual-uncased-sentiment🎈")
|
| 10 |
+
st.write("This classifier can now deal with texts in English, French, but also Dutch, German, Italian and Spanish!")
|
| 11 |
+
classifier = pipeline('sentiment-analysis')
|
| 12 |
+
model_name = "nlptown/bert-base-multilingual-uncased-sentiment"
|
| 13 |
+
model = TFAutoModelForSequenceClassification.from_pretrained(model_name, from_pt=True)
|
| 14 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 15 |
+
classifier = pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)
|
| 16 |
+
user_input = st.text_area('Enter Text to Analyze')
|
| 17 |
+
button = st.button("Analyze")
|
| 18 |
+
if user_input and button :
|
| 19 |
+
tt = classifier(user_input)
|
| 20 |
+
st.write(tt)
|
| 21 |
+
for result in tt:
|
| 22 |
+
st.success(f"label: {result['label']}, with score: {round(result['score'], 4)}")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def engdistilbertmod():
|
| 26 |
+
st.markdown("distilbert base finetuned english ❄️")
|
| 27 |
+
st.sidebar.markdown("# distilbert-base-uncased-finetuned-sst-2-english ❄️")
|
| 28 |
+
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
|
| 29 |
+
tf_model = TFAutoModelForSequenceClassification.from_pretrained(model_name)
|
| 30 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 31 |
+
classifier = pipeline('sentiment-analysis', model=tf_model, tokenizer=tokenizer)
|
| 32 |
+
|
| 33 |
+
user_input = st.text_area('Enter Text to Analyze With distilbert ', key= "distilbert_input")
|
| 34 |
+
button = st.button("Analyze", key= "distilbert_button")
|
| 35 |
+
|
| 36 |
+
if user_input and button :
|
| 37 |
+
tt = classifier(user_input)
|
| 38 |
+
for result in tt:
|
| 39 |
+
st.success(f"label: {result['label']}, with score: {round(result['score'], 4)}")
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
page_names_to_funcs = {
|
| 43 |
+
"Bert-base-Multilingual": multilingualmodel,
|
| 44 |
+
"Distilbert base": engdistilbertmod,
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
selected_page = st.sidebar.selectbox("Select a page", page_names_to_funcs.keys())
|
| 48 |
+
page_names_to_funcs[selected_page]()
|
| 49 |
+
|