Spaces:
Sleeping
Sleeping
usamaferoz12
commited on
Commit
•
a793ade
1
Parent(s):
900cb10
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,27 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
model.eval()
|
12 |
-
|
13 |
-
# Function to perform sentiment analysis
|
14 |
-
def analyze_sentiment(text):
|
15 |
-
inputs = tokenizer(text, return_tensors='pt', truncation=True, padding=True)
|
16 |
-
with torch.no_grad():
|
17 |
-
outputs = model(**inputs)
|
18 |
-
logits = outputs.logits
|
19 |
-
predicted_class = logits.argmax().item()
|
20 |
-
return predicted_class
|
21 |
-
|
22 |
-
# Create a Streamlit app
|
23 |
st.title("Sentiment Analysis App")
|
24 |
|
25 |
-
|
26 |
-
text = st.text_area("Enter text for sentiment analysis")
|
27 |
|
28 |
if st.button("Analyze Sentiment"):
|
29 |
-
if
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
model_path = "citizenlab/twitter-xlm-roberta-base-sentiment-finetunned"
|
5 |
+
|
6 |
+
st.set_page_config(page_title="Sentiment Analysis App")
|
7 |
+
|
8 |
+
|
9 |
+
sentiment_classifier = pipeline("text-classification", model=model_path, tokenizer=model_path)
|
10 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
st.title("Sentiment Analysis App")
|
12 |
|
13 |
+
user_input = st.text_area("Enter a message:")
|
|
|
14 |
|
15 |
if st.button("Analyze Sentiment"):
|
16 |
+
if user_input:
|
17 |
+
# Perform sentiment analysis
|
18 |
+
results = sentiment_classifier(user_input)
|
19 |
+
sentiment_label = results[0]["label"]
|
20 |
+
sentiment_score = results[0]["score"]
|
21 |
+
|
22 |
+
st.write(f"Sentiment: {sentiment_label}")
|
23 |
+
st.write(f"Confidence Score: {sentiment_score:.2f}")
|
24 |
+
|
25 |
+
# Run the Streamlit app
|
26 |
+
if _name_ == "_main_":
|
27 |
+
st.write("Enter a message and click 'Analyze Sentiment' to classify its sentiment.")
|