Spaces:
Runtime error
Runtime error
Commit
•
41c9c41
1
Parent(s):
dac9003
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
|
|
5 |
|
6 |
-
|
|
|
7 |
|
8 |
-
if
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import streamlit as st
|
2 |
+
# from transformers import pipeline
|
3 |
+
|
4 |
+
# sentiment_analysis = pipeline("sentiment-analysis")
|
5 |
+
|
6 |
+
# text = st.text_input("Enter some text")
|
7 |
+
|
8 |
+
# if text:
|
9 |
+
# result = sentiment_analysis(text)
|
10 |
+
# st.json(result)
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
import streamlit as st
|
15 |
+
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
16 |
+
|
17 |
+
# Load sentiment analysis model from Hugging Face
|
18 |
+
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
|
19 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
20 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
21 |
+
sentiment_analyzer = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
22 |
|
23 |
+
# Streamlit UI
|
24 |
+
st.title("Sentiment Analysis App")
|
25 |
|
26 |
+
# User input
|
27 |
+
user_input = st.text_input("Enter a sentence:")
|
28 |
|
29 |
+
if user_input:
|
30 |
+
# Perform sentiment analysis
|
31 |
+
results = sentiment_analyzer(user_input)
|
32 |
+
|
33 |
+
# Display sentiment and confidence
|
34 |
+
sentiment = results[0]['label']
|
35 |
+
confidence = results[0]['score']
|
36 |
+
|
37 |
+
st.write(f"Sentiment: {sentiment}")
|
38 |
+
st.write(f"Confidence: {confidence:.2f}")
|