refactor: update Gradio UI theme and custom CSS to light Google Gemini style
Browse files
app.py
CHANGED
|
@@ -141,87 +141,132 @@ def chat_response(
|
|
| 141 |
|
| 142 |
|
| 143 |
# ==============================================================================
|
| 144 |
-
# TÙY BIẾN GIAO DIỆN THEME GOOGLE GEMINI
|
| 145 |
# ==============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
CUSTOM_CSS = """
|
| 147 |
-
@import url('https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&family=Inter:wght@400;500;600&display=swap');
|
| 148 |
-
|
| 149 |
-
:root {
|
| 150 |
-
--bg-primary: #131314;
|
| 151 |
-
--bg-secondary: #1e1f20;
|
| 152 |
-
--bg-bubble-user: #282a2c;
|
| 153 |
-
--text-primary: #e3e3e3;
|
| 154 |
-
--text-muted: #9aa0a6;
|
| 155 |
-
--border-color: #3c4043;
|
| 156 |
-
}
|
| 157 |
|
|
|
|
| 158 |
body, .gradio-container {
|
| 159 |
-
background-color:
|
| 160 |
-
color:
|
| 161 |
font-family: 'Google Sans', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
|
|
|
|
|
|
|
| 162 |
}
|
| 163 |
|
| 164 |
-
/* Tiêu đề phong cách Gemini Sparkle */
|
| 165 |
-
|
| 166 |
-
text-align: center;
|
| 167 |
-
|
| 168 |
-
font-
|
| 169 |
-
|
| 170 |
-
background:
|
| 171 |
-
-webkit-
|
| 172 |
-
-
|
| 173 |
-
|
| 174 |
}
|
| 175 |
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
|
|
|
| 181 |
}
|
| 182 |
|
| 183 |
-
/*
|
| 184 |
-
|
| 185 |
-
background-color:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
}
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
|
|
|
|
|
|
| 191 |
border-radius: 20px 20px 4px 20px !important;
|
| 192 |
-
color: #f1f3f4 !important;
|
| 193 |
padding: 12px 18px !important;
|
| 194 |
font-size: 15px !important;
|
|
|
|
|
|
|
| 195 |
}
|
| 196 |
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
background-color: transparent !important;
|
|
|
|
| 199 |
border: none !important;
|
| 200 |
-
border-radius: 20px 20px 20px 4px !important;
|
| 201 |
-
color: var(--text-primary) !important;
|
| 202 |
-
padding: 12px 18px !important;
|
| 203 |
font-size: 15px !important;
|
| 204 |
-
line-height: 1.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
}
|
| 206 |
|
| 207 |
-
/*
|
| 208 |
input[type="text"], textarea {
|
| 209 |
-
background-color:
|
| 210 |
-
border:
|
| 211 |
-
border-radius:
|
| 212 |
-
color: #
|
|
|
|
|
|
|
|
|
|
| 213 |
}
|
| 214 |
|
| 215 |
input[type="text"]:focus, textarea:focus {
|
| 216 |
-
border-color: #
|
| 217 |
-
box-shadow: 0 0 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
}
|
| 219 |
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
border: 1px solid var(--border-color) !important;
|
| 224 |
-
border-radius: 12px !important;
|
| 225 |
}
|
| 226 |
|
| 227 |
footer {
|
|
@@ -229,100 +274,86 @@ footer {
|
|
| 229 |
}
|
| 230 |
"""
|
| 231 |
|
| 232 |
-
DEFAULT_SYSTEM_PROMPT = (
|
| 233 |
-
"Bạn là Gemma, một trợ lý trí tuệ nhân tạo thông minh, am hiểu và thân thiện. "
|
| 234 |
-
"Hãy trả lời súc tích, chính xác, định dạng câu trả lời bằng Markdown đẹp mắt."
|
| 235 |
-
)
|
| 236 |
-
|
| 237 |
-
custom_theme = gr.themes.Base(
|
| 238 |
-
primary_hue="blue",
|
| 239 |
-
neutral_hue="neutral",
|
| 240 |
-
)
|
| 241 |
-
|
| 242 |
# ==============================================================================
|
| 243 |
-
# KHỞI TẠO GIAO DIỆN
|
| 244 |
# ==============================================================================
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
gr.
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
|
|
|
|
|
|
| 259 |
),
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
),
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
),
|
| 274 |
-
|
| 275 |
-
minimum=128,
|
| 276 |
-
maximum=4096,
|
| 277 |
-
value=1536,
|
| 278 |
-
step=128,
|
| 279 |
-
label="Độ dài tối đa (Max New Tokens)",
|
| 280 |
-
info="Số lượng token tối đa mô hình tạo ra trong mỗi lượt trả lời.",
|
| 281 |
-
),
|
| 282 |
-
gr.Slider(
|
| 283 |
-
minimum=0.1,
|
| 284 |
-
maximum=1.0,
|
| 285 |
-
value=0.9,
|
| 286 |
-
step=0.05,
|
| 287 |
-
label="Top-P (Nucleus Sampling)",
|
| 288 |
-
),
|
| 289 |
-
],
|
| 290 |
-
additional_inputs_accordion=gr.Accordion(
|
| 291 |
-
label="⚙️ Cài đặt tham số mô hình & System Prompt",
|
| 292 |
-
open=False,
|
| 293 |
),
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
1536,
|
| 314 |
-
0.9,
|
| 315 |
-
],
|
| 316 |
-
[
|
| 317 |
-
"So sánh ưu điểm và nhược điểm giữa cấu trúc Dense Model và Mixture-of-Experts (MoE).",
|
| 318 |
-
DEFAULT_SYSTEM_PROMPT,
|
| 319 |
-
0.7,
|
| 320 |
-
1536,
|
| 321 |
-
0.9,
|
| 322 |
-
],
|
| 323 |
],
|
| 324 |
-
|
| 325 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
|
| 327 |
if __name__ == "__main__":
|
| 328 |
demo.queue().launch(theme=custom_theme, css=CUSTOM_CSS)
|
|
|
|
| 141 |
|
| 142 |
|
| 143 |
# ==============================================================================
|
| 144 |
+
# TÙY BIẾN GIAO DIỆN THEME GOOGLE GEMINI (SÁNG - TINH TẾ - DỄ ĐỌC)
|
| 145 |
# ==============================================================================
|
| 146 |
+
DEFAULT_SYSTEM_PROMPT = (
|
| 147 |
+
"Bạn là Gemma, một trợ lý trí tuệ nhân tạo thông minh, am hiểu và thân thiện. "
|
| 148 |
+
"Hãy trả lời súc tích, chính xác, định dạng câu trả lời bằng Markdown đẹp mắt."
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
# Khởi tạo theme chuẩn Google (màu xanh dương dịu mắt, tương phản cao)
|
| 152 |
+
custom_theme = gr.themes.Soft(
|
| 153 |
+
primary_hue="blue",
|
| 154 |
+
secondary_hue="indigo",
|
| 155 |
+
neutral_hue="slate",
|
| 156 |
+
font=[gr.themes.GoogleFont("Inter"), "sans-serif"],
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
CUSTOM_CSS = """
|
| 160 |
+
@import url('https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;600;700&family=Inter:wght@400;500;600&display=swap');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
+
/* Toàn bộ nền trang sáng sủa, sạch sẽ phong cách Google */
|
| 163 |
body, .gradio-container {
|
| 164 |
+
background-color: #f8fafd !important;
|
| 165 |
+
color: #1f2937 !important;
|
| 166 |
font-family: 'Google Sans', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
|
| 167 |
+
max-width: 960px !important;
|
| 168 |
+
margin: 0 auto !important;
|
| 169 |
}
|
| 170 |
|
| 171 |
+
/* Tiêu đề phong cách Gemini Sparkle Gradient */
|
| 172 |
+
h1 {
|
| 173 |
+
text-align: center !important;
|
| 174 |
+
font-size: 2.2rem !important;
|
| 175 |
+
font-weight: 700 !important;
|
| 176 |
+
background: linear-gradient(135deg, #1a73e8 0%, #8b5cf6 50%, #ec4899 100%) !important;
|
| 177 |
+
-webkit-background-clip: text !important;
|
| 178 |
+
-webkit-text-fill-color: transparent !important;
|
| 179 |
+
letter-spacing: -0.5px !important;
|
| 180 |
+
margin-bottom: 0.25rem !important;
|
| 181 |
}
|
| 182 |
|
| 183 |
+
/* Mô tả phụ bên dưới tiêu đề */
|
| 184 |
+
.description, p.description {
|
| 185 |
+
text-align: center !important;
|
| 186 |
+
color: #5f6368 !important;
|
| 187 |
+
font-size: 0.95rem !important;
|
| 188 |
+
margin-bottom: 1.25rem !important;
|
| 189 |
}
|
| 190 |
|
| 191 |
+
/* Khung Chatbot chính: Nền trắng, bo tròn mềm mại, đổ bóng nhẹ */
|
| 192 |
+
[data-testid="chatbot"], .chatbot {
|
| 193 |
+
background-color: #ffffff !important;
|
| 194 |
+
border: 1px solid #e2e8f0 !important;
|
| 195 |
+
border-radius: 20px !important;
|
| 196 |
+
box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.05) !important;
|
| 197 |
+
min-height: 520px !important;
|
| 198 |
}
|
| 199 |
|
| 200 |
+
/* Tin nhắn Người dùng: Nền xanh nhạt dịu mắt (Google Blue tint), chữ xanh đậm rõ nét */
|
| 201 |
+
[data-testid="user"], .message.user, .user-row .message {
|
| 202 |
+
background-color: #e8f0fe !important;
|
| 203 |
+
border: 1px solid #d2e3fc !important;
|
| 204 |
+
color: #174ea6 !important;
|
| 205 |
border-radius: 20px 20px 4px 20px !important;
|
|
|
|
| 206 |
padding: 12px 18px !important;
|
| 207 |
font-size: 15px !important;
|
| 208 |
+
font-weight: 500 !important;
|
| 209 |
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04) !important;
|
| 210 |
}
|
| 211 |
|
| 212 |
+
[data-testid="user"] *, .message.user * {
|
| 213 |
+
color: #174ea6 !important;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
/* Tin nhắn Trợ lý Bot: Chữ tối rõ nét trên nền trắng, dễ đọc */
|
| 217 |
+
[data-testid="bot"], .message.bot, .bot-row .message {
|
| 218 |
background-color: transparent !important;
|
| 219 |
+
color: #1f2937 !important;
|
| 220 |
border: none !important;
|
|
|
|
|
|
|
|
|
|
| 221 |
font-size: 15px !important;
|
| 222 |
+
line-height: 1.7 !important;
|
| 223 |
+
padding: 12px 18px !important;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
[data-testid="bot"] *, .message.bot * {
|
| 227 |
+
color: #1f2937 !important;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
/* Code block hiển thị đẹp mắt và tương phản chuẩn */
|
| 231 |
+
pre {
|
| 232 |
+
background-color: #1e293b !important;
|
| 233 |
+
border-radius: 10px !important;
|
| 234 |
+
padding: 14px 16px !important;
|
| 235 |
+
color: #f8fafc !important;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
pre code, pre span {
|
| 239 |
+
color: #f8fafc !important;
|
| 240 |
}
|
| 241 |
|
| 242 |
+
/* Ô nhập câu hỏi dạng viên thuốc (Pill shape) chuẩn Google */
|
| 243 |
input[type="text"], textarea {
|
| 244 |
+
background-color: #ffffff !important;
|
| 245 |
+
border: 1.5px solid #dadce0 !important;
|
| 246 |
+
border-radius: 26px !important;
|
| 247 |
+
color: #1f2937 !important;
|
| 248 |
+
padding: 12px 20px !important;
|
| 249 |
+
font-size: 15px !important;
|
| 250 |
+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04) !important;
|
| 251 |
}
|
| 252 |
|
| 253 |
input[type="text"]:focus, textarea:focus {
|
| 254 |
+
border-color: #1a73e8 !important;
|
| 255 |
+
box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.15) !important;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
/* Khối Accordion cài đặt: Thu gọn, nền trắng, tinh gọn */
|
| 259 |
+
details, .gr-accordion {
|
| 260 |
+
background-color: #ffffff !important;
|
| 261 |
+
border: 1px solid #e2e8f0 !important;
|
| 262 |
+
border-radius: 14px !important;
|
| 263 |
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03) !important;
|
| 264 |
+
margin-top: 0.75rem !important;
|
| 265 |
}
|
| 266 |
|
| 267 |
+
label, span.label-text {
|
| 268 |
+
color: #374151 !important;
|
| 269 |
+
font-weight: 500 !important;
|
|
|
|
|
|
|
| 270 |
}
|
| 271 |
|
| 272 |
footer {
|
|
|
|
| 274 |
}
|
| 275 |
"""
|
| 276 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
# ==============================================================================
|
| 278 |
+
# KHỞI TẠO GIAO DIỆN CHAT INTERFACE
|
| 279 |
# ==============================================================================
|
| 280 |
+
demo = gr.ChatInterface(
|
| 281 |
+
fn=chat_response,
|
| 282 |
+
title="✨ Google Gemma Assistant",
|
| 283 |
+
description="Trải nghiệm đối thoại AI phong cách Google Gemini • Tải trực tiếp mô hình Gemma 4 31B (4-bit ZeroGPU)",
|
| 284 |
+
textbox=gr.Textbox(
|
| 285 |
+
placeholder="Hỏi Gemma bất kỳ điều gì (nhấn Enter để gửi)...",
|
| 286 |
+
lines=1,
|
| 287 |
+
max_lines=6,
|
| 288 |
+
container=False,
|
| 289 |
+
scale=7,
|
| 290 |
+
),
|
| 291 |
+
additional_inputs=[
|
| 292 |
+
gr.Textbox(
|
| 293 |
+
label="Chỉ dẫn hệ thống (System Prompt)",
|
| 294 |
+
value=DEFAULT_SYSTEM_PROMPT,
|
| 295 |
+
lines=2,
|
| 296 |
),
|
| 297 |
+
gr.Slider(
|
| 298 |
+
minimum=0.0,
|
| 299 |
+
maximum=1.0,
|
| 300 |
+
value=0.7,
|
| 301 |
+
step=0.05,
|
| 302 |
+
label="Độ sáng tạo (Temperature)",
|
| 303 |
+
info="Giá trị thấp trả lời chuẩn xác hơn; giá trị cao trả lời phong phú và sáng tạo hơn.",
|
| 304 |
+
),
|
| 305 |
+
gr.Slider(
|
| 306 |
+
minimum=128,
|
| 307 |
+
maximum=4096,
|
| 308 |
+
value=1536,
|
| 309 |
+
step=128,
|
| 310 |
+
label="Độ dài tối đa (Max New Tokens)",
|
| 311 |
+
info="Số lượng token tối đa mô hình tạo ra trong mỗi lượt trả lời.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
),
|
| 313 |
+
gr.Slider(
|
| 314 |
+
minimum=0.1,
|
| 315 |
+
maximum=1.0,
|
| 316 |
+
value=0.9,
|
| 317 |
+
step=0.05,
|
| 318 |
+
label="Top-P (Nucleus Sampling)",
|
| 319 |
+
),
|
| 320 |
+
],
|
| 321 |
+
additional_inputs_accordion=gr.Accordion(
|
| 322 |
+
label="⚙️ Cài đặt tham số mô hình & System Prompt",
|
| 323 |
+
open=False,
|
| 324 |
+
),
|
| 325 |
+
examples=[
|
| 326 |
+
[
|
| 327 |
+
"Giải thích ngắn gọn cách hoạt động của cơ chế Multi-Head Attention trong mô hình Transformer.",
|
| 328 |
+
DEFAULT_SYSTEM_PROMPT,
|
| 329 |
+
0.7,
|
| 330 |
+
1536,
|
| 331 |
+
0.9,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
],
|
| 333 |
+
[
|
| 334 |
+
"Viết một kịch bản ngắn giới thiệu vẻ đẹp thiên nhiên và văn hóa cồng chiêng của vùng đất Gia Lai.",
|
| 335 |
+
DEFAULT_SYSTEM_PROMPT,
|
| 336 |
+
0.7,
|
| 337 |
+
1536,
|
| 338 |
+
0.9,
|
| 339 |
+
],
|
| 340 |
+
[
|
| 341 |
+
"Tạo một hàm Python đọc tệp CSV, làm sạch dữ liệu thiếu và vẽ biểu đồ xu hướng bằng Matplotlib.",
|
| 342 |
+
DEFAULT_SYSTEM_PROMPT,
|
| 343 |
+
0.7,
|
| 344 |
+
1536,
|
| 345 |
+
0.9,
|
| 346 |
+
],
|
| 347 |
+
[
|
| 348 |
+
"So sánh ưu điểm và nhược điểm giữa cấu trúc Dense Model và Mixture-of-Experts (MoE).",
|
| 349 |
+
DEFAULT_SYSTEM_PROMPT,
|
| 350 |
+
0.7,
|
| 351 |
+
1536,
|
| 352 |
+
0.9,
|
| 353 |
+
],
|
| 354 |
+
],
|
| 355 |
+
cache_examples=False,
|
| 356 |
+
)
|
| 357 |
|
| 358 |
if __name__ == "__main__":
|
| 359 |
demo.queue().launch(theme=custom_theme, css=CUSTOM_CSS)
|