|
|
|
import streamlit as st |
|
from transformers import AutoTokenizer, TFAutoModelForSequenceClassification |
|
from transformers import pipeline |
|
|
|
|
|
def multilingualmodel(): |
|
st.markdown("# multilingual model 🎈") |
|
st.sidebar.markdown("# nlptown/bert-base-multilingual-uncased-sentiment🎈") |
|
st.write("This classifier can now deal with texts in English, French, but also Dutch, German, Italian and Spanish!") |
|
classifier = pipeline('sentiment-analysis') |
|
model_name = "nlptown/bert-base-multilingual-uncased-sentiment" |
|
model = TFAutoModelForSequenceClassification.from_pretrained(model_name, from_pt=True) |
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
classifier = pipeline('sentiment-analysis', model=model, tokenizer=tokenizer) |
|
user_input = st.text_area('Enter Text to Analyze') |
|
button = st.button("Analyze") |
|
if user_input and button : |
|
tt = classifier(user_input) |
|
st.write(tt) |
|
for result in tt: |
|
st.success(f"label: {result['label']}, with score: {round(result['score'], 4)}") |
|
|
|
|
|
def engdistilbertmod(): |
|
st.markdown("distilbert base finetuned english ❄️") |
|
st.sidebar.markdown("# distilbert-base-uncased-finetuned-sst-2-english ❄️") |
|
model_name = "distilbert-base-uncased-finetuned-sst-2-english" |
|
tf_model = TFAutoModelForSequenceClassification.from_pretrained(model_name) |
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
classifier = pipeline('sentiment-analysis', model=tf_model, tokenizer=tokenizer) |
|
|
|
user_input = st.text_area('Enter Text to Analyze With distilbert ', key= "distilbert_input") |
|
button = st.button("Analyze", key= "distilbert_button") |
|
|
|
if user_input and button : |
|
tt = classifier(user_input) |
|
for result in tt: |
|
st.success(f"label: {result['label']}, with score: {round(result['score'], 4)}") |
|
|
|
|
|
page_names_to_funcs = { |
|
"Bert-base-Multilingual": multilingualmodel, |
|
"Distilbert base": engdistilbertmod, |
|
} |
|
|
|
selected_page = st.sidebar.selectbox("Select a page", page_names_to_funcs.keys()) |
|
page_names_to_funcs[selected_page]() |
|
|
|
|