Spaces:
Sleeping
Sleeping
Redesign UI to AMOLED with custom bubbles and tool HTML
Browse files
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 =
|
| 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 |
-
|
|
|
|
| 204 |
# Sonucu modele geri besle
|
| 205 |
messages.append({
|
| 206 |
"role": "tool",
|
| 207 |
"name": func_name,
|
| 208 |
-
"content":
|
| 209 |
})
|
| 210 |
except Exception as e:
|
| 211 |
error_msg = {"error": str(e)}
|
| 212 |
-
turn_str += f"
|
| 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"
|
| 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 + "
|
| 232 |
|
| 233 |
# ==========================================
|
| 234 |
# 4. Gradio UI
|
| 235 |
# ==========================================
|
| 236 |
css = """
|
| 237 |
-
body {
|
| 238 |
-
|
| 239 |
-
}
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
}
|
| 247 |
-
.
|
| 248 |
-
|
| 249 |
-
|
| 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;
|
| 255 |
-
|
|
|
|
| 256 |
|
| 257 |
with gr.Row():
|
| 258 |
-
|
| 259 |
-
|
|
|
|
|
|
|
| 260 |
with gr.Row():
|
| 261 |
-
msg = gr.Textbox(placeholder="
|
| 262 |
-
submit_btn = gr.Button("Gönder", variant="primary", scale=
|
| 263 |
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 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
|