Update app.py to enable public sharing link
Browse files
app.py
CHANGED
@@ -1,33 +1,33 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
-
|
4 |
-
pipe = pipeline(model="delarosajav95/tw-roberta-base-sentiment-FT-v2")
|
5 |
-
#function that Gradio will use to classify
|
6 |
-
def classify_text(inputs):
|
7 |
-
result = pipe(inputs, return_all_scores=True)
|
8 |
-
output = []
|
9 |
-
label_mapping = {"LABEL_0": "Negative", "LABEL_1": "Neutral", "LABEL_2": "Positive"}
|
10 |
-
for i, predictions in enumerate(result):
|
11 |
-
for pred in predictions:
|
12 |
-
label = label_mapping.get(pred['label'], pred['label'])
|
13 |
-
score = pred['score']
|
14 |
-
output.append(f"{label}: {score:.2%}")
|
15 |
-
|
16 |
-
return "\n".join(output)
|
17 |
-
#defining Gradio interface
|
18 |
-
textbox = gr.Textbox(lines=3, placeholder="Enter a user review, comment, or opinion to evaluate...(e.g., 'I love this product! It looks great.')",
|
19 |
-
label="User Review/Comment:")
|
20 |
-
|
21 |
-
output_box = gr.Textbox(label="Results:")
|
22 |
-
|
23 |
-
iface = gr.Interface(
|
24 |
-
fn=classify_text,
|
25 |
-
inputs=textbox,
|
26 |
-
outputs=output_box,
|
27 |
-
live=True,
|
28 |
-
title="Sentiment Analysis for User Opinions & Feedback",
|
29 |
-
allow_flagging="never",
|
30 |
-
)
|
31 |
-
|
32 |
-
# Launch the interface
|
33 |
-
iface.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
pipe = pipeline(model="delarosajav95/tw-roberta-base-sentiment-FT-v2")
|
5 |
+
#function that Gradio will use to classify
|
6 |
+
def classify_text(inputs):
|
7 |
+
result = pipe(inputs, return_all_scores=True)
|
8 |
+
output = []
|
9 |
+
label_mapping = {"LABEL_0": "Negative", "LABEL_1": "Neutral", "LABEL_2": "Positive"}
|
10 |
+
for i, predictions in enumerate(result):
|
11 |
+
for pred in predictions:
|
12 |
+
label = label_mapping.get(pred['label'], pred['label'])
|
13 |
+
score = pred['score']
|
14 |
+
output.append(f"{label}: {score:.2%}")
|
15 |
+
|
16 |
+
return "\n".join(output)
|
17 |
+
#defining Gradio interface
|
18 |
+
textbox = gr.Textbox(lines=3, placeholder="Enter a user review, comment, or opinion to evaluate...(e.g., 'I love this product! It looks great.')",
|
19 |
+
label="User Review/Comment:")
|
20 |
+
|
21 |
+
output_box = gr.Textbox(label="Results:")
|
22 |
+
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=classify_text,
|
25 |
+
inputs=textbox,
|
26 |
+
outputs=output_box,
|
27 |
+
live=True,
|
28 |
+
title="Sentiment Analysis for User Opinions & Feedback",
|
29 |
+
allow_flagging="never",
|
30 |
+
)
|
31 |
+
|
32 |
+
# Launch the interface
|
33 |
+
iface.launch(share=True)
|