Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
import pandas as pd
|
|
@@ -466,8 +493,11 @@ with gr.Blocks(title="Multilingual Sentiment Analysis") as demo:
|
|
| 466 |
- Language detection: papluca/xlm-roberta-base-language-detection
|
| 467 |
""")
|
| 468 |
|
|
|
|
| 469 |
with gr.Row():
|
| 470 |
-
|
|
|
|
|
|
|
| 471 |
user_text = gr.Textbox(
|
| 472 |
label="βοΈ Enter Text",
|
| 473 |
placeholder="Type in English, Urdu, or Roman Urdu...",
|
|
@@ -484,21 +514,47 @@ with gr.Blocks(title="Multilingual Sentiment Analysis") as demo:
|
|
| 484 |
btn_show = gr.Button("π Show Logs")
|
| 485 |
btn_clear = gr.Button("ποΈ Clear Logs")
|
| 486 |
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 500 |
|
| 501 |
-
# Event handlers
|
| 502 |
btn_analyze.click(
|
| 503 |
analyze_sentiment_complete,
|
| 504 |
inputs=[user_text, lang_dropdown],
|
|
|
|
| 1 |
+
[file name]: image.png
|
| 2 |
+
[file content begin]
|
| 3 |
+
Enter Text
|
| 4 |
+
|
| 5 |
+
Type in English, Urdu, or Roman Urdu...
|
| 6 |
+
|
| 7 |
+
Language Selection
|
| 8 |
+
Auto Detect
|
| 9 |
+
|
| 10 |
+
Analyze Sentiment
|
| 11 |
+
Show Logs
|
| 12 |
+
|
| 13 |
+
Clear Logs
|
| 14 |
+
|
| 15 |
+
Sentiment
|
| 16 |
+
Confidence Score
|
| 17 |
+
Detailed Explanation
|
| 18 |
+
Strong Words
|
| 19 |
+
|
| 20 |
+
Download Logs
|
| 21 |
+
|
| 22 |
+
Analysis History
|
| 23 |
+
Sent_ Lang_Sent_ Conf_ Stro_Tima_
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
[file content end]
|
| 27 |
+
|
| 28 |
import gradio as gr
|
| 29 |
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
| 30 |
import pandas as pd
|
|
|
|
| 493 |
- Language detection: papluca/xlm-roberta-base-language-detection
|
| 494 |
""")
|
| 495 |
|
| 496 |
+
# Top row with two columns
|
| 497 |
with gr.Row():
|
| 498 |
+
# Left column - Input section
|
| 499 |
+
with gr.Column(scale=1):
|
| 500 |
+
gr.Markdown("### π₯ Input Section")
|
| 501 |
user_text = gr.Textbox(
|
| 502 |
label="βοΈ Enter Text",
|
| 503 |
placeholder="Type in English, Urdu, or Roman Urdu...",
|
|
|
|
| 514 |
btn_show = gr.Button("π Show Logs")
|
| 515 |
btn_clear = gr.Button("ποΈ Clear Logs")
|
| 516 |
|
| 517 |
+
# Right column - Results section
|
| 518 |
+
with gr.Column(scale=1):
|
| 519 |
+
gr.Markdown("### π Results")
|
| 520 |
+
with gr.Row():
|
| 521 |
+
with gr.Column():
|
| 522 |
+
out_sent = gr.Textbox(label="π Sentiment")
|
| 523 |
+
out_conf = gr.Textbox(label="π Confidence Score")
|
| 524 |
+
with gr.Column():
|
| 525 |
+
out_strong = gr.Textbox(label="πͺ Strong Words")
|
| 526 |
+
out_file = gr.File(label="β¬οΈ Download Logs")
|
| 527 |
+
|
| 528 |
+
out_exp = gr.Textbox(label="π‘ Detailed Explanation", lines=3)
|
| 529 |
+
|
| 530 |
+
# Bottom row with analysis history taking 75% width
|
| 531 |
+
with gr.Row():
|
| 532 |
+
with gr.Column(scale=3): # 75% width (3/4)
|
| 533 |
+
logs_df = gr.Dataframe(
|
| 534 |
+
headers=["Sentence", "Language", "Sentiment", "Confidence", "Strong_Words", "Timestamp"],
|
| 535 |
+
label="π Analysis History",
|
| 536 |
+
interactive=False,
|
| 537 |
+
wrap=True,
|
| 538 |
+
height=400
|
| 539 |
+
)
|
| 540 |
+
with gr.Column(scale=1): # 25% width (1/4)
|
| 541 |
+
gr.Markdown("### βΉοΈ Information")
|
| 542 |
+
gr.Markdown("""
|
| 543 |
+
**How to use:**
|
| 544 |
+
1. Enter text in any supported language
|
| 545 |
+
2. Select language or use Auto Detect
|
| 546 |
+
3. Click Analyze Sentiment
|
| 547 |
+
4. View results and history
|
| 548 |
+
|
| 549 |
+
**Supported Languages:**
|
| 550 |
+
- English
|
| 551 |
+
- Urdu (Script)
|
| 552 |
+
- Roman Urdu (Latin script)
|
| 553 |
+
|
| 554 |
+
**Note:** Auto Detect works best with clear text samples.
|
| 555 |
+
""")
|
| 556 |
|
| 557 |
+
# Event handlers
|
| 558 |
btn_analyze.click(
|
| 559 |
analyze_sentiment_complete,
|
| 560 |
inputs=[user_text, lang_dropdown],
|