Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,13 +22,13 @@ def analyze_sentiment(user_input):
|
|
| 22 |
# Interpret Results
|
| 23 |
labels = ["้ๅธธใซๅฆๅฎ็ ๐ก", "ๅฆๅฎ็ ๐", "ไธญ็ซ็ ๐", "่ฏๅฎ็ ๐", "้ๅธธใซ่ฏๅฎ็ ๐"]
|
| 24 |
sentiment = labels[scores.index(max(scores))] # Select sentiment with highest score
|
| 25 |
-
|
| 26 |
# Format Confidence Scores
|
| 27 |
confidence = "\n".join([f"{label}: {score:.2%}" for label, score in zip(labels, scores)])
|
| 28 |
|
| 29 |
-
return f"ไบๆธฌใใใๆๆ
: {sentiment}", confidence
|
| 30 |
else:
|
| 31 |
-
return "โ ๏ธ Please enter text before analyzing.", ""
|
| 32 |
|
| 33 |
# Gradio Blocks interface
|
| 34 |
with gr.Blocks() as app:
|
|
@@ -36,12 +36,13 @@ with gr.Blocks() as app:
|
|
| 36 |
gr.Markdown("ๅๆใใใใญในใใๅ
ฅๅใใฆใใ ใใ")
|
| 37 |
|
| 38 |
# Text input
|
| 39 |
-
user_input = gr.Textbox(label="ๅๆใใใใญในใ",
|
| 40 |
|
| 41 |
# Outputs
|
| 42 |
sentiment_output = gr.Textbox(label="ไบๆธฌใใใๆๆ
", interactive=False)
|
| 43 |
confidence_output = gr.Textbox(label="็ขบไฟกๅบฆ", interactive=False)
|
| 44 |
-
|
|
|
|
| 45 |
# Button to trigger analysis
|
| 46 |
analyze_button = gr.Button("ๆๆ
ๅๆ")
|
| 47 |
|
|
@@ -49,7 +50,7 @@ with gr.Blocks() as app:
|
|
| 49 |
analyze_button.click(
|
| 50 |
fn=analyze_sentiment,
|
| 51 |
inputs=[user_input],
|
| 52 |
-
outputs=[sentiment_output, confidence_output]
|
| 53 |
)
|
| 54 |
|
| 55 |
# Launch the Gradio app
|
|
|
|
| 22 |
# Interpret Results
|
| 23 |
labels = ["้ๅธธใซๅฆๅฎ็ ๐ก", "ๅฆๅฎ็ ๐", "ไธญ็ซ็ ๐", "่ฏๅฎ็ ๐", "้ๅธธใซ่ฏๅฎ็ ๐"]
|
| 24 |
sentiment = labels[scores.index(max(scores))] # Select sentiment with highest score
|
| 25 |
+
|
| 26 |
# Format Confidence Scores
|
| 27 |
confidence = "\n".join([f"{label}: {score:.2%}" for label, score in zip(labels, scores)])
|
| 28 |
|
| 29 |
+
return f"ไบๆธฌใใใๆๆ
: {sentiment}", confidence, sentiment # Returning sentiment separately
|
| 30 |
else:
|
| 31 |
+
return "โ ๏ธ Please enter text before analyzing.", "", ""
|
| 32 |
|
| 33 |
# Gradio Blocks interface
|
| 34 |
with gr.Blocks() as app:
|
|
|
|
| 36 |
gr.Markdown("ๅๆใใใใญในใใๅ
ฅๅใใฆใใ ใใ")
|
| 37 |
|
| 38 |
# Text input
|
| 39 |
+
user_input = gr.Textbox(label="ๅๆใใใใญในใ", placeholder="ใใใซใใญในใใๅ
ฅๅใใฆใใ ใใ...")
|
| 40 |
|
| 41 |
# Outputs
|
| 42 |
sentiment_output = gr.Textbox(label="ไบๆธฌใใใๆๆ
", interactive=False)
|
| 43 |
confidence_output = gr.Textbox(label="็ขบไฟกๅบฆ", interactive=False)
|
| 44 |
+
top_sentiment_output = gr.Textbox(label="ๆใ้ซใๆๆ
", interactive=False) # New output for top sentiment
|
| 45 |
+
|
| 46 |
# Button to trigger analysis
|
| 47 |
analyze_button = gr.Button("ๆๆ
ๅๆ")
|
| 48 |
|
|
|
|
| 50 |
analyze_button.click(
|
| 51 |
fn=analyze_sentiment,
|
| 52 |
inputs=[user_input],
|
| 53 |
+
outputs=[sentiment_output, confidence_output, top_sentiment_output] # Include new output
|
| 54 |
)
|
| 55 |
|
| 56 |
# Launch the Gradio app
|