Spaces:
Running on Zero
Running on Zero
Clean up unnecessary comments in UI code
Browse files
app.py
CHANGED
|
@@ -149,30 +149,32 @@ def parse_tool_calls(text):
|
|
| 149 |
def _escape(text: str) -> str:
|
| 150 |
return text.replace("&", "&").replace("<", "<").replace(">", ">")
|
| 151 |
|
|
|
|
| 152 |
def render_thinking(text: str) -> str:
|
| 153 |
-
"""Modelin araç çağrısı öncesi/yanındaki serbest metnini
|
| 154 |
return (
|
| 155 |
-
f'<
|
| 156 |
-
f'<
|
| 157 |
-
f'<div class="
|
| 158 |
-
f'</
|
| 159 |
)
|
| 160 |
|
| 161 |
def render_tool(name: str, args_str: str, output_str: str, is_error: bool = False) -> str:
|
| 162 |
-
"""Bir araç çağrısını
|
| 163 |
-
|
| 164 |
-
|
| 165 |
return (
|
| 166 |
-
f'<
|
| 167 |
-
f'<
|
| 168 |
-
f'<div class="
|
| 169 |
-
f'<div class="
|
| 170 |
-
f'<div class="
|
| 171 |
f'</div>'
|
|
|
|
| 172 |
)
|
| 173 |
|
| 174 |
-
def render_status(text: str = "
|
| 175 |
-
return f'<div class="status-
|
| 176 |
|
| 177 |
def chat_interface(user_input, history):
|
| 178 |
if not model:
|
|
@@ -229,7 +231,7 @@ def chat_interface(user_input, history):
|
|
| 229 |
try:
|
| 230 |
result = available_functions[func_name](**args)
|
| 231 |
res_json = json.dumps(result, ensure_ascii=False)
|
| 232 |
-
out_display = res_json[:
|
| 233 |
final_output += render_tool(func_name, args_str, out_display)
|
| 234 |
# Sonucu modele geri besle
|
| 235 |
messages.append({
|
|
@@ -257,237 +259,234 @@ def chat_interface(user_input, history):
|
|
| 257 |
turn += 1
|
| 258 |
|
| 259 |
# Ara adımları UI'da akarak göster (stream)
|
| 260 |
-
yield final_output + render_status("
|
| 261 |
|
| 262 |
# ==========================================
|
| 263 |
-
# 4. Gradio UI
|
| 264 |
# ==========================================
|
| 265 |
css = """
|
| 266 |
-
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@
|
| 267 |
-
|
| 268 |
-
:root {
|
| 269 |
-
--bg: #000000;
|
| 270 |
-
--fg: #ededed;
|
| 271 |
-
--fg-dim: #9a9a9a;
|
| 272 |
-
--fg-dimmer: #5c5c5c;
|
| 273 |
-
--line: #232323;
|
| 274 |
-
--think: #8f8f8f;
|
| 275 |
-
}
|
| 276 |
-
|
| 277 |
-
* { box-sizing: border-box; }
|
| 278 |
|
| 279 |
body, .gradio-container {
|
| 280 |
-
|
| 281 |
-
color: var(--fg) !important;
|
| 282 |
-
font-family: 'Inter', system-ui, -apple-system, sans-serif !important;
|
| 283 |
}
|
| 284 |
|
| 285 |
.gradio-container {
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
max-width: 900px !important;
|
| 289 |
-
margin: 0 auto !important;
|
| 290 |
}
|
| 291 |
|
|
|
|
| 292 |
footer { display: none !important; }
|
| 293 |
-
::selection { background: #3a3a3a; color: #fff; }
|
| 294 |
-
|
| 295 |
-
/* ince, gri kaydırma çubuğu */
|
| 296 |
-
::-webkit-scrollbar { width: 6px; height: 6px; }
|
| 297 |
-
::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 4px; }
|
| 298 |
-
::-webkit-scrollbar-track { background: transparent; }
|
| 299 |
|
| 300 |
-
/*
|
| 301 |
-
.header-
|
| 302 |
-
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
|
| 305 |
-
/*
|
| 306 |
#chatbot {
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
}
|
| 311 |
-
#chatbot .message-wrap,
|
| 312 |
-
#chatbot .wrap,
|
| 313 |
-
#chatbot .bot-row,
|
| 314 |
-
#chatbot .user-row {
|
| 315 |
-
background: transparent !important;
|
| 316 |
}
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
}
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
}
|
| 329 |
-
|
| 330 |
-
|
| 331 |
}
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
border-top: 1px solid var(--line);
|
| 335 |
-
margin-top: 4px;
|
| 336 |
-
padding-top: 4px;
|
| 337 |
}
|
| 338 |
|
| 339 |
-
/*
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
}
|
| 345 |
-
.
|
| 346 |
-
|
| 347 |
-
display: block;
|
| 348 |
-
font-family: 'JetBrains Mono', monospace;
|
| 349 |
-
font-size: 0.65em;
|
| 350 |
-
letter-spacing: 0.14em;
|
| 351 |
-
text-transform: uppercase;
|
| 352 |
-
color: var(--fg-dimmer);
|
| 353 |
-
margin-bottom: 5px;
|
| 354 |
}
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
}
|
| 362 |
|
| 363 |
-
/*
|
| 364 |
-
.
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
|
|
|
|
|
|
| 368 |
}
|
| 369 |
-
.
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
margin-bottom: 5px;
|
| 377 |
}
|
| 378 |
-
.
|
| 379 |
-
|
| 380 |
-
background: #9a9a9a;
|
| 381 |
-
display: inline-block;
|
| 382 |
-
flex-shrink: 0;
|
| 383 |
}
|
| 384 |
-
.
|
| 385 |
-
|
| 386 |
-
font-size: 0.78em;
|
| 387 |
-
color: var(--fg-dim);
|
| 388 |
-
padding: 2px 0;
|
| 389 |
-
word-break: break-word;
|
| 390 |
-
white-space: pre-wrap;
|
| 391 |
}
|
| 392 |
-
.
|
| 393 |
-
|
| 394 |
-
|
|
|
|
| 395 |
}
|
| 396 |
-
.
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
.status-line {
|
| 401 |
-
display: flex;
|
| 402 |
-
align-items: center;
|
| 403 |
-
gap: 8px;
|
| 404 |
-
color: var(--fg-dimmer);
|
| 405 |
-
font-size: 0.8em;
|
| 406 |
-
margin-top: 8px;
|
| 407 |
-
font-style: italic;
|
| 408 |
}
|
| 409 |
-
.
|
| 410 |
-
|
| 411 |
-
background: var(--fg-dim);
|
| 412 |
-
animation: pulse 1.2s ease-in-out infinite;
|
| 413 |
-
flex-shrink: 0;
|
| 414 |
}
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
/* ---------- örnek baloncukları (textbox'ın üstünde, küçük) ---------- */
|
| 418 |
-
.examples-row { margin-bottom: 8px !important; gap: 6px !important; }
|
| 419 |
-
.bubble-btn {
|
| 420 |
-
background: transparent !important;
|
| 421 |
-
border: 1px solid #2c2c2c !important;
|
| 422 |
-
border-radius: 999px !important;
|
| 423 |
-
color: var(--fg-dim) !important;
|
| 424 |
-
font-size: 0.76em !important;
|
| 425 |
-
font-weight: 400 !important;
|
| 426 |
-
padding: 5px 14px !important;
|
| 427 |
-
min-width: auto !important;
|
| 428 |
-
flex-grow: 0 !important;
|
| 429 |
-
box-shadow: none !important;
|
| 430 |
-
transition: color .15s ease, border-color .15s ease;
|
| 431 |
}
|
| 432 |
-
.
|
| 433 |
-
|
| 434 |
-
|
|
|
|
|
|
|
|
|
|
| 435 |
}
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
font-size: 0.95em !important;
|
| 446 |
}
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
}
|
| 451 |
-
#msg_box textarea::placeholder { color: #555 !important; }
|
| 452 |
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
}
|
| 460 |
-
#submit_btn:hover { border-color: #7a7a7a !important; color: #fff !important; }
|
| 461 |
"""
|
| 462 |
|
| 463 |
-
with gr.Blocks(theme=gr.themes.
|
| 464 |
-
gr.Markdown(
|
| 465 |
-
"<div class='header-wrap'>"
|
| 466 |
-
"<div class='header-title'>🌍 AFET TAKİP</div>"
|
| 467 |
-
"<div class='header-sub'>agentic disaster intelligence</div>"
|
| 468 |
-
"</div>"
|
| 469 |
-
)
|
| 470 |
|
| 471 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 472 |
|
|
|
|
| 473 |
with gr.Row(elem_classes="examples-row"):
|
| 474 |
-
ex1 = gr.Button("
|
| 475 |
-
ex2 = gr.Button("
|
| 476 |
-
ex3 = gr.Button("
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 482 |
ex1.click(lambda: "2026-07-25 ile 2026-07-30 tarihleri arasındaki 5.5 üzeri depremleri listele.", outputs=msg)
|
| 483 |
ex2.click(lambda: "Şu anki aktif büyük orman yangınları hangileri? 3 tanesini getir.", outputs=msg)
|
| 484 |
ex3.click(lambda: "Son 7 günde (2026-07-23 ile 2026-07-30) 6.0'dan büyük deprem oldu mu? Ayrıca şu an aktif orman yangını var mı?", outputs=msg)
|
| 485 |
|
| 486 |
def respond(user_message, chat_history):
|
| 487 |
-
|
|
|
|
|
|
|
| 488 |
chat_history.append((user_message, ""))
|
| 489 |
|
| 490 |
-
# Jeneratörden gelen kısımları adım adım güncelle
|
| 491 |
for bot_message in chat_interface(user_message, chat_history[:-1]):
|
| 492 |
chat_history[-1] = (user_message, bot_message)
|
| 493 |
yield chat_history, ""
|
|
|
|
| 149 |
def _escape(text: str) -> str:
|
| 150 |
return text.replace("&", "&").replace("<", "<").replace(">", ">")
|
| 151 |
|
| 152 |
+
# Arayüz için HTML Oluşturucuları
|
| 153 |
def render_thinking(text: str) -> str:
|
| 154 |
+
"""Modelin araç çağrısı öncesi/yanındaki serbest metnini açılır-kapanır blok olarak gösterir."""
|
| 155 |
return (
|
| 156 |
+
f'<details class="chatgpt-details">'
|
| 157 |
+
f'<summary>🤔 Düşünce Süreci</summary>'
|
| 158 |
+
f'<div class="details-content thinking-text">{_escape(text)}</div>'
|
| 159 |
+
f'</details>'
|
| 160 |
)
|
| 161 |
|
| 162 |
def render_tool(name: str, args_str: str, output_str: str, is_error: bool = False) -> str:
|
| 163 |
+
"""Bir araç çağrısını açılır-kapanır şık bir blok olarak gösterir."""
|
| 164 |
+
icon = "⚠️" if is_error else "🛠️"
|
| 165 |
+
status = "Hata" if is_error else "Başarılı"
|
| 166 |
return (
|
| 167 |
+
f'<details class="chatgpt-details">'
|
| 168 |
+
f'<summary>{icon} Araç Kullanımı: <code>{_escape(str(name))}</code></summary>'
|
| 169 |
+
f'<div class="details-content">'
|
| 170 |
+
f'<div class="io-section"><span class="io-label">Girdi:</span> <code>{_escape(args_str)}</code></div>'
|
| 171 |
+
f'<div class="io-section"><span class="io-label">Çıktı ({status}):</span> <pre><code>{_escape(output_str)}</code></pre></div>'
|
| 172 |
f'</div>'
|
| 173 |
+
f'</details>'
|
| 174 |
)
|
| 175 |
|
| 176 |
+
def render_status(text: str = "Model düşünüyor") -> str:
|
| 177 |
+
return f'<div class="status-indicator"><span class="spinner"></span>{_escape(text)}...</div>'
|
| 178 |
|
| 179 |
def chat_interface(user_input, history):
|
| 180 |
if not model:
|
|
|
|
| 231 |
try:
|
| 232 |
result = available_functions[func_name](**args)
|
| 233 |
res_json = json.dumps(result, ensure_ascii=False)
|
| 234 |
+
out_display = res_json[:300] + ("…" if len(res_json) > 300 else "")
|
| 235 |
final_output += render_tool(func_name, args_str, out_display)
|
| 236 |
# Sonucu modele geri besle
|
| 237 |
messages.append({
|
|
|
|
| 259 |
turn += 1
|
| 260 |
|
| 261 |
# Ara adımları UI'da akarak göster (stream)
|
| 262 |
+
yield final_output + render_status("Araç sonuçları işleniyor")
|
| 263 |
|
| 264 |
# ==========================================
|
| 265 |
+
# 4. Gradio UI
|
| 266 |
# ==========================================
|
| 267 |
css = """
|
| 268 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
|
| 270 |
body, .gradio-container {
|
| 271 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
|
|
|
|
|
|
|
| 272 |
}
|
| 273 |
|
| 274 |
.gradio-container {
|
| 275 |
+
max-width: 850px !important;
|
| 276 |
+
margin: auto !important;
|
|
|
|
|
|
|
| 277 |
}
|
| 278 |
|
| 279 |
+
/* Footer gizleme */
|
| 280 |
footer { display: none !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
|
| 282 |
+
/* Başlık */
|
| 283 |
+
.header-title {
|
| 284 |
+
text-align: center;
|
| 285 |
+
font-weight: 600;
|
| 286 |
+
font-size: 1.5rem;
|
| 287 |
+
margin-top: 1rem;
|
| 288 |
+
margin-bottom: 0.5rem;
|
| 289 |
+
}
|
| 290 |
|
| 291 |
+
/* Chatbot Alanı */
|
| 292 |
#chatbot {
|
| 293 |
+
border: none !important;
|
| 294 |
+
background: transparent !important;
|
| 295 |
+
box-shadow: none !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
}
|
| 297 |
+
|
| 298 |
+
/* Örnek Butonları (Pills) */
|
| 299 |
+
.examples-row {
|
| 300 |
+
display: flex;
|
| 301 |
+
justify-content: center;
|
| 302 |
+
gap: 8px;
|
| 303 |
+
margin-bottom: 12px;
|
| 304 |
}
|
| 305 |
+
.bubble-btn {
|
| 306 |
+
background: transparent !important;
|
| 307 |
+
border: 1px solid var(--border-color-primary) !important;
|
| 308 |
+
border-radius: 9999px !important;
|
| 309 |
+
font-size: 0.85rem !important;
|
| 310 |
+
padding: 6px 16px !important;
|
| 311 |
+
box-shadow: none !important;
|
| 312 |
+
transition: background 0.2s;
|
| 313 |
}
|
| 314 |
+
.bubble-btn:hover {
|
| 315 |
+
background: var(--neutral-100) !important;
|
| 316 |
}
|
| 317 |
+
.dark .bubble-btn:hover {
|
| 318 |
+
background: var(--neutral-800) !important;
|
|
|
|
|
|
|
|
|
|
| 319 |
}
|
| 320 |
|
| 321 |
+
/* Modern Input Alanı */
|
| 322 |
+
#input-container {
|
| 323 |
+
display: flex;
|
| 324 |
+
align-items: center;
|
| 325 |
+
border: 1px solid var(--border-color-primary);
|
| 326 |
+
border-radius: 24px;
|
| 327 |
+
padding: 4px 8px;
|
| 328 |
+
background: var(--background-fill-primary);
|
| 329 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
|
| 330 |
+
margin-bottom: 20px;
|
| 331 |
}
|
| 332 |
+
.dark #input-container {
|
| 333 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
}
|
| 335 |
+
#msg_box, #msg_box textarea {
|
| 336 |
+
border: none !important;
|
| 337 |
+
box-shadow: none !important;
|
| 338 |
+
background: transparent !important;
|
| 339 |
+
font-size: 1rem !important;
|
| 340 |
+
resize: none !important;
|
| 341 |
+
}
|
| 342 |
+
#submit_btn {
|
| 343 |
+
background: #10a37f !important;
|
| 344 |
+
color: white !important;
|
| 345 |
+
border: none !important;
|
| 346 |
+
border-radius: 50% !important;
|
| 347 |
+
width: 38px !important;
|
| 348 |
+
height: 38px !important;
|
| 349 |
+
min-width: 38px !important;
|
| 350 |
+
padding: 0 !important;
|
| 351 |
+
display: flex;
|
| 352 |
+
align-items: center;
|
| 353 |
+
justify-content: center;
|
| 354 |
+
cursor: pointer;
|
| 355 |
+
transition: transform 0.1s, background 0.2s;
|
| 356 |
+
margin-left: 8px;
|
| 357 |
+
margin-right: 4px;
|
| 358 |
+
}
|
| 359 |
+
#submit_btn:hover {
|
| 360 |
+
background: #0d8a6a !important;
|
| 361 |
+
}
|
| 362 |
+
#submit_btn:active {
|
| 363 |
+
transform: scale(0.95);
|
| 364 |
}
|
| 365 |
|
| 366 |
+
/* Araç ve Düşünce Çıktıları */
|
| 367 |
+
.chatgpt-details {
|
| 368 |
+
border: 1px solid var(--border-color-primary);
|
| 369 |
+
border-radius: 8px;
|
| 370 |
+
margin: 10px 0;
|
| 371 |
+
background-color: var(--background-fill-secondary);
|
| 372 |
+
overflow: hidden;
|
| 373 |
}
|
| 374 |
+
.chatgpt-details summary {
|
| 375 |
+
padding: 10px 14px;
|
| 376 |
+
cursor: pointer;
|
| 377 |
+
font-weight: 500;
|
| 378 |
+
font-size: 0.9rem;
|
| 379 |
+
outline: none;
|
| 380 |
+
user-select: none;
|
|
|
|
| 381 |
}
|
| 382 |
+
.chatgpt-details summary:hover {
|
| 383 |
+
background-color: var(--neutral-100);
|
|
|
|
|
|
|
|
|
|
| 384 |
}
|
| 385 |
+
.dark .chatgpt-details summary:hover {
|
| 386 |
+
background-color: var(--neutral-800);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
}
|
| 388 |
+
.details-content {
|
| 389 |
+
padding: 12px 14px;
|
| 390 |
+
border-top: 1px solid var(--border-color-primary);
|
| 391 |
+
font-size: 0.85rem;
|
| 392 |
}
|
| 393 |
+
.thinking-text {
|
| 394 |
+
font-style: italic;
|
| 395 |
+
color: var(--body-text-color-subdued);
|
| 396 |
+
white-space: pre-wrap;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
}
|
| 398 |
+
.io-section {
|
| 399 |
+
margin-bottom: 8px;
|
|
|
|
|
|
|
|
|
|
| 400 |
}
|
| 401 |
+
.io-section:last-child {
|
| 402 |
+
margin-bottom: 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
}
|
| 404 |
+
.io-label {
|
| 405 |
+
font-weight: 600;
|
| 406 |
+
margin-right: 6px;
|
| 407 |
+
font-size: 0.8rem;
|
| 408 |
+
text-transform: uppercase;
|
| 409 |
+
letter-spacing: 0.05em;
|
| 410 |
}
|
| 411 |
+
.details-content pre {
|
| 412 |
+
background: var(--neutral-100);
|
| 413 |
+
padding: 8px;
|
| 414 |
+
border-radius: 6px;
|
| 415 |
+
overflow-x: auto;
|
| 416 |
+
margin-top: 4px;
|
| 417 |
+
}
|
| 418 |
+
.dark .details-content pre {
|
| 419 |
+
background: #1e1e1e;
|
|
|
|
| 420 |
}
|
| 421 |
+
.details-content code {
|
| 422 |
+
font-family: 'JetBrains Mono', monospace;
|
| 423 |
+
font-size: 0.8rem;
|
| 424 |
}
|
|
|
|
| 425 |
|
| 426 |
+
/* Yükleniyor / Durum Göstergesi */
|
| 427 |
+
.status-indicator {
|
| 428 |
+
display: flex;
|
| 429 |
+
align-items: center;
|
| 430 |
+
gap: 8px;
|
| 431 |
+
font-size: 0.85rem;
|
| 432 |
+
color: var(--body-text-color-subdued);
|
| 433 |
+
margin-top: 10px;
|
| 434 |
+
}
|
| 435 |
+
.spinner {
|
| 436 |
+
width: 12px;
|
| 437 |
+
height: 12px;
|
| 438 |
+
border: 2px solid var(--border-color-primary);
|
| 439 |
+
border-top-color: var(--color-accent);
|
| 440 |
+
border-radius: 50%;
|
| 441 |
+
animation: spin 1s linear infinite;
|
| 442 |
+
}
|
| 443 |
+
@keyframes spin {
|
| 444 |
+
to { transform: rotate(360deg); }
|
| 445 |
}
|
|
|
|
| 446 |
"""
|
| 447 |
|
| 448 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="zinc", neutral_hue="slate"), css=css) as demo:
|
| 449 |
+
gr.Markdown("<div class='header-title'>🌍 Afet Takip Asistanı</div>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
|
| 451 |
+
# Sohbet Ekranı
|
| 452 |
+
chatbot = gr.Chatbot(
|
| 453 |
+
elem_id="chatbot",
|
| 454 |
+
height=550,
|
| 455 |
+
show_label=False,
|
| 456 |
+
bubble_full_width=False,
|
| 457 |
+
avatar_images=(None, "https://upload.wikimedia.org/wikipedia/commons/0/04/ChatGPT_logo.svg")
|
| 458 |
+
)
|
| 459 |
|
| 460 |
+
# Örnek Sorular
|
| 461 |
with gr.Row(elem_classes="examples-row"):
|
| 462 |
+
ex1 = gr.Button("Son depremler", elem_classes="bubble-btn")
|
| 463 |
+
ex2 = gr.Button("Aktif yangınlar", elem_classes="bubble-btn")
|
| 464 |
+
ex3 = gr.Button("Deprem + Yangınları analiz et", elem_classes="bubble-btn")
|
| 465 |
+
|
| 466 |
+
# Giriş Alanı
|
| 467 |
+
with gr.Row(elem_id="input-container"):
|
| 468 |
+
msg = gr.Textbox(
|
| 469 |
+
placeholder="Afetlerle ilgili ne öğrenmek istersiniz?",
|
| 470 |
+
lines=1,
|
| 471 |
+
max_lines=4,
|
| 472 |
+
show_label=False,
|
| 473 |
+
elem_id="msg_box",
|
| 474 |
+
scale=10
|
| 475 |
+
)
|
| 476 |
+
# Gönder ikonu
|
| 477 |
+
submit_btn = gr.Button("↑", scale=1, elem_id="submit_btn")
|
| 478 |
+
|
| 479 |
+
# Buton Fonksiyonları
|
| 480 |
ex1.click(lambda: "2026-07-25 ile 2026-07-30 tarihleri arasındaki 5.5 üzeri depremleri listele.", outputs=msg)
|
| 481 |
ex2.click(lambda: "Şu anki aktif büyük orman yangınları hangileri? 3 tanesini getir.", outputs=msg)
|
| 482 |
ex3.click(lambda: "Son 7 günde (2026-07-23 ile 2026-07-30) 6.0'dan büyük deprem oldu mu? Ayrıca şu an aktif orman yangını var mı?", outputs=msg)
|
| 483 |
|
| 484 |
def respond(user_message, chat_history):
|
| 485 |
+
if not user_message.strip():
|
| 486 |
+
return chat_history, ""
|
| 487 |
+
|
| 488 |
chat_history.append((user_message, ""))
|
| 489 |
|
|
|
|
| 490 |
for bot_message in chat_interface(user_message, chat_history[:-1]):
|
| 491 |
chat_history[-1] = (user_message, bot_message)
|
| 492 |
yield chat_history, ""
|