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

Fix get_wildfires to use NASA EONET and update UI with Glassmorphism

Browse files
Files changed (1) hide show
  1. app.py +37 -23
app.py CHANGED
@@ -34,21 +34,20 @@ def get_earthquakes(start_date: str, end_date: str, min_magnitude: float):
34
 
35
  def get_wildfires(limit: int = 5):
36
  """
37
- Dünya genelindeki son aktif orman yangınlarını (GDACS üzerinden) getirir.
38
  """
39
  try:
40
- url = "https://www.gdacs.org/gdacsapi/api/events/geteventlist/SEARCH?eventlist=WF"
41
  res = requests.get(url, timeout=10)
42
  data = res.json()
43
- features = data.get('features', [])[:limit]
44
  results = []
45
- for f in features:
46
- props = f.get('properties', {})
47
  results.append({
48
- "name": props.get('name'),
49
- "country": props.get('country'),
50
- "alert_level": props.get('alertlevel'),
51
- "description": props.get('htmldescription')
52
  })
53
  return {"count": len(results), "wildfires": results}
54
  except Exception as e:
@@ -80,7 +79,7 @@ tools = [
80
  "type": "function",
81
  "function": {
82
  "name": "get_wildfires",
83
- "description": "Güncel aktif orman yangınlarını GDACS üzerinden getirir.",
84
  "parameters": {
85
  "type": "object",
86
  "properties": {
@@ -234,24 +233,39 @@ def chat_interface(user_input, history):
234
  # ==========================================
235
  # 4. Gradio UI
236
  # ==========================================
237
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="red")) as demo:
238
- gr.Markdown("# 🌍 Agentic Disaster Tracker")
239
- gr.Markdown("""
240
- Bu uygulama **Tool Calling** (Function Calling) teknolojisini kullanarak, dünya genelindeki deprem ve orman yangınlarını takip eder.
241
- Hugging Face **ZeroGPU** altyapısı ve **Qwen2.5-7B-Instruct** modeli kullanılarak geliştirilmiştir.
242
-
243
- Arka planda çağrılan araçları (USGS Earthquake & GDACS Wildfires) adımlar halinde görebilirsiniz.
244
- """)
 
 
 
 
 
 
 
 
 
 
 
 
245
 
246
- chatbot = gr.Chatbot(height=500, label="Afet Takip Asistanı")
247
- msg = gr.Textbox(placeholder="Örn: Son 3 günde dünyada olan 6.0 üzeri depremleri ve güncel yangınları getir.", label="Mesajınız", lines=2)
248
- submit_btn = gr.Button("Gönder", variant="primary")
 
 
 
249
 
250
  gr.Examples(
251
  examples=[
252
- "2023-10-01 ile 2023-10-05 tarihleri arasındaki 5.5 üzeri depremleri listele.",
253
  "Şu anki aktif büyük orman yangınları hangileri? 3 tanesini getir.",
254
- "Son 7 günde 6.0'dan büyük deprem oldu mu? Ayrıca şu an aktif orman yangını var mı?"
255
  ],
256
  inputs=msg
257
  )
 
34
 
35
  def get_wildfires(limit: int = 5):
36
  """
37
+ Dünya genelindeki son aktif orman yangınlarını (NASA EONET üzerinden) getirir.
38
  """
39
  try:
40
+ url = "https://eonet.gsfc.nasa.gov/api/v3/events?category=wildfires&status=open"
41
  res = requests.get(url, timeout=10)
42
  data = res.json()
43
+ events = data.get('events', [])[:limit]
44
  results = []
45
+ for e in events:
46
+ geom = e.get('geometry', [{}])[0]
47
  results.append({
48
+ "title": e.get('title'),
49
+ "date": geom.get('date'),
50
+ "coordinates": geom.get('coordinates')
 
51
  })
52
  return {"count": len(results), "wildfires": results}
53
  except Exception as e:
 
79
  "type": "function",
80
  "function": {
81
  "name": "get_wildfires",
82
+ "description": "Güncel aktif orman yangınlarını NASA EONET üzerinden getirir.",
83
  "parameters": {
84
  "type": "object",
85
  "properties": {
 
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
  )