joulammous commited on
Commit
b2f42dd
2 Parent(s): e0678f1 58eb48c

Merge pull request #6 from joulammous/milestone-2

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -7,18 +7,25 @@ from transformers import pipeline
7
 
8
  # Milestone 2
9
 
 
10
  sentiment_pipeline = pipeline("sentiment-analysis", model = "siebert/sentiment-roberta-large-english")
11
 
12
- st.title('Sentiment Analysis with Hugging Face')
13
- st.write('Enter some text and we will predict its sentiment!')
 
14
 
15
- # Add a text input box for the user to enter text
16
- text_input = st.text_input('Enter text here')
17
 
18
- # When the user submits text, run the sentiment analysis model on it
19
- if st.button('Submit'):
20
- # Predict the sentiment of the text using the Hugging Face model
21
- sentiment = sentiment_pipeline(text_input)[0]['label']
22
 
23
- # Display the sentiment prediction to the user
24
- st.write(f'Sentiment: {sentiment}')
 
 
 
 
 
 
 
 
7
 
8
  # Milestone 2
9
 
10
+ # select a pretrained model
11
  sentiment_pipeline = pipeline("sentiment-analysis", model = "siebert/sentiment-roberta-large-english")
12
 
13
+ # intro
14
+ st.title("Sentiment Analysis App")
15
+ st.write("Enter some text and I'll predict its sentiment!")
16
 
17
+ # add a text input box
18
+ text_input = st.text_input("Enter your text here:", value = "The weather is nice today.")
19
 
20
+ # run the model when the user clicks submit
21
+ if st.button("Submit"):
 
 
22
 
23
+ # get result
24
+ sentiment = sentiment_pipeline(text_input)
25
+
26
+ # split into sentiment and score
27
+ sen = sentiment[0]['label']
28
+ score = round(sentiment[0]['score'], 4)
29
+
30
+ # display the prediction
31
+ st.write(f"Sentiment: {sen} , Confidence Score: {score}")