Spaces:
Sleeping
Sleeping
nurindahpratiwi
commited on
Commit
·
2cec43b
1
Parent(s):
d167160
first commit
Browse files- app.py +32 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# title
|
5 |
+
st.title("Sentiment Analysis App")
|
6 |
+
|
7 |
+
# subtitle
|
8 |
+
st.markdown("Enter a text and select a pretrained model to get the sentiment analysis:")
|
9 |
+
|
10 |
+
st.markdown("Link to the app - [sentiment-analysis-streamlit on 🤗 Spaces](https://huggingface.co/spaces/rd448/sentiment-analysis-streamlit)")
|
11 |
+
|
12 |
+
# text input
|
13 |
+
text = st.text_input("Enter text here", "I love you")
|
14 |
+
|
15 |
+
# Model selection dropdown
|
16 |
+
model_names = ["distilbert-base-uncased-finetuned-sst-2-english"]
|
17 |
+
model = st.selectbox("Select a pretrained model", model_names)
|
18 |
+
|
19 |
+
# Sentiment analysis function
|
20 |
+
def analyze_sentiment(text, model):
|
21 |
+
if model == "distilbert-base-uncased-finetuned-sst-2-english":
|
22 |
+
classifier = pipeline("sentiment-analysis", model=model)
|
23 |
+
result = classifier(text)[0]
|
24 |
+
sentiment = result['label']
|
25 |
+
score = result['score']
|
26 |
+
return sentiment, score
|
27 |
+
|
28 |
+
if st.button("Analyze"):
|
29 |
+
sentiment, score = analyze_sentiment(text, model)
|
30 |
+
st.write(f"Sentiment: {sentiment}")
|
31 |
+
if score is not None:
|
32 |
+
st.write(f"Score: {score}")
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
transformers
|