Spaces:
Sleeping
Sleeping
pedrogengo
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
distilled_student_sentiment_classifier = pipeline(
|
5 |
+
model="lxyuan/distilbert-base-multilingual-cased-sentiments-student",
|
6 |
+
return_all_scores=True
|
7 |
+
)
|
8 |
+
|
9 |
+
def sentiment_analysis(user_query: str):
|
10 |
+
result = distilled_student_sentiment_classifier(user_query)[0]
|
11 |
+
structured_result = dict()
|
12 |
+
for r in result:
|
13 |
+
structured_result[r["label"]] = r["score"]
|
14 |
+
return structured_result
|
15 |
+
|
16 |
+
demo = gr.Interface(
|
17 |
+
fn = sentiment_analysis,
|
18 |
+
inputs = [gr.Textbox()],
|
19 |
+
outputs = [gr.Label()]
|
20 |
+
)
|
21 |
+
|
22 |
+
demo.launch()
|