lbiester commited on
Commit
dc962d5
·
verified ·
1 Parent(s): e41696f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -16
app.py CHANGED
@@ -11,15 +11,13 @@ def classify(text):
11
 
12
  def predict_sentiment(text):
13
  if model == "finiteautomata/bertweet-base-sentiment-analysis":
14
- # pipe = pipeline("text-classification", model="finiteautomata/bertweet-base-sentiment-analysis")
15
- # out = pipe(text, return_all_scores=True)
16
- # return {pred["label"]: pred["score"] for pred in out[0]}
17
- return {"cathf": 0.3, "doghf": 0.7}
18
  elif model == "vader":
19
- # nltk.download('vader_lexicon')
20
- # sia = SentimentIntensityAnalyzer()
21
- # return sia.polarity_scores(text)
22
- return {"catv": 0.3, "dogv": 0.7}
23
 
24
 
25
 
@@ -37,15 +35,21 @@ with demo:
37
 
38
  with gr.TabItem("Multiple Inputs"):
39
  gr.Markdown("A more complex interface for sentiment analysis with multiple inputs, including a dropdown, and some examples")
40
- demo = gr.Interface(
41
- fn=predict_sentiment,
42
- inputs=[
43
- gr.Textbox(),
44
- # gr.Dropdown(
45
- # ["finiteautomata/bertweet-base-sentiment-analysis", "vader"], label="Model"
46
- # ),
47
  ],
48
- outputs="label"
 
 
 
 
 
 
49
  )
50
 
51
  demo.launch()
 
11
 
12
  def predict_sentiment(text):
13
  if model == "finiteautomata/bertweet-base-sentiment-analysis":
14
+ pipe = pipeline("text-classification", model="finiteautomata/bertweet-base-sentiment-analysis")
15
+ out = pipe(text, return_all_scores=True)
16
+ return {pred["label"]: pred["score"] for pred in out[0]}
 
17
  elif model == "vader":
18
+ nltk.download('vader_lexicon')
19
+ sia = SentimentIntensityAnalyzer()
20
+ return sia.polarity_scores(text)
 
21
 
22
 
23
 
 
35
 
36
  with gr.TabItem("Multiple Inputs"):
37
  gr.Markdown("A more complex interface for sentiment analysis with multiple inputs, including a dropdown, and some examples")
38
+ interface = gr.Interface(
39
+ predict_sentiment,
40
+ [
41
+ gr.Textbox(placeholder="Your text input"),
42
+ gr.Dropdown(
43
+ ["finiteautomata/bertweet-base-sentiment-analysis", "vader"], label="Model"
44
+ ),
45
  ],
46
+ "text",
47
+ examples=[
48
+ ["Happy smile", "vader"],
49
+ ["Happy smile", "finiteautomata/bertweet-base-sentiment-analysis"],
50
+ ["Sad frown", "vader"],
51
+ ["Sad frown", "finiteautomata/bertweet-base-sentiment-analysis"],
52
+ ]
53
  )
54
 
55
  demo.launch()