JasmineQiuqiu commited on
Commit
b236a9b
1 Parent(s): 18ad580

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -1,9 +1,6 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # load the pipeline
5
- sentiment_analysis = pipeline("sentiment-analysis")
6
-
7
  # title
8
  st.title('Analyze Sentiment of Text!')
9
 
@@ -15,9 +12,26 @@ st.write("Let's try it: :smiley:")
15
 
16
  user_input = st.text_input('Enter something below:')
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  if st.button('Submit'):
19
  if user_input:
20
- results = sentiment_analysis(user_input)
21
- st.write('The detected sentiment is', result[0].label, "with a score of",result[0].score)
 
 
 
22
  else:
23
  st.write('Please enter something!')
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
 
 
 
4
  # title
5
  st.title('Analyze Sentiment of Text!')
6
 
 
12
 
13
  user_input = st.text_input('Enter something below:')
14
 
15
+ model_options = ["finiteautomata/bertweet-base-sentiment-analysis",
16
+ "nlptown/bert-base-multilingual-uncased-sentiment",
17
+ "bhadresh-savani/distilbert-base-uncased-emotion"]
18
+ selected_model = st.selectbox('Choose a model:', model_options)
19
+
20
+ def choose_model(option):
21
+ chosen_model = pipeline("sentiment-analysis", model=option)
22
+ return chosen_model
23
+
24
+ # Initialize the model
25
+ model = None
26
+ if selected_model:
27
+ model = choose_model(selected_model)
28
+
29
  if st.button('Submit'):
30
  if user_input:
31
+ if model:
32
+ results = model(user_input)
33
+ st.write('The detected sentiment is', results[0]['label'], "with a score of", results[0]['score'])
34
+ else:
35
+ st.write('Please select a model!')
36
  else:
37
  st.write('Please enter something!')