Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
15 |
-
|
16 |
-
|
17 |
-
return {"cathf": 0.3, "doghf": 0.7}
|
18 |
elif model == "vader":
|
19 |
-
|
20 |
-
|
21 |
-
|
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 |
-
|
41 |
-
|
42 |
-
|
43 |
-
gr.Textbox(),
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
],
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|