Spaces:
Running
Running
Nattapong Tapachoom
commited on
Commit
·
fad188f
1
Parent(s):
28e39dc
Revamp Gradio interface with modern styling and improved user experience
Browse files
app.py
CHANGED
|
@@ -388,338 +388,6 @@ body, .gradio-container {
|
|
| 388 |
}
|
| 389 |
"""
|
| 390 |
|
| 391 |
-
# Create the modern Gradio interface
|
| 392 |
-
with gr.Blocks(css=CUSTOM_CSS, title="🧠 AI Thai Sentiment Analyzer - วิเคราะห์ความรู้สึกภาษาไทย") as demo:
|
| 393 |
-
gr.HTML("""
|
| 394 |
-
<div class='main-uxui-header'>
|
| 395 |
-
<h1>🧠 Thai Sentiment Analyzer</h1>
|
| 396 |
-
<p>AI วิเคราะห์ความรู้สึกภาษาไทยและหลายภาษา <br>ใช้งานง่าย รองรับหลายโมเดล</p>
|
| 397 |
-
</div>
|
| 398 |
-
""")
|
| 399 |
-
with gr.Row():
|
| 400 |
-
with gr.Column(scale=1):
|
| 401 |
-
gr.HTML("""
|
| 402 |
-
<div class='main-uxui-card'>
|
| 403 |
-
<div class='main-uxui-section-title'>
|
| 404 |
-
<span>🤖</span> เลือกโมเดล AI
|
| 405 |
-
</div>
|
| 406 |
-
""")
|
| 407 |
-
model_dropdown = gr.Dropdown(
|
| 408 |
-
choices=[choice[1] for choice in MODEL_LIST],
|
| 409 |
-
value="🏆 MultiSent E5 Pro - แนะนำ (ความแม่นยำสูงสุด)",
|
| 410 |
-
label="",
|
| 411 |
-
show_label=False,
|
| 412 |
-
elem_classes=["main-uxui-dropdown"]
|
| 413 |
-
)
|
| 414 |
-
gr.HTML("""
|
| 415 |
-
<div class='main-uxui-section-title' style='margin-top:28px;'>
|
| 416 |
-
<span>💡</span> วิธีใช้งาน
|
| 417 |
-
</div>
|
| 418 |
-
<ul style='color:#7da2e3; font-size:1em; line-height:1.7; margin-bottom:0; padding-left:18px;'>
|
| 419 |
-
<li>พิมพ์ข้อความภาษาไทยหรือภาษาอื่นที่ต้องการวิเคราะห์</li>
|
| 420 |
-
<li>แยกประโยคด้วยจุด (.) หรือขึ้นบรรทัดใหม่</li>
|
| 421 |
-
<li>รองรับการวิเคราะห์หลายประโยคพร้อมกัน</li>
|
| 422 |
-
<li>ผลลัพธ์จะแสดงความมั่นใจและสรุปภาพรวม</li>
|
| 423 |
-
</ul>
|
| 424 |
-
</div>
|
| 425 |
-
""")
|
| 426 |
-
with gr.Column(scale=2):
|
| 427 |
-
gr.HTML("""
|
| 428 |
-
<div class='main-uxui-card'>
|
| 429 |
-
<div class='main-uxui-section-title'>
|
| 430 |
-
<span>✍️</span> ข้อความที่ต้องการวิเคราะห์
|
| 431 |
-
</div>
|
| 432 |
-
""")
|
| 433 |
-
text_input = gr.Textbox(
|
| 434 |
-
lines=7,
|
| 435 |
-
placeholder="ตัวอย่าง: วันนี้อากาศดีมาก ฉันรู้สึกมีความสุขมาก สีฟ้าสวยจริงๆ\nแต่การจราจรติดมาก น่าเบื่อจริงๆ\nโดยรวมแล้วก็โอเคนะ",
|
| 436 |
-
label="",
|
| 437 |
-
show_label=False,
|
| 438 |
-
elem_classes=["main-uxui-input"]
|
| 439 |
-
)
|
| 440 |
-
with gr.Row():
|
| 441 |
-
analyze_btn = gr.Button("🔍 วิเคราะห์ข้อความ", elem_classes=["main-uxui-btn"])
|
| 442 |
-
clear_btn = gr.Button("🗑️ ล้างข้อความ", elem_classes=["main-uxui-btn", "secondary"])
|
| 443 |
-
output_box = gr.HTML("""
|
| 444 |
-
<div class='main-uxui-output'>
|
| 445 |
-
<div style='text-align:center; color:#7da2e3; font-size:1.2em;'>
|
| 446 |
-
<div style='font-size:2.5em; margin-bottom:10px;'>🤖</div>
|
| 447 |
-
พร้อมวิเคราะห์ความรู้สึก<br>ใส่ข้อความแล้วกดปุ่ม "วิเคราะห์ข้อความ"
|
| 448 |
-
</div>
|
| 449 |
-
</div>
|
| 450 |
-
""")
|
| 451 |
-
gr.HTML("""
|
| 452 |
-
<div class='main-uxui-card' style='margin-top:0;'>
|
| 453 |
-
<div class='main-uxui-section-title'><span>✨</span> ตัวอย่างข้อความ</div>
|
| 454 |
-
</div>
|
| 455 |
-
""")
|
| 456 |
-
examples = gr.Examples(
|
| 457 |
-
examples=[
|
| 458 |
-
["วันนี้อากาศดีมาก ฉันรู้สึกมีความสุขมาก สีฟ้าสวยจริงๆ"],
|
| 459 |
-
["ฉันไม่ชอบอาหารนี้เลย รสชาติแปลกมาก เค็มเกินไป"],
|
| 460 |
-
["วันนี้เป็นยังไงบ้าง?\nเรียนหนังสือกันไหม?\nมีงานอะไรให้ช่วยไหม?"],
|
| 461 |
-
["บริการดีมาก พนักงานใจดีและเป็นกันเอง\nแต่ของมีราคาแพงไปหน่อย\nโดยรวมแล้วพอใจครับ แนะนำให้เพื่อนมาลอง"],
|
| 462 |
-
["เมื่อไหร่จะได้เจอกันอีก คิดถึงมากเลย\nแต่ตอนนี้ต้องทำงานหนักก่อน เพื่ออนาคตที่ดี"]
|
| 463 |
-
],
|
| 464 |
-
inputs=[text_input],
|
| 465 |
-
label="",
|
| 466 |
-
examples_per_page=5
|
| 467 |
-
)
|
| 468 |
-
gr.HTML("""
|
| 469 |
-
<div class='main-uxui-legend'>
|
| 470 |
-
<div class='main-uxui-section-title'><span>🎯</span> คำอธิบายผลการวิเคราะห์</div>
|
| 471 |
-
<div class='legend-row'>
|
| 472 |
-
<div class='legend-item'>
|
| 473 |
-
<div style='font-size:28px;'>😊</div>
|
| 474 |
-
<strong>Positive</strong><br><small>ความรู้สึกเชิงบวก<br>ดี, สุข, ชอบ</small>
|
| 475 |
-
</div>
|
| 476 |
-
<div class='legend-item'>
|
| 477 |
-
<div style='font-size:28px;'>😢</div>
|
| 478 |
-
<strong>Negative</strong><br><small>ความรู้สึกเชิงลบ<br>เศร้า, โกรธ, ไม่ชอบ</small>
|
| 479 |
-
</div>
|
| 480 |
-
<div class='legend-item'>
|
| 481 |
-
<div style='font-size:28px;'>😐</div>
|
| 482 |
-
<strong>Neutral</strong><br><small>ความรู้สึกเป็นกลาง<br>ปกติ, พอใช้ได้</small>
|
| 483 |
-
</div>
|
| 484 |
-
<div class='legend-item'>
|
| 485 |
-
<div style='font-size:28px;'>🤔</div>
|
| 486 |
-
<strong>Question</strong><br><small>ประโยคคำถาม<br>อะไร, ไหน, เมื่อไหร่</small>
|
| 487 |
-
</div>
|
| 488 |
-
</div>
|
| 489 |
-
</div>
|
| 490 |
-
""")
|
| 491 |
-
|
| 492 |
-
with gr.Row(equal_height=False):
|
| 493 |
-
# Left Column - Controls
|
| 494 |
-
with gr.Column(scale=1):
|
| 495 |
-
# Model Selection Card
|
| 496 |
-
with gr.Group():
|
| 497 |
-
gr.HTML("""
|
| 498 |
-
<div style="background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%); color: #f8fafc; padding: 20px; border-radius: 16px 16px 0 0; margin: -20px -20px 20px -20px;">
|
| 499 |
-
<h3 style="margin: 0; font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px;">
|
| 500 |
-
<span style="font-size: 20px;">🤖</span>
|
| 501 |
-
เลือกโมเดล AI
|
| 502 |
-
</h3>
|
| 503 |
-
<p style="margin: 8px 0 0 0; opacity: 0.9; font-size: 14px;">เลือกโมเดลที่ต้องการใช้ในการวิเคราะห์</p>
|
| 504 |
-
</div>
|
| 505 |
-
""")
|
| 506 |
-
|
| 507 |
-
model_dropdown = gr.Dropdown(
|
| 508 |
-
choices=[choice[1] for choice in MODEL_LIST],
|
| 509 |
-
value="🏆 MultiSent E5 Pro - แนะนำ (ความแม่นยำสูงสุด)",
|
| 510 |
-
label="",
|
| 511 |
-
show_label=False,
|
| 512 |
-
container=False
|
| 513 |
-
)
|
| 514 |
-
|
| 515 |
-
# Tips Card
|
| 516 |
-
with gr.Group():
|
| 517 |
-
gr.HTML("""
|
| 518 |
-
<div style="background: linear-gradient(135deg, #1e40af 0%, #1e293b 100%); padding: 20px; border-radius: 16px;">
|
| 519 |
-
<h4 style="color: #f8fafc; margin: 0 0 16px 0; font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px;">
|
| 520 |
-
<span style="font-size: 18px;">💡</span>
|
| 521 |
-
เคล็ดลับการใช้งาน
|
| 522 |
-
</h4>
|
| 523 |
-
<div style="color: #cbd5e1; font-size: 14px; line-height: 1.6;">
|
| 524 |
-
<div style="margin-bottom: 12px; display: flex; align-items: flex-start; gap: 8px;">
|
| 525 |
-
<span style="color: #60a5fa; font-weight: 600;">•</span>
|
| 526 |
-
<span>พิมพ์ข้อความภาษาไทยที่ต้องการวิเคราะห์</span>
|
| 527 |
-
</div>
|
| 528 |
-
<div style="margin-bottom: 12px; display: flex; align-items: flex-start; gap: 8px;">
|
| 529 |
-
<span style="color: #60a5fa; font-weight: 600;">•</span>
|
| 530 |
-
<span>แยกประโยคด้วยจุด (.) หรือขึ้นบรรทัดใหม่</span>
|
| 531 |
-
</div>
|
| 532 |
-
<div style="margin-bottom: 12px; display: flex; align-items: flex-start; gap: 8px;">
|
| 533 |
-
<span style="color: #60a5fa; font-weight: 600;">•</span>
|
| 534 |
-
<span>สามารถวิเคราะห์หลายประโยคพร้อมกันได้</span>
|
| 535 |
-
</div>
|
| 536 |
-
<div style="display: flex; align-items: flex-start; gap: 8px;">
|
| 537 |
-
<span style="color: #60a5fa; font-weight: 600;">•</span>
|
| 538 |
-
<span>ผลลัพธ์จะแสดงความมั่นใจและสรุปภาพรวม</span>
|
| 539 |
-
</div>
|
| 540 |
-
</div>
|
| 541 |
-
</div>
|
| 542 |
-
""")
|
| 543 |
-
|
| 544 |
-
# Right Column - Main Interface
|
| 545 |
-
with gr.Column(scale=2):
|
| 546 |
-
# Input Section
|
| 547 |
-
with gr.Group():
|
| 548 |
-
gr.HTML("""
|
| 549 |
-
<div style="background: linear-gradient(135deg, #1e40af 0%, #1e293b 100%); padding: 20px; border-radius: 16px 16px 0 0; margin: -20px -20px 20px -20px;">
|
| 550 |
-
<h3 style="color: #f8fafc; margin: 0; font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px;">
|
| 551 |
-
<span style="font-size: 20px;">✍️</span>
|
| 552 |
-
ข้อความที่ต้องการวิเคราะห์
|
| 553 |
-
</h3>
|
| 554 |
-
</div>
|
| 555 |
-
""")
|
| 556 |
-
|
| 557 |
-
text_input = gr.Textbox(
|
| 558 |
-
lines=6,
|
| 559 |
-
placeholder="💭 ลองพิมพ์ข้อความที่ต้องการวิเคราะห์...\n\nตัวอย่าง:\nวันนี้อากาศดีมาก ฉันรู้สึกมีความสุข ☀️\nแต่การจราจรติดมาก น่าเบื่อจริงๆ 😤\nโดยรวมแล้วก็โอเคนะ 😊",
|
| 560 |
-
label="",
|
| 561 |
-
show_label=False,
|
| 562 |
-
container=False
|
| 563 |
-
)
|
| 564 |
-
|
| 565 |
-
with gr.Row():
|
| 566 |
-
analyze_btn = gr.Button(
|
| 567 |
-
"🔍 วิเคราะห์ข้อความ",
|
| 568 |
-
variant="primary",
|
| 569 |
-
size="lg",
|
| 570 |
-
scale=2
|
| 571 |
-
)
|
| 572 |
-
clear_btn = gr.Button(
|
| 573 |
-
"🗑️ ล้าง",
|
| 574 |
-
variant="secondary",
|
| 575 |
-
scale=1
|
| 576 |
-
)
|
| 577 |
-
|
| 578 |
-
# Output Section
|
| 579 |
-
with gr.Row():
|
| 580 |
-
with gr.Column():
|
| 581 |
-
output_box = gr.HTML(
|
| 582 |
-
label="📊 ผลการวิเคราะห์",
|
| 583 |
-
value="""
|
| 584 |
-
<div style="padding: 60px 20px; text-align: center; color: #94a3b8; background: rgba(30, 41, 59, 0.9); border-radius: 16px; border: 2px dashed #334155;">
|
| 585 |
-
<div style="font-size: 48px; margin-bottom: 16px;">🤖</div>
|
| 586 |
-
<h3 style="color: #f8fafc; margin: 0 0 8px 0;">พร้อมวิเคราะห์ความรู้สึก</h3>
|
| 587 |
-
<p style="margin: 0; font-size: 14px;">ใส่ข้อความด้านบนแล้วกดปุ่ม "วิเคราะห์ข้อความ"</p>
|
| 588 |
-
</div>
|
| 589 |
-
"""
|
| 590 |
-
)
|
| 591 |
-
|
| 592 |
-
# Examples Section
|
| 593 |
-
gr.HTML("""
|
| 594 |
-
<div style="margin: 40px 0 20px 0;">
|
| 595 |
-
<h3 style="color: #f8fafc; text-align: center; font-size: 20px; font-weight: 700; margin-bottom: 20px; text-shadow: 0 2px 4px rgba(0,0,0,0.4);">
|
| 596 |
-
✨ ตัวอย่างการใช้งาน
|
| 597 |
-
</h3>
|
| 598 |
-
</div>
|
| 599 |
-
""")
|
| 600 |
-
|
| 601 |
-
examples = gr.Examples(
|
| 602 |
-
examples=[
|
| 603 |
-
["วันนี้อากาศดีมาก ฉันรู้สึกมีความสุขมาก ☀️ สีฟ้าสวยจริงๆ น่ามองจัง"],
|
| 604 |
-
["ฉันไม่ชอบอาหารนี้เลย 😤 รสชาติแปลกมาก เค็มเกินไป ไม่อร่อยเลย"],
|
| 605 |
-
["วันนี้เป็นยังไงบ้าง? 🤔\nเรียนหนังสือกันไหม? 📚\nมีงานอะไรให้ช่วยไหม? 💪"],
|
| 606 |
-
["บริการดีมาก 👍 พนักงานใจดีและเป็นกันเอง\nแต่ของมีราคาแพงไปหน่อย 💸\nโดยรวมแล้วพอใจครับ แนะนำให้เพื่อนมาลอง ⭐"],
|
| 607 |
-
["เมื่อไหร่จะได้เจอกันอีก 😢 คิดถึงมากเลย\nแต่ตอนนี้ต้องทำงานหนักก่อน 💪 เพื่ออนาคตที่ดี ✨"]
|
| 608 |
-
],
|
| 609 |
-
inputs=[text_input],
|
| 610 |
-
label="",
|
| 611 |
-
examples_per_page=5
|
| 612 |
-
)
|
| 613 |
-
|
| 614 |
-
# Legend Section
|
| 615 |
-
gr.HTML("""
|
| 616 |
-
<div style="margin: 40px 0 20px 0; background: rgba(30, 58, 138, 0.9); backdrop-filter: blur(10px); border-radius: 20px; padding: 30px; border: 1px solid rgba(59, 130, 246, 0.3);">
|
| 617 |
-
<h3 style="color: #f8fafc; text-align: center; font-size: 22px; font-weight: 700; margin-bottom: 25px; text-shadow: 0 2px 4px rgba(0,0,0,0.4);">
|
| 618 |
-
🎯 คำอธิบายผลการวิเคราะห์
|
| 619 |
-
</h3>
|
| 620 |
-
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px;">
|
| 621 |
-
<div style="background: rgba(52, 211, 153, 0.2); backdrop-filter: blur(10px); border-radius: 16px; padding: 20px; text-align: center; border: 1px solid rgba(52, 211, 153, 0.3); transition: all 0.3s ease;" onmouseover="this.style.transform='translateY(-5px)'; this.style.boxShadow='0 10px 25px rgba(52, 211, 153, 0.3)'" onmouseout="this.style.transform='translateY(0)'; this.style.boxShadow='none'">
|
| 622 |
-
<div style="font-size: 36px; margin-bottom: 12px;">😊</div>
|
| 623 |
-
<h4 style="color: #34d399; margin: 0 0 8px 0; font-size: 16px; font-weight: 700;">POSITIVE</h4>
|
| 624 |
-
<p style="color: #cbd5e1; margin: 0; font-size: 13px; line-height: 1.4;">ความรู้สึกเชิงบวก<br>ดี, สุข, ชอบ, ยินดี</p>
|
| 625 |
-
</div>
|
| 626 |
-
<div style="background: rgba(248, 113, 113, 0.2); backdrop-filter: blur(10px); border-radius: 16px; padding: 20px; text-align: center; border: 1px solid rgba(248, 113, 113, 0.3); transition: all 0.3s ease;" onmouseover="this.style.transform='translateY(-5px)'; this.style.boxShadow='0 10px 25px rgba(248, 113, 113, 0.3)'" onmouseout="this.style.transform='translateY(0)'; this.style.boxShadow='none'">
|
| 627 |
-
<div style="font-size: 36px; margin-bottom: 12px;">😢</div>
|
| 628 |
-
<h4 style="color: #f87171; margin: 0 0 8px 0; font-size: 16px; font-weight: 700;">NEGATIVE</h4>
|
| 629 |
-
<p style="color: #cbd5e1; margin: 0; font-size: 13px; line-height: 1.4;">ความรู้สึกเชิงลบ<br>เศร้า, โกรธ, ไม่ชอบ</p>
|
| 630 |
-
</div>
|
| 631 |
-
<div style="background: rgba(250, 204, 21, 0.2); backdrop-filter: blur(10px); border-radius: 16px; padding: 20px; text-align: center; border: 1px solid rgba(250, 204, 21, 0.3); transition: all 0.3s ease;" onmouseover="this.style.transform='translateY(-5px)'; this.style.boxShadow='0 10px 25px rgba(250, 204, 21, 0.3)'" onmouseout="this.style.transform='translateY(0)'; this.style.boxShadow='none'">
|
| 632 |
-
<div style="font-size: 36px; margin-bottom: 12px;">😐</div>
|
| 633 |
-
<h4 style="color: #facc15; margin: 0 0 8px 0; font-size: 16px; font-weight: 700;">NEUTRAL</h4>
|
| 634 |
-
<p style="color: #cbd5e1; margin: 0; font-size: 13px; line-height: 1.4;">ความรู้สึกเป็นกลาง<br>ปกติ, พอใช้ได้, ธรรมดา</p>
|
| 635 |
-
</div>
|
| 636 |
-
<div style="background: rgba(96, 165, 250, 0.2); backdrop-filter: blur(10px); border-radius: 16px; padding: 20px; text-align: center; border: 1px solid rgba(96, 165, 250, 0.3); transition: all 0.3s ease;" onmouseover="this.style.transform='translateY(-5px)'; this.style.boxShadow='0 10px 25px rgba(96, 165, 250, 0.3)'" onmouseout="this.style.transform='translateY(0)'; this.style.boxShadow='none'">
|
| 637 |
-
<div style="font-size: 36px; margin-bottom: 12px;">🤔</div>
|
| 638 |
-
<h4 style="color: #60a5fa; margin: 0 0 8px 0; font-size: 16px; font-weight: 700;">QUESTION</h4>
|
| 639 |
-
<p style="color: #cbd5e1; margin: 0; font-size: 13px; line-height: 1.4;">ประโยคคำถาม<br>อะไร, ไหน, เมื่อไหร่</p>
|
| 640 |
-
</div>
|
| 641 |
-
</div>
|
| 642 |
-
</div>
|
| 643 |
-
""")
|
| 644 |
-
|
| 645 |
-
# Footer
|
| 646 |
-
gr.HTML("""
|
| 647 |
-
<div style="text-align: center; padding: 30px 0 10px 0;">
|
| 648 |
-
<p style="color: #cbd5e1; font-size: 14px; margin: 0; text-shadow: 0 1px 2px rgba(0,0,0,0.4);">
|
| 649 |
-
พัฒนาด้วย ❤️ โดยใช้ Transformers และ Gradio | รองรับโมเดล AI หลากหลาย
|
| 650 |
-
</p>
|
| 651 |
-
</div>
|
| 652 |
-
""")
|
| 653 |
-
|
| 654 |
-
# Event handlers with enhanced functionality
|
| 655 |
-
def analyze_wrapper(text, model_display_name):
|
| 656 |
-
if not text.strip():
|
| 657 |
-
return """
|
| 658 |
-
<div style="padding: 60px 20px; text-align: center; color: #94a3b8; background: rgba(30, 41, 59, 0.9); border-radius: 16px; border: 2px dashed #334155;">
|
| 659 |
-
<div style="font-size: 48px; margin-bottom: 16px;">⚠️</div>
|
| 660 |
-
<h3 style="color: #f87171; margin: 0 0 8px 0;">กรุณาใส่ข้อความ</h3>
|
| 661 |
-
<p style="margin: 0; font-size: 14px;">ใส่ข้อความที่ต้องการวิเคราะห์ในช่องด้านบน</p>
|
| 662 |
-
</div>
|
| 663 |
-
"""
|
| 664 |
-
|
| 665 |
-
# Find actual model name from display name
|
| 666 |
-
model_name = None
|
| 667 |
-
for model_tuple in MODEL_LIST:
|
| 668 |
-
if model_tuple[1] == model_display_name:
|
| 669 |
-
model_name = model_tuple[0]
|
| 670 |
-
break
|
| 671 |
-
|
| 672 |
-
if not model_name:
|
| 673 |
-
model_name = "ZombitX64/MultiSent-E5-Pro" # fallback
|
| 674 |
-
|
| 675 |
-
return analyze_text(text, model_name)
|
| 676 |
-
|
| 677 |
-
def clear_text():
|
| 678 |
-
return "", """
|
| 679 |
-
<div style="padding: 60px 20px; text-align: center; color: #94a3b8; background: rgba(30, 41, 59, 0.9); border-radius: 16px; border: 2px dashed #334155;">
|
| 680 |
-
<div style="font-size: 48px; margin-bottom: 16px;">🤖</div>
|
| 681 |
-
<h3 style="color: #f8fafc; margin: 0 0 8px 0;">��ร้อมวิเคราะห์ความรู้สึก</h3>
|
| 682 |
-
<p style="margin: 0; font-size: 14px;">ใส่ข้อความด้านบนแล้วกดปุ่ม "วิเคราะห์ข้อความ"</p>
|
| 683 |
-
</div>
|
| 684 |
-
"""
|
| 685 |
-
|
| 686 |
-
def auto_analyze(text, model_display_name):
|
| 687 |
-
if text.strip():
|
| 688 |
-
return analyze_wrapper(text, model_display_name)
|
| 689 |
-
return """
|
| 690 |
-
<div style="padding: 60px 20px; text-align: center; color: #94a3b8; background: rgba(30, 41, 59, 0.9); border-radius: 16px; border: 2px dashed #334155;">
|
| 691 |
-
<div style="font-size: 48px; margin-bottom: 16px;">🤖</div>
|
| 692 |
-
<h3 style="color: #f8fafc; margin: 0 0 8px 0;">พร้อมวิเคราะห์ความรู้สึก</h3>
|
| 693 |
-
<p style="margin: 0; font-size: 14px;">ใส่ข้อความด้านบนแล้วกดปุ่ม "วิเคราะห์ข้อความ"</p>
|
| 694 |
-
</div>
|
| 695 |
-
"""
|
| 696 |
-
|
| 697 |
-
# Connect events
|
| 698 |
-
analyze_btn.click(
|
| 699 |
-
analyze_wrapper,
|
| 700 |
-
inputs=[text_input, model_dropdown],
|
| 701 |
-
outputs=output_box,
|
| 702 |
-
show_progress=True
|
| 703 |
-
)
|
| 704 |
-
|
| 705 |
-
text_input.submit(
|
| 706 |
-
analyze_wrapper,
|
| 707 |
-
inputs=[text_input, model_dropdown],
|
| 708 |
-
outputs=output_box,
|
| 709 |
-
show_progress=True
|
| 710 |
-
)
|
| 711 |
-
|
| 712 |
-
model_dropdown.change(
|
| 713 |
-
auto_analyze,
|
| 714 |
-
inputs=[text_input, model_dropdown],
|
| 715 |
-
outputs=output_box
|
| 716 |
-
)
|
| 717 |
-
|
| 718 |
-
clear_btn.click(
|
| 719 |
-
clear_text,
|
| 720 |
-
outputs=[text_input, output_box]
|
| 721 |
-
)
|
| 722 |
-
|
| 723 |
# Launch configuration
|
| 724 |
if __name__ == "__main__":
|
| 725 |
demo.queue(
|
|
|
|
| 388 |
}
|
| 389 |
"""
|
| 390 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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