Mer1Alii commited on
Commit
af5afb9
·
verified ·
1 Parent(s): 666c090

Redesign UI to AMOLED with custom bubbles and tool HTML

Browse files
Files changed (1) hide show
  1. app.py +33 -36
app.py CHANGED
@@ -188,28 +188,28 @@ def chat_interface(user_input, history):
188
  break
189
 
190
  # Tool çağrısı varsa UI'da göstermek için metin formatla
191
- turn_str = f"\n\n[Turn {turn}] Araç Çağrıları:\n"
192
 
193
  for call in tool_calls:
194
  func_name = call.get("name")
195
  args = call.get("arguments", {})
196
-
197
- turn_str += f" -> {func_name}({', '.join(f'{k}={v}' for k, v in args.items())})\n"
198
 
199
  # Aracı çalıştır
200
  if func_name in available_functions:
201
  try:
202
  result = available_functions[func_name](**args)
203
- turn_str += f" <- {json.dumps(result, ensure_ascii=False)}\n"
 
204
  # Sonucu modele geri besle
205
  messages.append({
206
  "role": "tool",
207
  "name": func_name,
208
- "content": json.dumps(result, ensure_ascii=False)
209
  })
210
  except Exception as e:
211
  error_msg = {"error": str(e)}
212
- turn_str += f" <- {json.dumps(error_msg, ensure_ascii=False)}\n"
213
  messages.append({
214
  "role": "tool",
215
  "name": func_name,
@@ -217,7 +217,7 @@ def chat_interface(user_input, history):
217
  })
218
  else:
219
  error_msg = {"error": f"Bilinmeyen fonksiyon: {func_name}"}
220
- turn_str += f" <- {json.dumps(error_msg, ensure_ascii=False)}\n"
221
  messages.append({
222
  "role": "tool",
223
  "name": func_name,
@@ -228,47 +228,44 @@ def chat_interface(user_input, history):
228
  turn += 1
229
 
230
  # Ara adımları UI'da akarak göster (stream)
231
- yield final_output + "\n\n(Model düşünüyor...)"
232
 
233
  # ==========================================
234
  # 4. Gradio UI
235
  # ==========================================
236
  css = """
237
- body {
238
- background: linear-gradient(135deg, #121212, #000000);
239
- }
240
- #chatbot {
241
- background: rgba(255, 255, 255, 0.04) !important;
242
- backdrop-filter: blur(12px) !important;
243
- border-radius: 24px !important;
244
- border: 0.5px solid rgba(255, 255, 255, 0.1) !important;
245
- box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37) !important;
246
- }
247
- .message {
248
- border-radius: 16px !important;
249
- padding: 12px 18px !important;
250
- }
251
  """
252
 
253
  with gr.Blocks(theme=gr.themes.Base(), css=css) as demo:
254
- gr.Markdown("<h1 style='text-align: center; font-weight: 300; color: #fff;'>🌍 Agentic Disaster Tracker</h1>")
255
- gr.Markdown("<p style='text-align: center; color: #aaa;'>Bu uygulama <b>Tool Calling</b> teknolojisini kullanarak, dünya genelindeki deprem ve orman yangınlarını takip eder.<br>Hugging Face <b>ZeroGPU</b> altyapısı ve <b>Qwen2.5-7B-Instruct</b> modeli kullanılarak geliştirilmiştir.</p>")
 
256
 
257
  with gr.Row():
258
- chatbot = gr.Chatbot(elem_id="chatbot", height=600, label="Afet Takip Asistanı", show_label=False)
259
-
 
 
260
  with gr.Row():
261
- msg = gr.Textbox(placeholder="Örn: 2026-07-25 ile 2026-07-30 arasındaki yangınlar...", label="Mesajınız", lines=2, show_label=False)
262
- submit_btn = gr.Button("Gönder", variant="primary", scale=0)
263
 
264
- gr.Examples(
265
- examples=[
266
- "2026-07-25 ile 2026-07-30 tarihleri arasındaki 5.5 üzeri depremleri listele.",
267
- "Şu anki aktif büyük orman yangınları hangileri? 3 tanesini getir.",
268
- "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ı?"
269
- ],
270
- inputs=msg
271
- )
272
 
273
  def respond(user_message, chat_history):
274
  # Arayüze kullanıcının mesajını ekle
 
188
  break
189
 
190
  # Tool çağrısı varsa UI'da göstermek için metin formatla
191
+ turn_str = ""
192
 
193
  for call in tool_calls:
194
  func_name = call.get("name")
195
  args = call.get("arguments", {})
196
+ args_str = ", ".join(f"{k}={v}" for k, v in args.items())
 
197
 
198
  # Aracı çalıştır
199
  if func_name in available_functions:
200
  try:
201
  result = available_functions[func_name](**args)
202
+ res_json = json.dumps(result, ensure_ascii=False)
203
+ turn_str += f"<div class='tool-box'><div class='tool-title'>🛠️ Araç: {func_name}</div><div class='tool-code'>Girdi: {args_str}</div><div class='tool-code'>Çıktı: {res_json[:200]}...</div></div>"
204
  # Sonucu modele geri besle
205
  messages.append({
206
  "role": "tool",
207
  "name": func_name,
208
+ "content": res_json
209
  })
210
  except Exception as e:
211
  error_msg = {"error": str(e)}
212
+ turn_str += f"<div class='tool-box'><div class='tool-title'>⚠️ Hata: {func_name}</div><div class='tool-code'>{str(e)}</div></div>"
213
  messages.append({
214
  "role": "tool",
215
  "name": func_name,
 
217
  })
218
  else:
219
  error_msg = {"error": f"Bilinmeyen fonksiyon: {func_name}"}
220
+ turn_str += f"<div class='tool-box'><div class='tool-title'>⚠️ Bilinmeyen Araç: {func_name}</div></div>"
221
  messages.append({
222
  "role": "tool",
223
  "name": func_name,
 
228
  turn += 1
229
 
230
  # Ara adımları UI'da akarak göster (stream)
231
+ yield final_output + "<br><i style='color:#666; font-size: 0.9em;'>💭 Model aksiyon alıyor...</i>"
232
 
233
  # ==========================================
234
  # 4. Gradio UI
235
  # ==========================================
236
  css = """
237
+ body { background-color: #000000 !important; color: #e0e0e0; font-family: 'Inter', sans-serif; }
238
+ .gradio-container { background: #000000 !important; border: none !important; }
239
+ #chatbot { background: #000000 !important; border: none !important; box-shadow: none !important; }
240
+ .message { border-radius: 12px !important; border: 1px solid #333 !important; padding: 14px !important; }
241
+ .bot { background: #0a0a0a !important; color: #ccc !important; }
242
+ .user { background: #1a1a1a !important; color: #fff !important; }
243
+ .tool-box { background: #111; border: 1px solid #222; border-left: 3px solid #555; padding: 10px; margin: 8px 0; border-radius: 4px 8px 8px 4px; font-size: 0.85em; color: #999; }
244
+ .tool-title { font-weight: 600; color: #bbb; margin-bottom: 4px; }
245
+ .tool-code { font-family: monospace; background: #000; padding: 4px; border-radius: 4px; overflow-wrap: break-word; }
246
+ .bubble-btn { background: #111 !important; border: 1px solid #333 !important; border-radius: 20px !important; color: #aaa !important; font-size: 0.85em !important; padding: 4px 12px !important; box-shadow: none !important; cursor: pointer; transition: 0.2s; min-width: auto !important; flex-grow: 0 !important; }
247
+ .bubble-btn:hover { background: #222 !important; color: #fff !important; border-color: #555 !important; }
248
+ #msg_box textarea { background: #111 !important; border: 1px solid #333 !important; color: white !important; border-radius: 12px !important; }
249
+ #submit_btn { background: #222 !important; color: white !important; border: 1px solid #444 !important; border-radius: 12px !important; }
 
250
  """
251
 
252
  with gr.Blocks(theme=gr.themes.Base(), css=css) as demo:
253
+ gr.Markdown("<h1 style='text-align: center; color: #fff; font-weight: 300;'>🌍 Agentic Disaster Tracker</h1>")
254
+
255
+ chatbot = gr.Chatbot(elem_id="chatbot", height=500, label="Asistan", show_label=False)
256
 
257
  with gr.Row():
258
+ ex1 = gr.Button("Son depremler", elem_classes="bubble-btn")
259
+ ex2 = gr.Button("Aktif yangınlar", elem_classes="bubble-btn")
260
+ ex3 = gr.Button("Deprem ve yangınları birleştir", elem_classes="bubble-btn")
261
+
262
  with gr.Row():
263
+ msg = gr.Textbox(placeholder="Afetlerle ilgili ne öğrenmek istersiniz?", label="Mesajınız", lines=1, show_label=False, elem_id="msg_box", scale=4)
264
+ submit_btn = gr.Button("Gönder", variant="primary", scale=1, elem_id="submit_btn")
265
 
266
+ ex1.click(lambda: "2026-07-25 ile 2026-07-30 tarihleri arasındaki 5.5 üzeri depremleri listele.", outputs=msg)
267
+ ex2.click(lambda: "Şu anki aktif büyük orman yangınları hangileri? 3 tanesini getir.", outputs=msg)
268
+ 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)
 
 
 
 
 
269
 
270
  def respond(user_message, chat_history):
271
  # Arayüze kullanıcının mesajını ekle