Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,14 +6,17 @@ def analyze_sentiment(text):
|
|
| 6 |
"sentiment-analysis",
|
| 7 |
model="nlptown/bert-base-multilingual-uncased-sentiment"
|
| 8 |
)
|
|
|
|
| 9 |
result = sentiment_analyzer(text, return_all_scores=True)
|
| 10 |
-
score = int(result[0]['score'] * 5) # Convert probability to 5-star scale
|
| 11 |
-
stars = "⭐" * score
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
with gr.Blocks() as demo:
|
| 16 |
gr.Markdown("## Sentiment Analysis Demo")
|
|
|
|
| 17 |
with gr.Row():
|
| 18 |
input_text = gr.Textbox(
|
| 19 |
label="Enter your text here",
|
|
@@ -26,14 +29,16 @@ with gr.Blocks() as demo:
|
|
| 26 |
"Absolutely fantastic! I would recommend it to everyone."
|
| 27 |
]
|
| 28 |
)
|
|
|
|
| 29 |
with gr.Row():
|
| 30 |
analyze_button = gr.Button("Analyze Sentiment", variant="primary")
|
|
|
|
| 31 |
with gr.Row():
|
| 32 |
output_text = gr.Textbox(
|
| 33 |
label="Sentiment (Stars)",
|
| 34 |
lines=1
|
| 35 |
)
|
| 36 |
-
|
| 37 |
analyze_button.click(
|
| 38 |
fn=analyze_sentiment,
|
| 39 |
inputs=input_text,
|
|
|
|
| 6 |
"sentiment-analysis",
|
| 7 |
model="nlptown/bert-base-multilingual-uncased-sentiment"
|
| 8 |
)
|
| 9 |
+
|
| 10 |
result = sentiment_analyzer(text, return_all_scores=True)
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
score = int(result[0]['score'] * 5)
|
| 13 |
+
sentiment_stars = "⭐" * score
|
| 14 |
+
|
| 15 |
+
return sentiment_stars
|
| 16 |
|
| 17 |
with gr.Blocks() as demo:
|
| 18 |
gr.Markdown("## Sentiment Analysis Demo")
|
| 19 |
+
|
| 20 |
with gr.Row():
|
| 21 |
input_text = gr.Textbox(
|
| 22 |
label="Enter your text here",
|
|
|
|
| 29 |
"Absolutely fantastic! I would recommend it to everyone."
|
| 30 |
]
|
| 31 |
)
|
| 32 |
+
|
| 33 |
with gr.Row():
|
| 34 |
analyze_button = gr.Button("Analyze Sentiment", variant="primary")
|
| 35 |
+
|
| 36 |
with gr.Row():
|
| 37 |
output_text = gr.Textbox(
|
| 38 |
label="Sentiment (Stars)",
|
| 39 |
lines=1
|
| 40 |
)
|
| 41 |
+
|
| 42 |
analyze_button.click(
|
| 43 |
fn=analyze_sentiment,
|
| 44 |
inputs=input_text,
|