Spaces:
Runtime error
Runtime error
Merge pull request #3 from cgr28/milestone-2
Browse files
app.py
CHANGED
@@ -13,16 +13,17 @@ analyze_button = st.button(label="Analyze")
|
|
13 |
|
14 |
st.markdown("**:red[Sentiment:]**")
|
15 |
|
16 |
-
|
17 |
-
if
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
13 |
|
14 |
st.markdown("**:red[Sentiment:]**")
|
15 |
|
16 |
+
with st.spinner(text="Analyzing..."):
|
17 |
+
if analyze_button:
|
18 |
+
if selected_model=="Model 1":
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-emotion")
|
20 |
+
model = RobertaForSequenceClassification.from_pretrained("cardiffnlp/twitter-roberta-base-emotion")
|
21 |
+
else:
|
22 |
+
tokenizer = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment-latest")
|
23 |
+
model = RobertaForSequenceClassification.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment-latest")
|
24 |
+
inputs = tokenizer(text, return_tensors="pt")
|
25 |
+
with torch.no_grad():
|
26 |
+
logits = model(**inputs).logits
|
27 |
+
prediction_id = logits.argmax().item()
|
28 |
+
results = model.config.id2label[prediction_id]
|
29 |
+
st.write(results)
|