celikn commited on
Commit
4448cdf
·
verified ·
1 Parent(s): 46ae896

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -15
app.py CHANGED
@@ -507,6 +507,27 @@ Use [out:json][timeout:25]; at top.
507
  End with: out center;
508
  """
509
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
510
  def generate_overpass_query_from_llm(prompt: str, model_name: str) -> str:
511
  """
512
  Doğal dilde verilen prompt'u kullanarak Overpass QL sorgusu üretir.
@@ -564,20 +585,21 @@ def normalize_overpass_query(raw_query: str) -> str:
564
  # ==========================================
565
  # MAHALLE KARŞILAŞTIRMA BAĞLAMI
566
  # ==========================================
567
- def prepare_comparison(city, district1, neigh1, district2, neigh2):
568
  """
569
  Butona basıldığında:
570
  - Her iki mahalle için OSM özetini hazırlar
571
  - İki metin döndürür
572
  - LLM için karşılaştırma bağlamını üretir
573
  """
574
- city = (city or "").strip()
575
  district1 = (district1 or "").strip()
576
  neigh1 = (neigh1 or "").strip()
 
577
  district2 = (district2 or "").strip()
578
  neigh2 = (neigh2 or "").strip()
579
 
580
- if not city or not district1 or not neigh1 or not district2 or not neigh2:
581
  msg = "Şehir, ilçe ve iki mahalle de girilmelidir."
582
  return (msg, msg, "", "<b>Harita için yeterli veri yok.</b>")
583
 
@@ -586,9 +608,9 @@ def prepare_comparison(city, district1, neigh1, district2, neigh2):
586
  labels2 = "Bu mahalle için isim verisi çıkarılamadı."
587
 
588
  # Mahalle 1
589
- gdf1 = get_neighborhood_gdf(city, district1, neigh1)
590
  if gdf1 is None or len(gdf1) == 0:
591
- stats1 = f"{city} / {district1} / {neigh1} için veri bulunamadı."
592
  summary1 = None
593
  else:
594
  pois1 = get_pois_within(gdf1)
@@ -598,9 +620,9 @@ def prepare_comparison(city, district1, neigh1, district2, neigh2):
598
  labels1 = build_poi_names_text(pois1)
599
 
600
  # Mahalle 2
601
- gdf2 = get_neighborhood_gdf(city, district2, neigh2)
602
  if gdf2 is None or len(gdf2) == 0:
603
- stats2 = f"{city} / {district2} / {neigh2} için veri bulunamadı."
604
  summary2 = None
605
  else:
606
  pois2 = get_pois_within(gdf2)
@@ -611,13 +633,15 @@ def prepare_comparison(city, district1, neigh1, district2, neigh2):
611
 
612
  # LLM bağlamı
613
  compare_context_parts = [
614
- f"Şehir: {city}",
615
  "",
616
  f"1. Mahalle: {neigh1} (İlçe: {district1})",
617
  stats1,
618
  "",
619
  "1. mahalledeki önemli POI isimleri (okullar, eczaneler, marketler, kafeler vb.):",
620
  labels1,
 
 
621
  "",
622
  f"2. Mahalle: {neigh2} (İlçe: {district2})",
623
  stats2,
@@ -1239,14 +1263,16 @@ with gr.Blocks() as demo:
1239
  with gr.Column(scale=1):
1240
  gr.Markdown("### Mahalle Karşılaştırma")
1241
 
1242
- city_in = gr.Textbox(
1243
- label="Şehir",
1244
- value="Ankara",
1245
- placeholder="Örn: Ankara",
1246
- )
1247
 
1248
  # 1. mahalle: ilçe + mahalle aynı satırda
1249
  with gr.Row():
 
 
 
 
 
 
1250
  district1_in = gr.Textbox(
1251
  label="1. İlçe",
1252
  value="Gölbaşı",
@@ -1262,6 +1288,11 @@ with gr.Blocks() as demo:
1262
 
1263
  # 2. mahalle: ilçe + mahalle aynı satırda
1264
  with gr.Row():
 
 
 
 
 
1265
  district2_in = gr.Textbox(
1266
  label="2. İlçe",
1267
  value="Gölbaşı",
@@ -1326,7 +1357,7 @@ with gr.Blocks() as demo:
1326
 
1327
  nearest_poi_btn.click(
1328
  fn=nearest_poi_wrapper,
1329
- inputs=[city_in, district1_in, neigh1_in, poi_type_dropdown],
1330
  outputs=[nearest_poi_box],
1331
  )
1332
 
@@ -1351,7 +1382,7 @@ with gr.Blocks() as demo:
1351
 
1352
  compare_btn.click(
1353
  fn=prepare_comparison,
1354
- inputs=[city_in, district1_in, neigh1_in, district2_in, neigh2_in],
1355
  outputs=[stats1_box, stats2_box, compare_state, map_html],
1356
  )
1357
 
 
507
  End with: out center;
508
  """
509
 
510
+
511
+ from pathlib import Path
512
+
513
+ OSM_PROMPT_PATH = Path("osm_query_system.txt") # veya Path("data/osm_query_system.txt")
514
+
515
+ try:
516
+ with OSM_PROMPT_PATH.open("r", encoding="utf-8") as f:
517
+ OSM_QUERY_SYSTEM = f.read()
518
+ print(f"OSM system prompt '{OSM_PROMPT_PATH}' dosyasından yüklendi.")
519
+ except FileNotFoundError:
520
+ print(f"UYARI: {OSM_PROMPT_PATH} bulunamadı, kısa yedek prompt kullanılacak.")
521
+ OSM_QUERY_SYSTEM = """
522
+ You are an expert in OpenStreetMap and Overpass API.
523
+ Produce only valid Overpass QL.
524
+ No explanations. No markdown.
525
+ Use [out:json][timeout:25]; at top.
526
+ End with: out center;
527
+ """
528
+
529
+
530
+
531
  def generate_overpass_query_from_llm(prompt: str, model_name: str) -> str:
532
  """
533
  Doğal dilde verilen prompt'u kullanarak Overpass QL sorgusu üretir.
 
585
  # ==========================================
586
  # MAHALLE KARŞILAŞTIRMA BAĞLAMI
587
  # ==========================================
588
+ def prepare_comparison(city1, district1, neigh1,city1, district2, neigh2):
589
  """
590
  Butona basıldığında:
591
  - Her iki mahalle için OSM özetini hazırlar
592
  - İki metin döndürür
593
  - LLM için karşılaştırma bağlamını üretir
594
  """
595
+ city1 = (city1 or "").strip()
596
  district1 = (district1 or "").strip()
597
  neigh1 = (neigh1 or "").strip()
598
+ city2 = (city2 or "").strip()
599
  district2 = (district2 or "").strip()
600
  neigh2 = (neigh2 or "").strip()
601
 
602
+ if not city1 or not district1 or not city1 or not neigh1 or not district2 or not neigh2:
603
  msg = "Şehir, ilçe ve iki mahalle de girilmelidir."
604
  return (msg, msg, "", "<b>Harita için yeterli veri yok.</b>")
605
 
 
608
  labels2 = "Bu mahalle için isim verisi çıkarılamadı."
609
 
610
  # Mahalle 1
611
+ gdf1 = get_neighborhood_gdf(city1, district1, neigh1)
612
  if gdf1 is None or len(gdf1) == 0:
613
+ stats1 = f"{city1} / {district1} / {neigh1} için veri bulunamadı."
614
  summary1 = None
615
  else:
616
  pois1 = get_pois_within(gdf1)
 
620
  labels1 = build_poi_names_text(pois1)
621
 
622
  # Mahalle 2
623
+ gdf2 = get_neighborhood_gdf(city2, district2, neigh2)
624
  if gdf2 is None or len(gdf2) == 0:
625
+ stats2 = f"{city2} / {district2} / {neigh2} için veri bulunamadı."
626
  summary2 = None
627
  else:
628
  pois2 = get_pois_within(gdf2)
 
633
 
634
  # LLM bağlamı
635
  compare_context_parts = [
636
+ f"Şehir: {city1}",
637
  "",
638
  f"1. Mahalle: {neigh1} (İlçe: {district1})",
639
  stats1,
640
  "",
641
  "1. mahalledeki önemli POI isimleri (okullar, eczaneler, marketler, kafeler vb.):",
642
  labels1,
643
+ "",
644
+ f"Şehir: {city2}",
645
  "",
646
  f"2. Mahalle: {neigh2} (İlçe: {district2})",
647
  stats2,
 
1263
  with gr.Column(scale=1):
1264
  gr.Markdown("### Mahalle Karşılaştırma")
1265
 
1266
+
 
 
 
 
1267
 
1268
  # 1. mahalle: ilçe + mahalle aynı satırda
1269
  with gr.Row():
1270
+ city_in1 = gr.Textbox(
1271
+ label="1. Şehir",
1272
+ value="Ankara",
1273
+ placeholder="Örn: Ankara",
1274
+ )
1275
+
1276
  district1_in = gr.Textbox(
1277
  label="1. İlçe",
1278
  value="Gölbaşı",
 
1288
 
1289
  # 2. mahalle: ilçe + mahalle aynı satırda
1290
  with gr.Row():
1291
+ city_in2 = gr.Textbox(
1292
+ label="2. Şehir",
1293
+ value="Ankara",
1294
+ placeholder="Örn: Ankara",
1295
+ )
1296
  district2_in = gr.Textbox(
1297
  label="2. İlçe",
1298
  value="Gölbaşı",
 
1357
 
1358
  nearest_poi_btn.click(
1359
  fn=nearest_poi_wrapper,
1360
+ inputs=[city_in1, district1_in, neigh1_in, poi_type_dropdown],
1361
  outputs=[nearest_poi_box],
1362
  )
1363
 
 
1382
 
1383
  compare_btn.click(
1384
  fn=prepare_comparison,
1385
+ inputs=[city_in1, district1_in, neigh1_in,city_in1, district2_in, neigh2_in],
1386
  outputs=[stats1_box, stats2_box, compare_state, map_html],
1387
  )
1388