Spaces:
Running
Running
Nattapong Tapachoom
commited on
Commit
·
ef1d1b7
1
Parent(s):
41cdf64
Implement feature X to enhance user experience and fix bug Y in module Z
Browse files
app.py
CHANGED
|
@@ -36,19 +36,19 @@ def get_nlp(model_name: str):
|
|
| 36 |
logger.error(f"Error loading model {model_name}: {e}")
|
| 37 |
raise gr.Error(f"ไม่สามารถโหลดโมเดล {model_name} ได้: {str(e)}")
|
| 38 |
|
| 39 |
-
# Enhanced label mapping with modern styling
|
| 40 |
LABEL_MAPPINGS = {
|
| 41 |
-
"LABEL_0": {"code": 0, "name": "question", "emoji": "🤔", "color": "#
|
| 42 |
-
"LABEL_1": {"code": 1, "name": "negative", "emoji": "😢", "color": "#
|
| 43 |
-
"LABEL_2": {"code": 2, "name": "neutral", "emoji": "😐", "color": "#
|
| 44 |
-
"LABEL_3": {"code": 3, "name": "positive", "emoji": "😊", "color": "#
|
| 45 |
|
| 46 |
-
"POSITIVE": {"code": 3, "name": "positive", "emoji": "😊", "color": "#
|
| 47 |
-
"NEGATIVE": {"code": 1, "name": "negative", "emoji": "😢", "color": "#
|
| 48 |
-
"NEUTRAL": {"code": 2, "name": "neutral", "emoji": "😐", "color": "#
|
| 49 |
|
| 50 |
-
"0": {"code": 0, "name": "negative", "emoji": "😢", "color": "#
|
| 51 |
-
"1": {"code": 1, "name": "positive", "emoji": "😊", "color": "#
|
| 52 |
}
|
| 53 |
|
| 54 |
def get_label_info(label: str) -> Dict:
|
|
@@ -57,8 +57,8 @@ def get_label_info(label: str) -> Dict:
|
|
| 57 |
"code": -1,
|
| 58 |
"name": label.lower(),
|
| 59 |
"emoji": "🔍",
|
| 60 |
-
"color": "#
|
| 61 |
-
"bg": "rgba(
|
| 62 |
"description": "ไม่ทราบ"
|
| 63 |
})
|
| 64 |
|
|
@@ -73,10 +73,10 @@ def create_confidence_bar(score: float) -> str:
|
|
| 73 |
percentage = int(score * 100)
|
| 74 |
return f"""
|
| 75 |
<div style="display: flex; align-items: center; gap: 10px; margin: 8px 0;">
|
| 76 |
-
<div style="flex: 1; height: 8px; background: #
|
| 77 |
-
<div style="width: {percentage}%; height: 100%; background: linear-gradient(90deg, #
|
| 78 |
</div>
|
| 79 |
-
<span style="font-weight: 600; color: #
|
| 80 |
</div>
|
| 81 |
"""
|
| 82 |
|
|
@@ -84,8 +84,8 @@ def analyze_text(text: str, model_name: str) -> str:
|
|
| 84 |
"""Enhanced text analysis with modern HTML formatting"""
|
| 85 |
if not text or not text.strip():
|
| 86 |
return """
|
| 87 |
-
<div style="padding: 20px; background: rgba(
|
| 88 |
-
<div style="color: #
|
| 89 |
<span style="font-size: 20px;">⚠️</span>
|
| 90 |
กรุณาใส่ข้อความที่ต้องการวิเคราะห์
|
| 91 |
</div>
|
|
@@ -96,8 +96,8 @@ def analyze_text(text: str, model_name: str) -> str:
|
|
| 96 |
|
| 97 |
if not sentences:
|
| 98 |
return """
|
| 99 |
-
<div style="padding: 20px; background: rgba(
|
| 100 |
-
<div style="color: #
|
| 101 |
<span style="font-size: 20px;">⚠️</span>
|
| 102 |
ไม่พบประโยคที่สามารถวิเคราะห์ได้ กรุณาใส่ข้อความที่ยาวกว่านี้
|
| 103 |
</div>
|
|
@@ -108,8 +108,8 @@ def analyze_text(text: str, model_name: str) -> str:
|
|
| 108 |
nlp = get_nlp(model_name)
|
| 109 |
except Exception as e:
|
| 110 |
return f"""
|
| 111 |
-
<div style="padding: 20px; background: rgba(
|
| 112 |
-
<div style="color: #
|
| 113 |
<span style="font-size: 20px;">❌</span>
|
| 114 |
เกิดข้อผิดพลาดในการโหลดโมเดล: {str(e)}
|
| 115 |
</div>
|
|
@@ -118,7 +118,7 @@ def analyze_text(text: str, model_name: str) -> str:
|
|
| 118 |
|
| 119 |
# Header
|
| 120 |
html_parts = ["""
|
| 121 |
-
<div style="background: linear-gradient(135deg, #
|
| 122 |
<h2 style="margin: 0; font-size: 24px; font-weight: 700; display: flex; align-items: center; gap: 12px;">
|
| 123 |
<span style="font-size: 28px;">🧠</span>
|
| 124 |
ผลการวิเคราะห์ความรู้สึก
|
|
@@ -166,19 +166,19 @@ def analyze_text(text: str, model_name: str) -> str:
|
|
| 166 |
|
| 167 |
# Results container
|
| 168 |
html_parts.append("""
|
| 169 |
-
<div style="background:
|
| 170 |
""")
|
| 171 |
|
| 172 |
# Individual sentence results
|
| 173 |
for result in sentence_results:
|
| 174 |
if 'error' in result:
|
| 175 |
html_parts.append(f"""
|
| 176 |
-
<div style="padding: 20px; border-bottom: 1px solid #
|
| 177 |
-
<div style="color: #
|
| 178 |
<span style="font-size: 18px;">❌</span>
|
| 179 |
เกิดข้อผิดพลาดในการวิเคราะห์ประโยคที่ {result['index']}
|
| 180 |
</div>
|
| 181 |
-
<p style="color: #
|
| 182 |
</div>
|
| 183 |
""")
|
| 184 |
else:
|
|
@@ -186,22 +186,22 @@ def analyze_text(text: str, model_name: str) -> str:
|
|
| 186 |
confidence_bar = create_confidence_bar(result['score'])
|
| 187 |
|
| 188 |
html_parts.append(f"""
|
| 189 |
-
<div style="padding: 20px; border-bottom: 1px solid #
|
| 190 |
<div style="display: flex; align-items: flex-start; gap: 16px;">
|
| 191 |
<div style="background: {label_info['bg']}; padding: 12px; border-radius: 50%; min-width: 48px; height: 48px; display: flex; align-items: center; justify-content: center;">
|
| 192 |
<span style="font-size: 20px;">{label_info['emoji']}</span>
|
| 193 |
</div>
|
| 194 |
<div style="flex: 1;">
|
| 195 |
<div style="display: flex; align-items: center; gap: 8px; margin-bottom: 8px;">
|
| 196 |
-
<span style="background: {label_info['color']}; color:
|
| 197 |
{label_info['description']}
|
| 198 |
</span>
|
| 199 |
-
<span style="color: #
|
| 200 |
</div>
|
| 201 |
-
<p style="color: #
|
| 202 |
"{result['sentence'][:150]}{'...' if len(result['sentence']) > 150 else ''}"
|
| 203 |
</p>
|
| 204 |
-
<div style="color: #
|
| 205 |
{confidence_bar}
|
| 206 |
</div>
|
| 207 |
</div>
|
|
@@ -214,40 +214,40 @@ def analyze_text(text: str, model_name: str) -> str:
|
|
| 214 |
|
| 215 |
# Create chart data for summary
|
| 216 |
chart_items = []
|
| 217 |
-
colors = {"positive": "#
|
| 218 |
emojis = {"positive": "😊", "negative": "😢", "neutral": "😐", "question": "🤔", "other": "🔍"}
|
| 219 |
|
| 220 |
for sentiment, count in sentiment_counts.items():
|
| 221 |
if count > 0:
|
| 222 |
percentage = (count / total_sentences) * 100
|
| 223 |
chart_items.append(f"""
|
| 224 |
-
<div style="display: flex; align-items: center; gap: 12px; padding: 12px; background: rgba(
|
| 225 |
<span style="font-size: 24px;">{emojis.get(sentiment, '🔍')}</span>
|
| 226 |
<div style="flex: 1;">
|
| 227 |
-
<div style="font-weight: 600; color: #
|
| 228 |
-
<div style="color: #
|
| 229 |
</div>
|
| 230 |
-
<div style="width: 60px; height: 6px; background: #
|
| 231 |
-
<div style="width: {percentage}%; height: 100%; background: {colors.get(sentiment, '#
|
| 232 |
</div>
|
| 233 |
</div>
|
| 234 |
""")
|
| 235 |
|
| 236 |
html_parts.append(f"""
|
| 237 |
-
<div style="padding: 24px; background: linear-gradient(135deg, #
|
| 238 |
-
<h3 style="color: #
|
| 239 |
<span style="font-size: 24px;">📊</span>
|
| 240 |
สรุปผลการวิเคราะห์
|
| 241 |
</h3>
|
| 242 |
|
| 243 |
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px;">
|
| 244 |
-
<div style="background:
|
| 245 |
-
<div style="font-size: 32px; font-weight: 700; color: #
|
| 246 |
-
<div style="color: #
|
| 247 |
</div>
|
| 248 |
-
<div style="background:
|
| 249 |
-
<div style="font-size: 32px; font-weight: 700; color: #
|
| 250 |
-
<div style="color: #
|
| 251 |
</div>
|
| 252 |
</div>
|
| 253 |
|
|
@@ -261,7 +261,7 @@ def analyze_text(text: str, model_name: str) -> str:
|
|
| 261 |
|
| 262 |
return "".join(html_parts)
|
| 263 |
|
| 264 |
-
# Modern CSS with
|
| 265 |
CUSTOM_CSS = """
|
| 266 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');
|
| 267 |
|
|
@@ -272,36 +272,36 @@ CUSTOM_CSS = """
|
|
| 272 |
.gradio-container {
|
| 273 |
max-width: 1200px !important;
|
| 274 |
margin: 0 auto !important;
|
| 275 |
-
background: linear-gradient(135deg, #
|
| 276 |
min-height: 100vh;
|
| 277 |
padding: 20px;
|
| 278 |
}
|
| 279 |
|
| 280 |
.main-content {
|
| 281 |
-
background: rgba(
|
| 282 |
backdrop-filter: blur(20px) !important;
|
| 283 |
border-radius: 24px !important;
|
| 284 |
-
box-shadow: 0 8px 32px rgba(
|
| 285 |
-
border: 1px solid rgba(
|
| 286 |
overflow: hidden;
|
| 287 |
}
|
| 288 |
|
| 289 |
.glass-card {
|
| 290 |
-
background: rgba(
|
| 291 |
-
backdrop-filter: blur(
|
| 292 |
border-radius: 16px !important;
|
| 293 |
-
border: 1px solid rgba(
|
| 294 |
-
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.
|
| 295 |
transition: all 0.3s ease !important;
|
| 296 |
}
|
| 297 |
|
| 298 |
.glass-card:hover {
|
| 299 |
transform: translateY(-2px) !important;
|
| 300 |
-
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.
|
| 301 |
}
|
| 302 |
|
| 303 |
.gr-button {
|
| 304 |
-
background: linear-gradient(135deg, #
|
| 305 |
border: none !important;
|
| 306 |
border-radius: 12px !important;
|
| 307 |
padding: 12px 24px !important;
|
|
@@ -309,47 +309,50 @@ CUSTOM_CSS = """
|
|
| 309 |
text-transform: uppercase !important;
|
| 310 |
letter-spacing: 0.5px !important;
|
| 311 |
transition: all 0.3s ease !important;
|
| 312 |
-
box-shadow: 0 4px 15px rgba(
|
|
|
|
| 313 |
}
|
| 314 |
|
| 315 |
.gr-button:hover {
|
| 316 |
transform: translateY(-2px) !important;
|
| 317 |
-
box-shadow: 0 6px 20px rgba(
|
| 318 |
}
|
| 319 |
|
| 320 |
.gr-button.secondary {
|
| 321 |
-
background: linear-gradient(135deg, #
|
| 322 |
-
box-shadow: 0 4px 15px rgba(
|
| 323 |
}
|
| 324 |
|
| 325 |
.gr-button.secondary:hover {
|
| 326 |
-
box-shadow: 0 6px 20px rgba(
|
| 327 |
}
|
| 328 |
|
| 329 |
.gr-textbox textarea, .gr-textbox input {
|
| 330 |
border-radius: 12px !important;
|
| 331 |
-
border: 2px solid rgba(
|
| 332 |
font-size: 16px !important;
|
| 333 |
padding: 16px !important;
|
| 334 |
transition: all 0.3s ease !important;
|
| 335 |
-
background: rgba(
|
|
|
|
| 336 |
}
|
| 337 |
|
| 338 |
.gr-textbox textarea:focus, .gr-textbox input:focus {
|
| 339 |
-
border-color: #
|
| 340 |
-
box-shadow: 0 0 0 3px rgba(
|
| 341 |
transform: scale(1.01) !important;
|
| 342 |
}
|
| 343 |
|
| 344 |
.gr-dropdown > div {
|
| 345 |
border-radius: 12px !important;
|
| 346 |
-
border: 2px solid rgba(
|
| 347 |
-
background: rgba(
|
|
|
|
| 348 |
}
|
| 349 |
|
| 350 |
.gr-dropdown > div:focus-within {
|
| 351 |
-
border-color: #
|
| 352 |
-
box-shadow: 0 0 0 3px rgba(
|
| 353 |
}
|
| 354 |
|
| 355 |
.gr-panel {
|
|
@@ -374,17 +377,17 @@ CUSTOM_CSS = """
|
|
| 374 |
}
|
| 375 |
|
| 376 |
::-webkit-scrollbar-track {
|
| 377 |
-
background: rgba(
|
| 378 |
border-radius: 4px;
|
| 379 |
}
|
| 380 |
|
| 381 |
::-webkit-scrollbar-thumb {
|
| 382 |
-
background: rgba(
|
| 383 |
border-radius: 4px;
|
| 384 |
}
|
| 385 |
|
| 386 |
::-webkit-scrollbar-thumb:hover {
|
| 387 |
-
background: rgba(
|
| 388 |
}
|
| 389 |
|
| 390 |
/* Animation for content */
|
|
@@ -410,16 +413,17 @@ CUSTOM_CSS = """
|
|
| 410 |
}
|
| 411 |
|
| 412 |
.gr-examples .gr-button {
|
| 413 |
-
background: rgba(
|
| 414 |
-
border: 1px solid rgba(
|
| 415 |
margin: 4px !important;
|
| 416 |
font-size: 14px !important;
|
| 417 |
text-transform: none !important;
|
| 418 |
letter-spacing: normal !important;
|
|
|
|
| 419 |
}
|
| 420 |
|
| 421 |
.gr-examples .gr-button:hover {
|
| 422 |
-
background: rgba(
|
| 423 |
transform: scale(1.02) !important;
|
| 424 |
}
|
| 425 |
"""
|
|
@@ -428,7 +432,7 @@ CUSTOM_CSS = """
|
|
| 428 |
with gr.Blocks(
|
| 429 |
theme=gr.themes.Glass(
|
| 430 |
primary_hue="blue",
|
| 431 |
-
secondary_hue="
|
| 432 |
neutral_hue="slate",
|
| 433 |
font=["Inter", "Noto Sans Thai", "sans-serif"]
|
| 434 |
),
|
|
@@ -436,15 +440,15 @@ with gr.Blocks(
|
|
| 436 |
title="🧠 AI Thai Sentiment Analyzer - วิเคราะห์ความรู้สึกภาษาไทย"
|
| 437 |
) as demo:
|
| 438 |
|
| 439 |
-
# Header with
|
| 440 |
gr.HTML("""
|
| 441 |
<div style="text-align: center; padding: 40px 0 30px 0;">
|
| 442 |
-
<div style="display: inline-block; background: rgba(
|
| 443 |
-
<h1 style="font-size: 3.5em; margin: 0; color:
|
| 444 |
<span style="font-size: 1.2em;">🧠</span>
|
| 445 |
Thai Sentiment AI
|
| 446 |
</h1>
|
| 447 |
-
<p style="font-size: 1.4em; color:
|
| 448 |
ระบบวิเคราะห์ความรู้สึกภาษาไทยด้วย AI ที่ทันสมัยและแม่นยำ
|
| 449 |
</p>
|
| 450 |
</div>
|
|
@@ -457,7 +461,7 @@ with gr.Blocks(
|
|
| 457 |
# Model Selection Card
|
| 458 |
with gr.Group():
|
| 459 |
gr.HTML("""
|
| 460 |
-
<div style="background: linear-gradient(135deg, #
|
| 461 |
<h3 style="margin: 0; font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px;">
|
| 462 |
<span style="font-size: 20px;">🤖</span>
|
| 463 |
เลือกโมเดล AI
|
|
@@ -477,26 +481,26 @@ with gr.Blocks(
|
|
| 477 |
# Tips Card
|
| 478 |
with gr.Group():
|
| 479 |
gr.HTML("""
|
| 480 |
-
<div style="background: linear-gradient(135deg, #
|
| 481 |
-
<h4 style="color: #
|
| 482 |
<span style="font-size: 18px;">💡</span>
|
| 483 |
เคล็ดลับการใช้งาน
|
| 484 |
</h4>
|
| 485 |
-
<div style="color: #
|
| 486 |
<div style="margin-bottom: 12px; display: flex; align-items: flex-start; gap: 8px;">
|
| 487 |
-
<span style="color: #
|
| 488 |
<span>พิมพ์ข้อความภาษาไทยที่ต้องการวิเคราะห์</span>
|
| 489 |
</div>
|
| 490 |
<div style="margin-bottom: 12px; display: flex; align-items: flex-start; gap: 8px;">
|
| 491 |
-
<span style="color: #
|
| 492 |
<span>แยกประโยคด้วยจุด (.) หรือขึ้นบรรทัดใหม่</span>
|
| 493 |
</div>
|
| 494 |
<div style="margin-bottom: 12px; display: flex; align-items: flex-start; gap: 8px;">
|
| 495 |
-
<span style="color: #
|
| 496 |
<span>สามารถวิเคราะห์หลายประโยคพร้อมกันได้</span>
|
| 497 |
</div>
|
| 498 |
<div style="display: flex; align-items: flex-start; gap: 8px;">
|
| 499 |
-
<span style="color: #
|
| 500 |
<span>ผลลัพธ์จะแสดงความมั่นใจและสรุปภาพรวม</span>
|
| 501 |
</div>
|
| 502 |
</div>
|
|
@@ -508,8 +512,8 @@ with gr.Blocks(
|
|
| 508 |
# Input Section
|
| 509 |
with gr.Group():
|
| 510 |
gr.HTML("""
|
| 511 |
-
<div style="background: linear-gradient(135deg, #
|
| 512 |
-
<h3 style="color: #
|
| 513 |
<span style="font-size: 20px;">✍️</span>
|
| 514 |
ข้อความที่ต้องการวิเคราะห์
|
| 515 |
</h3>
|
|
@@ -543,9 +547,9 @@ with gr.Blocks(
|
|
| 543 |
output_box = gr.HTML(
|
| 544 |
label="📊 ผลการวิเคราะห์",
|
| 545 |
value="""
|
| 546 |
-
<div style="padding: 60px 20px; text-align: center; color: #
|
| 547 |
<div style="font-size: 48px; margin-bottom: 16px;">🤖</div>
|
| 548 |
-
<h3 style="color: #
|
| 549 |
<p style="margin: 0; font-size: 14px;">ใส่ข้อความด้านบนแล้วกดปุ่ม "วิเคราะห์ข้อความ"</p>
|
| 550 |
</div>
|
| 551 |
"""
|
|
@@ -554,7 +558,7 @@ with gr.Blocks(
|
|
| 554 |
# Examples Section
|
| 555 |
gr.HTML("""
|
| 556 |
<div style="margin: 40px 0 20px 0;">
|
| 557 |
-
<h3 style="color:
|
| 558 |
✨ ตัวอย่างการใช้งาน
|
| 559 |
</h3>
|
| 560 |
</div>
|
|
@@ -575,30 +579,30 @@ with gr.Blocks(
|
|
| 575 |
|
| 576 |
# Legend Section
|
| 577 |
gr.HTML("""
|
| 578 |
-
<div style="margin: 40px 0 20px 0; background: rgba(
|
| 579 |
-
<h3 style="color:
|
| 580 |
🎯 คำอธิบายผลการวิเคราะห์
|
| 581 |
</h3>
|
| 582 |
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px;">
|
| 583 |
-
<div style="background: rgba(
|
| 584 |
<div style="font-size: 36px; margin-bottom: 12px;">😊</div>
|
| 585 |
-
<h4 style="color: #
|
| 586 |
-
<p style="color:
|
| 587 |
</div>
|
| 588 |
-
<div style="background: rgba(
|
| 589 |
<div style="font-size: 36px; margin-bottom: 12px;">😢</div>
|
| 590 |
-
<h4 style="color: #
|
| 591 |
-
<p style="color:
|
| 592 |
</div>
|
| 593 |
-
<div style="background: rgba(
|
| 594 |
<div style="font-size: 36px; margin-bottom: 12px;">😐</div>
|
| 595 |
-
<h4 style="color: #
|
| 596 |
-
<p style="color:
|
| 597 |
</div>
|
| 598 |
-
<div style="background: rgba(
|
| 599 |
<div style="font-size: 36px; margin-bottom: 12px;">🤔</div>
|
| 600 |
-
<h4 style="color: #
|
| 601 |
-
<p style="color:
|
| 602 |
</div>
|
| 603 |
</div>
|
| 604 |
</div>
|
|
@@ -607,7 +611,7 @@ with gr.Blocks(
|
|
| 607 |
# Footer
|
| 608 |
gr.HTML("""
|
| 609 |
<div style="text-align: center; padding: 30px 0 10px 0;">
|
| 610 |
-
<p style="color:
|
| 611 |
พัฒนาด้วย ❤️ โดยใช้ Transformers และ Gradio | รองรับโมเดล AI หลากหลาย
|
| 612 |
</p>
|
| 613 |
</div>
|
|
@@ -617,9 +621,9 @@ with gr.Blocks(
|
|
| 617 |
def analyze_wrapper(text, model_display_name):
|
| 618 |
if not text.strip():
|
| 619 |
return """
|
| 620 |
-
<div style="padding: 60px 20px; text-align: center; color: #
|
| 621 |
<div style="font-size: 48px; margin-bottom: 16px;">⚠️</div>
|
| 622 |
-
<h3 style="color: #
|
| 623 |
<p style="margin: 0; font-size: 14px;">ใส่ข้อความที่ต้องการวิเคราะห์ในช่องด้านบน</p>
|
| 624 |
</div>
|
| 625 |
"""
|
|
@@ -638,9 +642,9 @@ with gr.Blocks(
|
|
| 638 |
|
| 639 |
def clear_text():
|
| 640 |
return "", """
|
| 641 |
-
<div style="padding: 60px 20px; text-align: center; color: #
|
| 642 |
<div style="font-size: 48px; margin-bottom: 16px;">🤖</div>
|
| 643 |
-
<h3 style="color: #
|
| 644 |
<p style="margin: 0; font-size: 14px;">ใส่ข้อความด้านบนแล้วกดปุ่ม "วิเคราะห์ข้อความ"</p>
|
| 645 |
</div>
|
| 646 |
"""
|
|
@@ -649,9 +653,9 @@ with gr.Blocks(
|
|
| 649 |
if text.strip():
|
| 650 |
return analyze_wrapper(text, model_display_name)
|
| 651 |
return """
|
| 652 |
-
<div style="padding: 60px 20px; text-align: center; color: #
|
| 653 |
<div style="font-size: 48px; margin-bottom: 16px;">🤖</div>
|
| 654 |
-
<h3 style="color: #
|
| 655 |
<p style="margin: 0; font-size: 14px;">ใส่ข้อความด้านบนแล้วกดปุ่ม "วิเคราะห์ข้อความ"</p>
|
| 656 |
</div>
|
| 657 |
"""
|
|
@@ -690,7 +694,7 @@ if __name__ == "__main__":
|
|
| 690 |
).launch(
|
| 691 |
server_name="0.0.0.0",
|
| 692 |
server_port=7860,
|
| 693 |
-
share=True,
|
| 694 |
show_error=True,
|
| 695 |
show_api=False,
|
| 696 |
quiet=False,
|
|
|
|
| 36 |
logger.error(f"Error loading model {model_name}: {e}")
|
| 37 |
raise gr.Error(f"ไม่สามารถโหลดโมเดล {model_name} ได้: {str(e)}")
|
| 38 |
|
| 39 |
+
# Enhanced label mapping with modern styling for dark blue theme
|
| 40 |
LABEL_MAPPINGS = {
|
| 41 |
+
"LABEL_0": {"code": 0, "name": "question", "emoji": "🤔", "color": "#60a5fa", "bg": "rgba(96, 165, 250, 0.2)", "description": "คำถาม"},
|
| 42 |
+
"LABEL_1": {"code": 1, "name": "negative", "emoji": "😢", "color": "#f87171", "bg": "rgba(248, 113, 113, 0.2)", "description": "เชิงลบ"},
|
| 43 |
+
"LABEL_2": {"code": 2, "name": "neutral", "emoji": "😐", "color": "#facc15", "bg": "rgba(250, 204, 21, 0.2)", "description": "เป็นกลาง"},
|
| 44 |
+
"LABEL_3": {"code": 3, "name": "positive", "emoji": "😊", "color": "#34d399", "bg": "rgba(52, 211, 153, 0.2)", "description": "เชิงบวก"},
|
| 45 |
|
| 46 |
+
"POSITIVE": {"code": 3, "name": "positive", "emoji": "😊", "color": "#34d399", "bg": "rgba(52, 211, 153, 0.2)", "description": "เชิงบวก"},
|
| 47 |
+
"NEGATIVE": {"code": 1, "name": "negative", "emoji": "😢", "color": "#f87171", "bg": "rgba(248, 113, 113, 0.2)", "description": "เชิงลบ"},
|
| 48 |
+
"NEUTRAL": {"code": 2, "name": "neutral", "emoji": "😐", "color": "#facc15", "bg": "rgba(250, 204, 21, 0.2)", "description": "เป็นกลาง"},
|
| 49 |
|
| 50 |
+
"0": {"code": 0, "name": "negative", "emoji": "😢", "color": "#f87171", "bg": "rgba(248, 113, 113, 0.2)", "description": "เชิงลบ"},
|
| 51 |
+
"1": {"code": 1, "name": "positive", "emoji": "😊", "color": "#34d399", "bg": "rgba(52, 211, 153, 0.2)", "description": "เชิงบวก"},
|
| 52 |
}
|
| 53 |
|
| 54 |
def get_label_info(label: str) -> Dict:
|
|
|
|
| 57 |
"code": -1,
|
| 58 |
"name": label.lower(),
|
| 59 |
"emoji": "🔍",
|
| 60 |
+
"color": "#64748b",
|
| 61 |
+
"bg": "rgba(100, 116, 139, 0.2)",
|
| 62 |
"description": "ไม่ทราบ"
|
| 63 |
})
|
| 64 |
|
|
|
|
| 73 |
percentage = int(score * 100)
|
| 74 |
return f"""
|
| 75 |
<div style="display: flex; align-items: center; gap: 10px; margin: 8px 0;">
|
| 76 |
+
<div style="flex: 1; height: 8px; background: #334155; border-radius: 4px; overflow: hidden;">
|
| 77 |
+
<div style="width: {percentage}%; height: 100%; background: linear-gradient(90deg, #60a5fa, #3b82f6); transition: all 0.3s ease;"></div>
|
| 78 |
</div>
|
| 79 |
+
<span style="font-weight: 600; color: #cbd5e1; min-width: 50px;">{percentage}%</span>
|
| 80 |
</div>
|
| 81 |
"""
|
| 82 |
|
|
|
|
| 84 |
"""Enhanced text analysis with modern HTML formatting"""
|
| 85 |
if not text or not text.strip():
|
| 86 |
return """
|
| 87 |
+
<div style="padding: 20px; background: rgba(248, 113, 113, 0.2); border-radius: 12px; border-left: 4px solid #f87171;">
|
| 88 |
+
<div style="color: #f87171; font-weight: 600; display: flex; align-items: center; gap: 8px;">
|
| 89 |
<span style="font-size: 20px;">⚠️</span>
|
| 90 |
กรุณาใส่ข้อความที่ต้องการวิเคราะห์
|
| 91 |
</div>
|
|
|
|
| 96 |
|
| 97 |
if not sentences:
|
| 98 |
return """
|
| 99 |
+
<div style="padding: 20px; background: rgba(248, 113, 113, 0.2); border-radius: 12px; border-left: 4px solid #f87171;">
|
| 100 |
+
<div style="color: #f87171; font-weight: 600; display: flex; align-items: center; gap: 8px;">
|
| 101 |
<span style="font-size: 20px;">⚠️</span>
|
| 102 |
ไม่พบประโยคที่สามารถวิเคราะห์ได้ กรุณาใส่ข้อความที่ยาวกว่านี้
|
| 103 |
</div>
|
|
|
|
| 108 |
nlp = get_nlp(model_name)
|
| 109 |
except Exception as e:
|
| 110 |
return f"""
|
| 111 |
+
<div style="padding: 20px; background: rgba(248, 113, 113, 0.2); border-radius: 12px; border-left: 4px solid #f87171;">
|
| 112 |
+
<div style="color: #f87171; font-weight: 600; display: flex; align-items: center; gap: 8px;">
|
| 113 |
<span style="font-size: 20px;">❌</span>
|
| 114 |
เกิดข้อผิดพลาดในการโหลดโมเดล: {str(e)}
|
| 115 |
</div>
|
|
|
|
| 118 |
|
| 119 |
# Header
|
| 120 |
html_parts = ["""
|
| 121 |
+
<div style="background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%); color: #f8fafc; padding: 24px; border-radius: 16px 16px 0 0; margin-bottom: 0;">
|
| 122 |
<h2 style="margin: 0; font-size: 24px; font-weight: 700; display: flex; align-items: center; gap: 12px;">
|
| 123 |
<span style="font-size: 28px;">🧠</span>
|
| 124 |
ผลการวิเคราะห์ความรู้สึก
|
|
|
|
| 166 |
|
| 167 |
# Results container
|
| 168 |
html_parts.append("""
|
| 169 |
+
<div style="background: #0f172a; padding: 0; border-radius: 0 0 16px 16px; box-shadow: 0 4px 20px rgba(0,0,0,0.3); overflow: hidden;">
|
| 170 |
""")
|
| 171 |
|
| 172 |
# Individual sentence results
|
| 173 |
for result in sentence_results:
|
| 174 |
if 'error' in result:
|
| 175 |
html_parts.append(f"""
|
| 176 |
+
<div style="padding: 20px; border-bottom: 1px solid #1e293b;">
|
| 177 |
+
<div style="color: #f87171; font-weight: 600; display: flex; align-items: center; gap: 8px;">
|
| 178 |
<span style="font-size: 18px;">❌</span>
|
| 179 |
เกิดข้อผิดพลาดในการวิเคราะห์ประโยคที่ {result['index']}
|
| 180 |
</div>
|
| 181 |
+
<p style="color: #94a3b8; margin: 8px 0 0 0; font-size: 14px;">{result['error']}</p>
|
| 182 |
</div>
|
| 183 |
""")
|
| 184 |
else:
|
|
|
|
| 186 |
confidence_bar = create_confidence_bar(result['score'])
|
| 187 |
|
| 188 |
html_parts.append(f"""
|
| 189 |
+
<div style="padding: 20px; border-bottom: 1px solid #1e293b; transition: all 0.2s ease;" onmouseover="this.style.background='#1e293b'" onmouseout="this.style.background='#0f172a'">
|
| 190 |
<div style="display: flex; align-items: flex-start; gap: 16px;">
|
| 191 |
<div style="background: {label_info['bg']}; padding: 12px; border-radius: 50%; min-width: 48px; height: 48px; display: flex; align-items: center; justify-content: center;">
|
| 192 |
<span style="font-size: 20px;">{label_info['emoji']}</span>
|
| 193 |
</div>
|
| 194 |
<div style="flex: 1;">
|
| 195 |
<div style="display: flex; align-items: center; gap: 8px; margin-bottom: 8px;">
|
| 196 |
+
<span style="background: {label_info['color']}; color: #f8fafc; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; text-transform: uppercase;">
|
| 197 |
{label_info['description']}
|
| 198 |
</span>
|
| 199 |
+
<span style="color: #94a3b8; font-size: 14px;">ประโยคที่ {result['index']}</span>
|
| 200 |
</div>
|
| 201 |
+
<p style="color: #f8fafc; margin: 0 0 12px 0; font-size: 16px; line-height: 1.5;">
|
| 202 |
"{result['sentence'][:150]}{'...' if len(result['sentence']) > 150 else ''}"
|
| 203 |
</p>
|
| 204 |
+
<div style="color: #94a3b8; font-size: 14px; margin-bottom: 8px;">ความมั่นใจ:</div>
|
| 205 |
{confidence_bar}
|
| 206 |
</div>
|
| 207 |
</div>
|
|
|
|
| 214 |
|
| 215 |
# Create chart data for summary
|
| 216 |
chart_items = []
|
| 217 |
+
colors = {"positive": "#34d399", "negative": "#f87171", "neutral": "#facc15", "question": "#60a5fa", "other": "#64748b"}
|
| 218 |
emojis = {"positive": "😊", "negative": "😢", "neutral": "😐", "question": "🤔", "other": "🔍"}
|
| 219 |
|
| 220 |
for sentiment, count in sentiment_counts.items():
|
| 221 |
if count > 0:
|
| 222 |
percentage = (count / total_sentences) * 100
|
| 223 |
chart_items.append(f"""
|
| 224 |
+
<div style="display: flex; align-items: center; gap: 12px; padding: 12px; background: rgba(59, 130, 246, 0.1); border-radius: 8px;">
|
| 225 |
<span style="font-size: 24px;">{emojis.get(sentiment, '🔍')}</span>
|
| 226 |
<div style="flex: 1;">
|
| 227 |
+
<div style="font-weight: 600; color: #f8fafc; text-transform: capitalize;">{sentiment}</div>
|
| 228 |
+
<div style="color: #94a3b8; font-size: 14px;">{count} ประโยค ({percentage:.1f}%)</div>
|
| 229 |
</div>
|
| 230 |
+
<div style="width: 60px; height: 6px; background: #334155; border-radius: 3px; overflow: hidden;">
|
| 231 |
+
<div style="width: {percentage}%; height: 100%; background: {colors.get(sentiment, '#64748b')}; transition: all 0.3s ease;"></div>
|
| 232 |
</div>
|
| 233 |
</div>
|
| 234 |
""")
|
| 235 |
|
| 236 |
html_parts.append(f"""
|
| 237 |
+
<div style="padding: 24px; background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);">
|
| 238 |
+
<h3 style="color: #f8fafc; margin: 0 0 20px 0; font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 8px;">
|
| 239 |
<span style="font-size: 24px;">📊</span>
|
| 240 |
สรุปผลการวิเคราะห์
|
| 241 |
</h3>
|
| 242 |
|
| 243 |
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px;">
|
| 244 |
+
<div style="background: #1e293b; padding: 20px; border-radius: 12px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.3);">
|
| 245 |
+
<div style="font-size: 32px; font-weight: 700; color: #60a5fa; margin-bottom: 4px;">{total_sentences}</div>
|
| 246 |
+
<div style="color: #94a3b8; font-size: 14px;">ประโยคทั้งหมด</div>
|
| 247 |
</div>
|
| 248 |
+
<div style="background: #1e293b; padding: 20px; border-radius: 12px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.3);">
|
| 249 |
+
<div style="font-size: 32px; font-weight: 700; color: #34d399; margin-bottom: 4px;">{avg_confidence*100:.0f}%</div>
|
| 250 |
+
<div style="color: #94a3b8; font-size: 14px;">ความมั่นใจเฉลี่ย</div>
|
| 251 |
</div>
|
| 252 |
</div>
|
| 253 |
|
|
|
|
| 261 |
|
| 262 |
return "".join(html_parts)
|
| 263 |
|
| 264 |
+
# Modern CSS with dark blue theme
|
| 265 |
CUSTOM_CSS = """
|
| 266 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');
|
| 267 |
|
|
|
|
| 272 |
.gradio-container {
|
| 273 |
max-width: 1200px !important;
|
| 274 |
margin: 0 auto !important;
|
| 275 |
+
background: linear-gradient(135deg, #1e3a8a 0%, #0f172a 100%) !important;
|
| 276 |
min-height: 100vh;
|
| 277 |
padding: 20px;
|
| 278 |
}
|
| 279 |
|
| 280 |
.main-content {
|
| 281 |
+
background: rgba(15, 23, 42, 0.95) !important;
|
| 282 |
backdrop-filter: blur(20px) !important;
|
| 283 |
border-radius: 24px !important;
|
| 284 |
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5) !important;
|
| 285 |
+
border: 1px solid rgba(59, 130, 246, 0.2) !important;
|
| 286 |
overflow: hidden;
|
| 287 |
}
|
| 288 |
|
| 289 |
.glass-card {
|
| 290 |
+
background: rgba(30, 58, 138, 0.9) !important;
|
| 291 |
+
backdrop-filter: blur(12px) !important;
|
| 292 |
border-radius: 16px !important;
|
| 293 |
+
border: 1px solid rgba(59, 130, 246, 0.3) !important;
|
| 294 |
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3) !important;
|
| 295 |
transition: all 0.3s ease !important;
|
| 296 |
}
|
| 297 |
|
| 298 |
.glass-card:hover {
|
| 299 |
transform: translateY(-2px) !important;
|
| 300 |
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4) !important;
|
| 301 |
}
|
| 302 |
|
| 303 |
.gr-button {
|
| 304 |
+
background: linear-gradient(135deg, #3b82f6 0%, #1e3a8a 100%) !important;
|
| 305 |
border: none !important;
|
| 306 |
border-radius: 12px !important;
|
| 307 |
padding: 12px 24px !important;
|
|
|
|
| 309 |
text-transform: uppercase !important;
|
| 310 |
letter-spacing: 0.5px !important;
|
| 311 |
transition: all 0.3s ease !important;
|
| 312 |
+
box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4) !important;
|
| 313 |
+
color: #f8fafc !important;
|
| 314 |
}
|
| 315 |
|
| 316 |
.gr-button:hover {
|
| 317 |
transform: translateY(-2px) !important;
|
| 318 |
+
box-shadow: 0 6px 20px rgba(59, 130, 246, 0.6) !important;
|
| 319 |
}
|
| 320 |
|
| 321 |
.gr-button.secondary {
|
| 322 |
+
background: linear-gradient(135deg, #60a5fa 0%, #93c5fd 100%) !important;
|
| 323 |
+
box-shadow: 0 4px 15px rgba(96, 165, 250, 0.4) !important;
|
| 324 |
}
|
| 325 |
|
| 326 |
.gr-button.secondary:hover {
|
| 327 |
+
box-shadow: 0 6px 20px rgba(96, 165, 250, 0.6) !important;
|
| 328 |
}
|
| 329 |
|
| 330 |
.gr-textbox textarea, .gr-textbox input {
|
| 331 |
border-radius: 12px !important;
|
| 332 |
+
border: 2px solid rgba(59, 130, 246, 0.3) !important;
|
| 333 |
font-size: 16px !important;
|
| 334 |
padding: 16px !important;
|
| 335 |
transition: all 0.3s ease !important;
|
| 336 |
+
background: rgba(30, 41, 59, 0.9) !important;
|
| 337 |
+
color: #f8fafc !important;
|
| 338 |
}
|
| 339 |
|
| 340 |
.gr-textbox textarea:focus, .gr-textbox input:focus {
|
| 341 |
+
border-color: #3b82f6 !important;
|
| 342 |
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2) !important;
|
| 343 |
transform: scale(1.01) !important;
|
| 344 |
}
|
| 345 |
|
| 346 |
.gr-dropdown > div {
|
| 347 |
border-radius: 12px !important;
|
| 348 |
+
border: 2px solid rgba(59, 130, 246, 0.3) !important;
|
| 349 |
+
background: rgba(30, 41, 59, 0.9) !important;
|
| 350 |
+
color: #f8fafc !important;
|
| 351 |
}
|
| 352 |
|
| 353 |
.gr-dropdown > div:focus-within {
|
| 354 |
+
border-color: #3b82f6 !important;
|
| 355 |
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2) !important;
|
| 356 |
}
|
| 357 |
|
| 358 |
.gr-panel {
|
|
|
|
| 377 |
}
|
| 378 |
|
| 379 |
::-webkit-scrollbar-track {
|
| 380 |
+
background: rgba(15, 23, 42, 0.3);
|
| 381 |
border-radius: 4px;
|
| 382 |
}
|
| 383 |
|
| 384 |
::-webkit-scrollbar-thumb {
|
| 385 |
+
background: rgba(59, 130, 246, 0.6);
|
| 386 |
border-radius: 4px;
|
| 387 |
}
|
| 388 |
|
| 389 |
::-webkit-scrollbar-thumb:hover {
|
| 390 |
+
background: rgba(59, 130, 246, 0.8);
|
| 391 |
}
|
| 392 |
|
| 393 |
/* Animation for content */
|
|
|
|
| 413 |
}
|
| 414 |
|
| 415 |
.gr-examples .gr-button {
|
| 416 |
+
background: rgba(59, 130, 246, 0.2) !important;
|
| 417 |
+
border: 1px solid rgba(59, 130, 246, 0.4) !important;
|
| 418 |
margin: 4px !important;
|
| 419 |
font-size: 14px !important;
|
| 420 |
text-transform: none !important;
|
| 421 |
letter-spacing: normal !important;
|
| 422 |
+
color: #f8fafc !important;
|
| 423 |
}
|
| 424 |
|
| 425 |
.gr-examples .gr-button:hover {
|
| 426 |
+
background: rgba(59, 130, 246, 0.4) !important;
|
| 427 |
transform: scale(1.02) !important;
|
| 428 |
}
|
| 429 |
"""
|
|
|
|
| 432 |
with gr.Blocks(
|
| 433 |
theme=gr.themes.Glass(
|
| 434 |
primary_hue="blue",
|
| 435 |
+
secondary_hue="indigo",
|
| 436 |
neutral_hue="slate",
|
| 437 |
font=["Inter", "Noto Sans Thai", "sans-serif"]
|
| 438 |
),
|
|
|
|
| 440 |
title="🧠 AI Thai Sentiment Analyzer - วิเคราะห์ความรู้สึกภาษาไทย"
|
| 441 |
) as demo:
|
| 442 |
|
| 443 |
+
# Header with dark blue design
|
| 444 |
gr.HTML("""
|
| 445 |
<div style="text-align: center; padding: 40px 0 30px 0;">
|
| 446 |
+
<div style="display: inline-block; background: rgba(30, 58, 138, 0.9); backdrop-filter: blur(10px); padding: 20px 40px; border-radius: 20px; border: 1px solid rgba(59, 130, 246, 0.3); margin-bottom: 20px;">
|
| 447 |
+
<h1 style="font-size: 3.5em; margin: 0; color: #f8fafc; font-weight: 800; text-shadow: 0 4px 8px rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; gap: 20px;">
|
| 448 |
<span style="font-size: 1.2em;">🧠</span>
|
| 449 |
Thai Sentiment AI
|
| 450 |
</h1>
|
| 451 |
+
<p style="font-size: 1.4em; color: #cbd5e1; margin: 10px 0 0 0; font-weight: 300; text-shadow: 0 2px 4px rgba(0,0,0,0.3);">
|
| 452 |
ระบบวิเคราะห์ความรู้สึกภาษาไทยด้วย AI ที่ทันสมัยและแม่นยำ
|
| 453 |
</p>
|
| 454 |
</div>
|
|
|
|
| 461 |
# Model Selection Card
|
| 462 |
with gr.Group():
|
| 463 |
gr.HTML("""
|
| 464 |
+
<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;">
|
| 465 |
<h3 style="margin: 0; font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px;">
|
| 466 |
<span style="font-size: 20px;">🤖</span>
|
| 467 |
เลือกโมเดล AI
|
|
|
|
| 481 |
# Tips Card
|
| 482 |
with gr.Group():
|
| 483 |
gr.HTML("""
|
| 484 |
+
<div style="background: linear-gradient(135deg, #1e40af 0%, #1e293b 100%); padding: 20px; border-radius: 16px;">
|
| 485 |
+
<h4 style="color: #f8fafc; margin: 0 0 16px 0; font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px;">
|
| 486 |
<span style="font-size: 18px;">💡</span>
|
| 487 |
เคล็ดลับการใช้งาน
|
| 488 |
</h4>
|
| 489 |
+
<div style="color: #cbd5e1; font-size: 14px; line-height: 1.6;">
|
| 490 |
<div style="margin-bottom: 12px; display: flex; align-items: flex-start; gap: 8px;">
|
| 491 |
+
<span style="color: #60a5fa; font-weight: 600;">•</span>
|
| 492 |
<span>พิมพ์ข้อความภาษาไทยที่ต้องการวิเคราะห์</span>
|
| 493 |
</div>
|
| 494 |
<div style="margin-bottom: 12px; display: flex; align-items: flex-start; gap: 8px;">
|
| 495 |
+
<span style="color: #60a5fa; font-weight: 600;">•</span>
|
| 496 |
<span>แยกประโยคด้วยจุด (.) หรือขึ้นบรรทัดใหม่</span>
|
| 497 |
</div>
|
| 498 |
<div style="margin-bottom: 12px; display: flex; align-items: flex-start; gap: 8px;">
|
| 499 |
+
<span style="color: #60a5fa; font-weight: 600;">•</span>
|
| 500 |
<span>สามารถวิเคราะห์หลายประโยคพร้อมกันได้</span>
|
| 501 |
</div>
|
| 502 |
<div style="display: flex; align-items: flex-start; gap: 8px;">
|
| 503 |
+
<span style="color: #60a5fa; font-weight: 600;">•</span>
|
| 504 |
<span>ผลลัพธ์จะแสดงความมั่นใจและสรุปภาพรวม</span>
|
| 505 |
</div>
|
| 506 |
</div>
|
|
|
|
| 512 |
# Input Section
|
| 513 |
with gr.Group():
|
| 514 |
gr.HTML("""
|
| 515 |
+
<div style="background: linear-gradient(135deg, #1e40af 0%, #1e293b 100%); padding: 20px; border-radius: 16px 16px 0 0; margin: -20px -20px 20px -20px;">
|
| 516 |
+
<h3 style="color: #f8fafc; margin: 0; font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px;">
|
| 517 |
<span style="font-size: 20px;">✍️</span>
|
| 518 |
ข้อความที่ต้องการวิเคราะห์
|
| 519 |
</h3>
|
|
|
|
| 547 |
output_box = gr.HTML(
|
| 548 |
label="📊 ผลการวิเคราะห์",
|
| 549 |
value="""
|
| 550 |
+
<div style="padding: 60px 20px; text-align: center; color: #94a3b8; background: rgba(30, 41, 59, 0.9); border-radius: 16px; border: 2px dashed #334155;">
|
| 551 |
<div style="font-size: 48px; margin-bottom: 16px;">🤖</div>
|
| 552 |
+
<h3 style="color: #f8fafc; margin: 0 0 8px 0;">พร้อมวิเคราะห์ความรู้สึก</h3>
|
| 553 |
<p style="margin: 0; font-size: 14px;">ใส่ข้อความด้านบนแล้วกดปุ่ม "วิเคราะห์ข้อความ"</p>
|
| 554 |
</div>
|
| 555 |
"""
|
|
|
|
| 558 |
# Examples Section
|
| 559 |
gr.HTML("""
|
| 560 |
<div style="margin: 40px 0 20px 0;">
|
| 561 |
+
<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);">
|
| 562 |
✨ ตัวอย่างการใช้งาน
|
| 563 |
</h3>
|
| 564 |
</div>
|
|
|
|
| 579 |
|
| 580 |
# Legend Section
|
| 581 |
gr.HTML("""
|
| 582 |
+
<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);">
|
| 583 |
+
<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);">
|
| 584 |
🎯 คำอธิบายผลการวิเคราะห์
|
| 585 |
</h3>
|
| 586 |
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px;">
|
| 587 |
+
<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'">
|
| 588 |
<div style="font-size: 36px; margin-bottom: 12px;">😊</div>
|
| 589 |
+
<h4 style="color: #34d399; margin: 0 0 8px 0; font-size: 16px; font-weight: 700;">POSITIVE</h4>
|
| 590 |
+
<p style="color: #cbd5e1; margin: 0; font-size: 13px; line-height: 1.4;">ความรู้สึกเชิงบวก<br>ดี, สุข, ชอบ, ยินดี</p>
|
| 591 |
</div>
|
| 592 |
+
<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'">
|
| 593 |
<div style="font-size: 36px; margin-bottom: 12px;">😢</div>
|
| 594 |
+
<h4 style="color: #f87171; margin: 0 0 8px 0; font-size: 16px; font-weight: 700;">NEGATIVE</h4>
|
| 595 |
+
<p style="color: #cbd5e1; margin: 0; font-size: 13px; line-height: 1.4;">ความรู้สึกเชิงลบ<br>เศร้า, โกรธ, ไม่ชอบ</p>
|
| 596 |
</div>
|
| 597 |
+
<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'">
|
| 598 |
<div style="font-size: 36px; margin-bottom: 12px;">😐</div>
|
| 599 |
+
<h4 style="color: #facc15; margin: 0 0 8px 0; font-size: 16px; font-weight: 700;">NEUTRAL</h4>
|
| 600 |
+
<p style="color: #cbd5e1; margin: 0; font-size: 13px; line-height: 1.4;">ความรู้สึกเป็นกลาง<br>ปกติ, พอใช้ได้, ธรรมดา</p>
|
| 601 |
</div>
|
| 602 |
+
<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'">
|
| 603 |
<div style="font-size: 36px; margin-bottom: 12px;">🤔</div>
|
| 604 |
+
<h4 style="color: #60a5fa; margin: 0 0 8px 0; font-size: 16px; font-weight: 700;">QUESTION</h4>
|
| 605 |
+
<p style="color: #cbd5e1; margin: 0; font-size: 13px; line-height: 1.4;">ประโยคคำถาม<br>อะไร, ไหน, เมื่อไหร่</p>
|
| 606 |
</div>
|
| 607 |
</div>
|
| 608 |
</div>
|
|
|
|
| 611 |
# Footer
|
| 612 |
gr.HTML("""
|
| 613 |
<div style="text-align: center; padding: 30px 0 10px 0;">
|
| 614 |
+
<p style="color: #cbd5e1; font-size: 14px; margin: 0; text-shadow: 0 1px 2px rgba(0,0,0,0.4);">
|
| 615 |
พัฒนาด้วย ❤️ โดยใช้ Transformers และ Gradio | รองรับโมเดล AI หลากหลาย
|
| 616 |
</p>
|
| 617 |
</div>
|
|
|
|
| 621 |
def analyze_wrapper(text, model_display_name):
|
| 622 |
if not text.strip():
|
| 623 |
return """
|
| 624 |
+
<div style="padding: 60px 20px; text-align: center; color: #94a3b8; background: rgba(30, 41, 59, 0.9); border-radius: 16px; border: 2px dashed #334155;">
|
| 625 |
<div style="font-size: 48px; margin-bottom: 16px;">⚠️</div>
|
| 626 |
+
<h3 style="color: #f87171; margin: 0 0 8px 0;">กรุณาใส่ข้อความ</h3>
|
| 627 |
<p style="margin: 0; font-size: 14px;">ใส่ข้อความที่ต้องการวิเคราะห์ในช่องด้านบน</p>
|
| 628 |
</div>
|
| 629 |
"""
|
|
|
|
| 642 |
|
| 643 |
def clear_text():
|
| 644 |
return "", """
|
| 645 |
+
<div style="padding: 60px 20px; text-align: center; color: #94a3b8; background: rgba(30, 41, 59, 0.9); border-radius: 16px; border: 2px dashed #334155;">
|
| 646 |
<div style="font-size: 48px; margin-bottom: 16px;">🤖</div>
|
| 647 |
+
<h3 style="color: #f8fafc; margin: 0 0 8px 0;">พร้อมวิเคราะห์ความรู้สึก</h3>
|
| 648 |
<p style="margin: 0; font-size: 14px;">ใส่ข้อความด้านบนแล้วกดปุ่ม "วิเคราะห์ข้อความ"</p>
|
| 649 |
</div>
|
| 650 |
"""
|
|
|
|
| 653 |
if text.strip():
|
| 654 |
return analyze_wrapper(text, model_display_name)
|
| 655 |
return """
|
| 656 |
+
<div style="padding: 60px 20px; text-align: center; color: #94a3b8; background: rgba(30, 41, 59, 0.9); border-radius: 16px; border: 2px dashed #334155;">
|
| 657 |
<div style="font-size: 48px; margin-bottom: 16px;">🤖</div>
|
| 658 |
+
<h3 style="color: #f8fafc; margin: 0 0 8px 0;">พร้อมวิเคราะห์ความรู้สึก</h3>
|
| 659 |
<p style="margin: 0; font-size: 14px;">ใส่ข้อความด้านบนแล้วกดปุ่ม "วิเคราะห์ข้อความ"</p>
|
| 660 |
</div>
|
| 661 |
"""
|
|
|
|
| 694 |
).launch(
|
| 695 |
server_name="0.0.0.0",
|
| 696 |
server_port=7860,
|
| 697 |
+
share=True,
|
| 698 |
show_error=True,
|
| 699 |
show_api=False,
|
| 700 |
quiet=False,
|