Spaces:
Runtime error
Runtime error
joulammous
commited on
Commit
•
e0d35f1
1
Parent(s):
f6d3905
Add files via upload
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# Libraries
|
3 |
+
|
4 |
+
import streamlit as st
|
5 |
+
import tensorflow as tf
|
6 |
+
from transformers import pipeline
|
7 |
+
|
8 |
+
# Milestone 2
|
9 |
+
|
10 |
+
# title
|
11 |
+
st.title("Sentiment Analysis App")
|
12 |
+
st.write("Enter some text and I'll predict its sentiment!")
|
13 |
+
|
14 |
+
# add a text input box
|
15 |
+
text_input = st.text_input("Enter your text here:", value = "The weather is nice today.")
|
16 |
+
|
17 |
+
# use a select box for pretrained models
|
18 |
+
option = st.selectbox(
|
19 |
+
"Select a pretrained model for sentiment analysis",
|
20 |
+
("siebert/sentiment-roberta-large-english", "yiyanghkust/finbert-tone", "finiteautomata/bertweet-base-sentiment-analysis"))
|
21 |
+
|
22 |
+
# display selection
|
23 |
+
st.write("You selected:", option)
|
24 |
+
|
25 |
+
# run pipeline
|
26 |
+
sentiment_pipeline = pipeline("sentiment-analysis", model = option)
|
27 |
+
|
28 |
+
# run the model when the user clicks submit
|
29 |
+
if st.button("Submit"):
|
30 |
+
sentiment = sentiment_pipeline(text_input)
|
31 |
+
|
32 |
+
# split into sentiment and score
|
33 |
+
sen = sentiment[0]['label']
|
34 |
+
score = round(sentiment[0]['score'], 4)
|
35 |
+
|
36 |
+
# get results
|
37 |
+
st.write(f"Sentiment: {sen} , Confidence Score: {score}")
|