Spaces:
Runtime error
Runtime error
JJ Makely
commited on
Commit
•
4abb8db
1
Parent(s):
07825ed
sentiment analysis model's added
Browse files- app.py +32 -2
- requirements.txt +3 -1
app.py
CHANGED
@@ -1,4 +1,34 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoTokenizer
|
3 |
|
4 |
+
# Define a list of pretrained models
|
5 |
+
models = {
|
6 |
+
"BERTweet": "finiteautomata/bertweet-base-sentiment-analysis",
|
7 |
+
"roBERTa": "cardiffnlp/twitter-roberta-base-sentiment",
|
8 |
+
"Distilbert": "bhadresh-savani/distilbert-base-uncased-emotion",
|
9 |
+
"BERT (BONUS!: Item Review)": "nlptown/bert-base-multilingual-uncased-sentiment",
|
10 |
+
}
|
11 |
+
|
12 |
+
# Display a selection box for the user to choose a model
|
13 |
+
selected_model = st.selectbox("Select a pretrained model", list(models.keys()))
|
14 |
+
|
15 |
+
# roBERTa specific label map
|
16 |
+
roberta_label_map = {"LABEL_0": "negative", "LABEL_1": "neutral", "LABEL_2": "positive"}
|
17 |
+
|
18 |
+
# Load the selected model and tokenizer
|
19 |
+
model_name = models[selected_model]
|
20 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
21 |
+
sentiment_pipeline = pipeline("sentiment-analysis", model=model_name, tokenizer=tokenizer)
|
22 |
+
|
23 |
+
# Get user input and perform sentiment analysis
|
24 |
+
text_input = st.text_input("Enter text for sentiment analysis", "Anish is a very awesome and dedicated TA! 🤗")
|
25 |
+
submit_btn = st.button("Submit")
|
26 |
+
|
27 |
+
if submit_btn and text_input:
|
28 |
+
result = sentiment_pipeline(text_input)
|
29 |
+
if selected_model == "roBERTa":
|
30 |
+
st.write("Sentiment:", roberta_label_map[result[0]["label"]])
|
31 |
+
st.write("Score:", result[0]["score"])
|
32 |
+
else:
|
33 |
+
st.write("Sentiment:", result[0]["label"])
|
34 |
+
st.write("Score:", result[0]["score"])
|
requirements.txt
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
streamlit
|
2 |
-
numpy
|
|
|
|
|
|
1 |
streamlit
|
2 |
+
numpy
|
3 |
+
transformers
|
4 |
+
tensorflow
|