Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -802,12 +802,18 @@ def create_comparison_map(gdf1, gdf2):
|
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
-
|
| 806 |
-
|
|
|
|
| 807 |
query = normalize_overpass_query(query) if 'normalize_overpass_query' in globals() else query
|
| 808 |
|
| 809 |
if not query or not query.strip():
|
| 810 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 811 |
|
| 812 |
url = "https://overpass-api.de/api/interpreter"
|
| 813 |
|
|
@@ -821,39 +827,51 @@ def run_overpass_to_map(query: str, previous_elements: list | None):
|
|
| 821 |
print("Overpass response text:", resp.text[:500])
|
| 822 |
except Exception:
|
| 823 |
pass
|
| 824 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 825 |
|
| 826 |
new_elements = data.get("elements", [])
|
| 827 |
if not new_elements:
|
| 828 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 829 |
|
| 830 |
-
#
|
| 831 |
-
if previous_elements
|
| 832 |
all_elements = new_elements
|
| 833 |
else:
|
| 834 |
all_elements = previous_elements + new_elements
|
| 835 |
|
| 836 |
-
# Merkez
|
| 837 |
center_lat, center_lon = None, None
|
| 838 |
for el in all_elements:
|
| 839 |
if "lat" in el and "lon" in el:
|
| 840 |
center_lat, center_lon = el["lat"], el["lon"]
|
| 841 |
break
|
|
|
|
| 842 |
if center_lat is None:
|
| 843 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 844 |
|
|
|
|
| 845 |
m = folium.Map(location=[center_lat, center_lon], zoom_start=14)
|
| 846 |
|
| 847 |
-
# Katmanlar
|
| 848 |
fg_nodes = folium.FeatureGroup(name="Noktalar")
|
| 849 |
fg_nodes.add_to(m)
|
| 850 |
fg_ways = folium.FeatureGroup(name="Yollar")
|
| 851 |
fg_ways.add_to(m)
|
| 852 |
|
| 853 |
-
# 👇 Artık sadece yeni değil, tüm elementleri çiziyoruz
|
| 854 |
for el in all_elements:
|
| 855 |
etype = el.get("type")
|
| 856 |
-
tags = el.get("tags", {})
|
| 857 |
name = tags.get("name", "")
|
| 858 |
popup_items = []
|
| 859 |
|
|
@@ -885,31 +903,29 @@ def run_overpass_to_map(query: str, previous_elements: list | None):
|
|
| 885 |
).add_to(fg_ways)
|
| 886 |
|
| 887 |
folium.LayerControl().add_to(m)
|
| 888 |
-
|
| 889 |
map_html = m._repr_html_()
|
| 890 |
|
| 891 |
-
#
|
| 892 |
-
|
| 893 |
-
|
| 894 |
if previous_spatial:
|
| 895 |
-
|
| 896 |
else:
|
| 897 |
-
|
| 898 |
-
|
| 899 |
-
return map_html, new_spatial, all_elements
|
| 900 |
|
| 901 |
-
#
|
| 902 |
-
return map_html,
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
-
|
| 907 |
-
|
|
|
|
|
|
|
| 908 |
if not natural_prompt or not natural_prompt.strip():
|
| 909 |
return (
|
| 910 |
"Doğal dil sorgu boş.",
|
| 911 |
"<b>Overpass sonucu: sorgu üretilemedi.</b>",
|
| 912 |
-
"Overpass sonucu: sorgu üretilemedi.",
|
| 913 |
previous_elements,
|
| 914 |
)
|
| 915 |
|
|
@@ -920,14 +936,19 @@ def llm_overpass_to_map(natural_prompt: str, model_name: str, previous_elements:
|
|
| 920 |
return (
|
| 921 |
f"LLM Overpass üretim hatası: {e}",
|
| 922 |
"<b>Overpass sonucu: LLM hatası.</b>",
|
| 923 |
-
"Overpass sonucu: LLM hatası.",
|
| 924 |
previous_elements,
|
| 925 |
)
|
| 926 |
|
| 927 |
-
|
| 928 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 929 |
|
| 930 |
-
return query, map_html, summary_text, all_elements
|
| 931 |
|
| 932 |
|
| 933 |
|
|
@@ -1315,11 +1336,13 @@ with gr.Blocks() as demo:
|
|
| 1315 |
# LLM ile üret + çalıştır (birikimli)
|
| 1316 |
gen_and_run_btn.click(
|
| 1317 |
fn=llm_overpass_to_map,
|
| 1318 |
-
inputs=[osm_nl_prompt, model_dropdown, overpass_elements_state],
|
| 1319 |
outputs=[overpass_box, map_html, spatial_state, overpass_elements_state],
|
| 1320 |
)
|
|
|
|
| 1321 |
|
| 1322 |
# Manuel Overpass çalıştırma (birikimli)
|
|
|
|
| 1323 |
run_overpass_btn.click(
|
| 1324 |
fn=run_overpass_to_map,
|
| 1325 |
inputs=[overpass_box, overpass_elements_state, spatial_state],
|
|
|
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
+
def run_overpass_to_map(query: str,
|
| 806 |
+
previous_elements: list | None,
|
| 807 |
+
previous_spatial: str | None):
|
| 808 |
query = normalize_overpass_query(query) if 'normalize_overpass_query' in globals() else query
|
| 809 |
|
| 810 |
if not query or not query.strip():
|
| 811 |
+
# previous_elements / previous_spatial'ı bozmadan geri dön
|
| 812 |
+
return (
|
| 813 |
+
"<b>Overpass sorgusu boş.</b>",
|
| 814 |
+
previous_spatial or "Geçerli bir Overpass sorgusu sağlanmadı.",
|
| 815 |
+
previous_elements,
|
| 816 |
+
)
|
| 817 |
|
| 818 |
url = "https://overpass-api.de/api/interpreter"
|
| 819 |
|
|
|
|
| 827 |
print("Overpass response text:", resp.text[:500])
|
| 828 |
except Exception:
|
| 829 |
pass
|
| 830 |
+
return (
|
| 831 |
+
f"<b>Overpass isteği hatası:</b> {e}",
|
| 832 |
+
previous_spatial or "Overpass isteğinde hata oluştu, veri yok.",
|
| 833 |
+
previous_elements,
|
| 834 |
+
)
|
| 835 |
|
| 836 |
new_elements = data.get("elements", [])
|
| 837 |
if not new_elements:
|
| 838 |
+
return (
|
| 839 |
+
"<b>Overpass sonucu: veri bulunamadı.</b>",
|
| 840 |
+
previous_spatial or "Overpass sonucu: hiç element bulunamadı.",
|
| 841 |
+
previous_elements,
|
| 842 |
+
)
|
| 843 |
|
| 844 |
+
# ---- Eski + yeni elementleri birleştir ----
|
| 845 |
+
if not previous_elements:
|
| 846 |
all_elements = new_elements
|
| 847 |
else:
|
| 848 |
all_elements = previous_elements + new_elements
|
| 849 |
|
| 850 |
+
# ---- Merkez bul (tüm elementler üzerinden) ----
|
| 851 |
center_lat, center_lon = None, None
|
| 852 |
for el in all_elements:
|
| 853 |
if "lat" in el and "lon" in el:
|
| 854 |
center_lat, center_lon = el["lat"], el["lon"]
|
| 855 |
break
|
| 856 |
+
|
| 857 |
if center_lat is None:
|
| 858 |
+
return (
|
| 859 |
+
"<b>Overpass sonucu: nokta verisi yok.</b>",
|
| 860 |
+
previous_spatial or "Overpass sonucu: nokta verisi bulunamadı.",
|
| 861 |
+
all_elements,
|
| 862 |
+
)
|
| 863 |
|
| 864 |
+
# ---- Haritayı çiz ----
|
| 865 |
m = folium.Map(location=[center_lat, center_lon], zoom_start=14)
|
| 866 |
|
|
|
|
| 867 |
fg_nodes = folium.FeatureGroup(name="Noktalar")
|
| 868 |
fg_nodes.add_to(m)
|
| 869 |
fg_ways = folium.FeatureGroup(name="Yollar")
|
| 870 |
fg_ways.add_to(m)
|
| 871 |
|
|
|
|
| 872 |
for el in all_elements:
|
| 873 |
etype = el.get("type")
|
| 874 |
+
tags = el.get("tags", {}) or {}
|
| 875 |
name = tags.get("name", "")
|
| 876 |
popup_items = []
|
| 877 |
|
|
|
|
| 903 |
).add_to(fg_ways)
|
| 904 |
|
| 905 |
folium.LayerControl().add_to(m)
|
|
|
|
| 906 |
map_html = m._repr_html_()
|
| 907 |
|
| 908 |
+
# ---- Yeni spatial özet ----
|
| 909 |
+
new_summary = summarize_overpass_data({"elements": new_elements})
|
|
|
|
| 910 |
if previous_spatial:
|
| 911 |
+
combined_spatial = previous_spatial + "\n\n--- Yeni Sorgu ---\n" + new_summary
|
| 912 |
else:
|
| 913 |
+
combined_spatial = new_summary
|
|
|
|
|
|
|
| 914 |
|
| 915 |
+
# 3 output: harita, birikmiş spatial metin, birikmiş element listesi
|
| 916 |
+
return map_html, combined_spatial, all_elements
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
+
def llm_overpass_to_map(natural_prompt: str,
|
| 921 |
+
model_name: str,
|
| 922 |
+
previous_elements: list | None,
|
| 923 |
+
previous_spatial: str | None):
|
| 924 |
if not natural_prompt or not natural_prompt.strip():
|
| 925 |
return (
|
| 926 |
"Doğal dil sorgu boş.",
|
| 927 |
"<b>Overpass sonucu: sorgu üretilemedi.</b>",
|
| 928 |
+
previous_spatial or "Overpass sonucu: sorgu üretilemedi.",
|
| 929 |
previous_elements,
|
| 930 |
)
|
| 931 |
|
|
|
|
| 936 |
return (
|
| 937 |
f"LLM Overpass üretim hatası: {e}",
|
| 938 |
"<b>Overpass sonucu: LLM hatası.</b>",
|
| 939 |
+
previous_spatial or "Overpass sonucu: LLM hatası.",
|
| 940 |
previous_elements,
|
| 941 |
)
|
| 942 |
|
| 943 |
+
map_html, combined_spatial, all_elements = run_overpass_to_map(
|
| 944 |
+
query,
|
| 945 |
+
previous_elements,
|
| 946 |
+
previous_spatial,
|
| 947 |
+
)
|
| 948 |
+
|
| 949 |
+
# 4 output: üretilen query, harita, birikmiş spatial metin, birikmiş element listesi
|
| 950 |
+
return query, map_html, combined_spatial, all_elements
|
| 951 |
|
|
|
|
| 952 |
|
| 953 |
|
| 954 |
|
|
|
|
| 1336 |
# LLM ile üret + çalıştır (birikimli)
|
| 1337 |
gen_and_run_btn.click(
|
| 1338 |
fn=llm_overpass_to_map,
|
| 1339 |
+
inputs=[osm_nl_prompt, model_dropdown, overpass_elements_state, spatial_state],
|
| 1340 |
outputs=[overpass_box, map_html, spatial_state, overpass_elements_state],
|
| 1341 |
)
|
| 1342 |
+
|
| 1343 |
|
| 1344 |
# Manuel Overpass çalıştırma (birikimli)
|
| 1345 |
+
|
| 1346 |
run_overpass_btn.click(
|
| 1347 |
fn=run_overpass_to_map,
|
| 1348 |
inputs=[overpass_box, overpass_elements_state, spatial_state],
|