AugustinHuang commited on
Commit
157f214
·
verified ·
1 Parent(s): be06db1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -22
app.py CHANGED
@@ -97,7 +97,7 @@ Tổng các số phải bằng 100.
97
  Văn bản cần phân tích: {text}"""
98
 
99
  res = self._call_groq_llm(prompt, api_key)
100
- if not res or res.startswith("️"):
101
  return {k: 0 for k in self.sentiment_labels}
102
 
103
  try:
@@ -127,28 +127,19 @@ Văn bản cần phân tích: {text}"""
127
  marker_colors=colors,
128
  textinfo='percent+label',
129
  insidetextorientation='radial',
130
- textfont=dict(size=11, color="#333") # Chữ bên trong rõ hơn chút
131
  )])
132
 
133
- # --- PHẦN SỬA LI GIAO DIỆN Ở ĐÂY ---
134
  fig.update_layout(
135
- # Bỏ title ở đây nếu muốn dùng label của Gradio, HOẶC giữ title này và bỏ label Gradio
136
- # Ở đây mình giữ title của Plotly vì nó đẹp và căn chỉnh dễ hơn
137
- title={
138
- 'text': "📊 Daily Activity Distribution",
139
- 'y': 0.95,
140
- 'x': 0.5,
141
- 'xanchor': 'center',
142
- 'yanchor': 'top',
143
- 'font': dict(size=18, color="#444")
144
- },
145
- height=480, # Tăng chiều cao để legend không bị đè
146
- margin=dict(t=60, b=80, l=20, r=20), # Tăng bottom margin (b=80) để chứa legend
147
  showlegend=True,
148
  legend=dict(
149
  orientation="h",
150
  yanchor="bottom",
151
- y=-0.15, # Đẩy legend xuống dưới hẳn, tránh chồng lên bánh
152
  xanchor="center",
153
  x=0.5,
154
  font=dict(size=10),
@@ -171,7 +162,7 @@ Văn bản cần phân tích: {text}"""
171
  hoverinfo='skip'
172
  ))
173
  fig.update_layout(
174
- title=" Phân Tích Cảm Xúc (%)",
175
  xaxis=dict(range=[0, 105], title="", showgrid=False),
176
  yaxis=dict(title="", autorange="reversed"),
177
  margin=dict(l=100, r=30, t=50, b=50),
@@ -205,7 +196,7 @@ Văn bản cần phân tích: {text}"""
205
  for task, cat in results:
206
  bg = color_map.get(cat, "#eee")
207
  html += f'<li style="margin-bottom:8px;padding:10px;background:#fff;border-left:5px solid {bg};box-shadow:0 1px 3px rgba(0,0,0,0.05);"><span style="font-weight:bold;color:#555;font-size:0.85em;text-transform:uppercase;">[{cat}]</span> <span style="color:#333;margin-left:8px;">{task}</span></li>'
208
- html += "</ul><h3 style='border-bottom:2px solid #eee;padding-bottom:10px;margin-top:20px;'> Summary</h3><ul>"
209
 
210
  total = sum(cat_counter.values())
211
  for cat, count in sorted(cat_counter.items(), key=lambda x: x[1], reverse=True):
@@ -218,7 +209,7 @@ Văn bản cần phân tích: {text}"""
218
  ai_agent = TaskDashboardAI_Vietnamese()
219
 
220
  with gr.Blocks(title="Vietnamese Task Dashboard AI", theme=gr.themes.Soft()) as demo:
221
- gr.Markdown("# 🇻🇳 Smart Task Dashboard AI\n`AI phân tích Intent & Cảm xúc hàng ngày, hỗ trợ Llama 3 (Groq)`")
222
 
223
  with gr.Row():
224
  # CỘT TRÁI
@@ -240,8 +231,10 @@ Hệ thống nhận diện tốt nhất khi chứa các từ khóa sau:
240
  """)
241
 
242
  # CỘT GIỮA - BIỂU ĐỒ DONUT
243
- # Lưu ý: Mình bỏ label="..." ở đây để tránh bị đúp tiêu đề với Plotly
 
244
  with gr.Column(scale=1):
 
245
  chart_output = gr.Plot()
246
 
247
  # CỘT PHẢI
@@ -249,7 +242,7 @@ Hệ thống nhận diện tốt nhất khi chứa các từ khóa sau:
249
  sentiment_output = gr.Plot(label="🧠 Phân Tích Cảm Xúc (%)")
250
  api_key_input = gr.Textbox(label="🔑 Groq API Key", type="password", info="Key không được lưu trữ.")
251
  gr.Markdown("""
252
- ### Hướng dẫn lấy API & ️ Bảo mật
253
  1. Truy cập [console.groq.com/keys](https://console.groq.com/keys)
254
  2. Đăng nhập → Nhấn **Create API Key** → Copy.
255
  3. Dán vào ô trên và nhấn **Phân tích**.
@@ -258,7 +251,7 @@ Hệ thống nhận diện tốt nhất khi chứa các từ khóa sau:
258
 
259
  # DÒNG DƯỚI
260
  with gr.Row():
261
- summary_output = gr.HTML(label="📋 Detailed Classification")
262
 
263
  btn.click(fn=ai_agent.process, inputs=[input_text, api_key_input], outputs=[chart_output, sentiment_output, summary_output])
264
 
 
97
  Văn bản cần phân tích: {text}"""
98
 
99
  res = self._call_groq_llm(prompt, api_key)
100
+ if not res or res.startswith("⚠️"):
101
  return {k: 0 for k in self.sentiment_labels}
102
 
103
  try:
 
127
  marker_colors=colors,
128
  textinfo='percent+label',
129
  insidetextorientation='radial',
130
+ textfont=dict(size=11, color="#333")
131
  )])
132
 
133
+ # --- SỬA TRIỆT ĐỂ: BỎ TITLE CỦA PLOTLY, CHỈ GIỮ LEGEND GỌN GÀNG ---
134
  fig.update_layout(
135
+ # KHÔNG CÓ title ở đây nữa! Tiêu đề sẽ do Gradio Markdown đảm nhận
136
+ height=500, # Tăng chiều cao để legend thoải mái
137
+ margin=dict(t=20, b=100, l=20, r=20), # Bottom margin lớn (100) để chứa legend bên dưới
 
 
 
 
 
 
 
 
 
138
  showlegend=True,
139
  legend=dict(
140
  orientation="h",
141
  yanchor="bottom",
142
+ y=-0.18, # Đẩy legend xuống hẳn vùng bottom margin
143
  xanchor="center",
144
  x=0.5,
145
  font=dict(size=10),
 
162
  hoverinfo='skip'
163
  ))
164
  fig.update_layout(
165
+ title="🧠 Phân Tích Cảm Xúc (%)",
166
  xaxis=dict(range=[0, 105], title="", showgrid=False),
167
  yaxis=dict(title="", autorange="reversed"),
168
  margin=dict(l=100, r=30, t=50, b=50),
 
196
  for task, cat in results:
197
  bg = color_map.get(cat, "#eee")
198
  html += f'<li style="margin-bottom:8px;padding:10px;background:#fff;border-left:5px solid {bg};box-shadow:0 1px 3px rgba(0,0,0,0.05);"><span style="font-weight:bold;color:#555;font-size:0.85em;text-transform:uppercase;">[{cat}]</span> <span style="color:#333;margin-left:8px;">{task}</span></li>'
199
+ html += "</ul><h3 style='border-bottom:2px solid #eee;padding-bottom:10px;margin-top:20px;'>📈 Summary</h3><ul>"
200
 
201
  total = sum(cat_counter.values())
202
  for cat, count in sorted(cat_counter.items(), key=lambda x: x[1], reverse=True):
 
209
  ai_agent = TaskDashboardAI_Vietnamese()
210
 
211
  with gr.Blocks(title="Vietnamese Task Dashboard AI", theme=gr.themes.Soft()) as demo:
212
+ gr.Markdown("# 🇳 Smart Task Dashboard AI\n`AI phân tích Intent & Cảm xúc hàng ngày, hỗ trợ Llama 3 (Groq)`")
213
 
214
  with gr.Row():
215
  # CỘT TRÁI
 
231
  """)
232
 
233
  # CỘT GIỮA - BIỂU ĐỒ DONUT
234
+ # MẸO QUAN TRỌNG: Đặt tiêu đề bằng gr.Markdown NGAY TRÊN gr.Plot
235
+ # Và KHÔNG dùng label trong gr.Plot để tránh đúp chữ
236
  with gr.Column(scale=1):
237
+ gr.Markdown("### 📊 Daily Activity Distribution")
238
  chart_output = gr.Plot()
239
 
240
  # CỘT PHẢI
 
242
  sentiment_output = gr.Plot(label="🧠 Phân Tích Cảm Xúc (%)")
243
  api_key_input = gr.Textbox(label="🔑 Groq API Key", type="password", info="Key không được lưu trữ.")
244
  gr.Markdown("""
245
+ ### 📖 Hướng dẫn lấy API & ⚠️ Bảo mật
246
  1. Truy cập [console.groq.com/keys](https://console.groq.com/keys)
247
  2. Đăng nhập → Nhấn **Create API Key** → Copy.
248
  3. Dán vào ô trên và nhấn **Phân tích**.
 
251
 
252
  # DÒNG DƯỚI
253
  with gr.Row():
254
+ summary_output = gr.HTML(label=" Detailed Classification")
255
 
256
  btn.click(fn=ai_agent.process, inputs=[input_text, api_key_input], outputs=[chart_output, sentiment_output, summary_output])
257