Nattapong Tapachoom commited on
Commit
b4693b4
·
1 Parent(s): fad188f

Implement Gradio Blocks interface with modern UX/UI for Thai sentiment analysis

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py CHANGED
@@ -388,6 +388,70 @@ body, .gradio-container {
388
  }
389
  """
390
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391
  # Launch configuration
392
  if __name__ == "__main__":
393
  demo.queue(
 
388
  }
389
  """
390
 
391
+ # Gradio Blocks app definition
392
+ with gr.Blocks(css=CUSTOM_CSS, theme=gr.themes.Base()) as demo:
393
+ with gr.Column(elem_classes="main-uxui-card"):
394
+ with gr.Row():
395
+ gr.HTML("""
396
+ <div class='main-uxui-header'>
397
+ <h1>Thai Sentiment Analysis (SpaceThai-e5)</h1>
398
+ <p>วิเคราะห์ความรู้สึกภาษาไทย/อังกฤษ รองรับหลายโมเดล | Modern UX/UI</p>
399
+ </div>
400
+ """)
401
+ with gr.Row():
402
+ model_dropdown = gr.Dropdown(
403
+ choices=[(desc, name) for name, desc in MODEL_LIST],
404
+ value=MODEL_LIST[0][0],
405
+ label="เลือกโมเดล (Model)",
406
+ elem_classes="main-uxui-dropdown"
407
+ )
408
+ with gr.Row():
409
+ input_box = gr.Textbox(
410
+ lines=4,
411
+ placeholder="พิมพ์ข้อความภาษาไทยหรืออังกฤษ (รองรับหลายประโยค)",
412
+ label="ข้อความที่ต้องการวิเคราะห์",
413
+ elem_classes="main-uxui-input"
414
+ )
415
+ with gr.Row():
416
+ analyze_btn = gr.Button("วิเคราะห์", elem_classes="main-uxui-btn")
417
+ clear_btn = gr.Button("ล้างข้อมูล", elem_classes="main-uxui-btn secondary")
418
+ with gr.Row():
419
+ output_html = gr.HTML(label="ผลลัพธ์", elem_classes="main-uxui-output")
420
+ with gr.Row():
421
+ gr.Examples([
422
+ ["วันนี้อากาศดีมากๆ รู้สึกสดชื่นและมีความสุขมาก!"],
423
+ ["เศร้ามากเลยวันนี้ งานเยอะเกินไป"],
424
+ ["อาหารอร่อยดี แต่บริการช้ามาก"],
425
+ ["คุณคิดอย่างไรกับเศรษฐกิจไทย?"],
426
+ ["I love this product! It's amazing."],
427
+ ["This is the worst experience I've ever had."]
428
+ ],
429
+ inputs=input_box,
430
+ label="ตัวอย่างข้อความ",
431
+ )
432
+ with gr.Row():
433
+ gr.HTML("""
434
+ <div class='main-uxui-legend'>
435
+ <div class='main-uxui-section-title'>
436
+ <span>🗂️</span> คำอธิบายผลลัพธ์
437
+ </div>
438
+ <div class='legend-row'>
439
+ <div class='legend-item'><strong>😊 เชิงบวก</strong><br><small>Positive</small></div>
440
+ <div class='legend-item'><strong>😢 เชิงลบ</strong><br><small>Negative</small></div>
441
+ <div class='legend-item'><strong>😐 เป็นกลาง</strong><br><small>Neutral</small></div>
442
+ <div class='legend-item'><strong>🤔 คำถาม</strong><br><small>Question</small></div>
443
+ </div>
444
+ </div>
445
+ """)
446
+
447
+ def on_analyze(text, model):
448
+ return analyze_text(text, model)
449
+
450
+ analyze_btn.click(on_analyze, [input_box, model_dropdown], output_html)
451
+ input_box.submit(on_analyze, [input_box, model_dropdown], output_html)
452
+ model_dropdown.change(on_analyze, [input_box, model_dropdown], output_html)
453
+ clear_btn.click(lambda: (""), None, output_html)
454
+
455
  # Launch configuration
456
  if __name__ == "__main__":
457
  demo.queue(