Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -658,7 +658,7 @@ def prepare_comparison(city1, district1, neigh1,city2, district2, neigh2):
|
|
| 658 |
# Harita HTML'i
|
| 659 |
map_html = create_comparison_map(gdf1, gdf2)
|
| 660 |
|
| 661 |
-
return stats1, stats2, compare_context, map_html
|
| 662 |
|
| 663 |
|
| 664 |
|
|
@@ -822,11 +822,15 @@ def create_comparison_map(gdf1, gdf2):
|
|
| 822 |
return m._repr_html_()
|
| 823 |
|
| 824 |
|
|
|
|
| 825 |
def run_overpass_to_map(query: str,
|
| 826 |
previous_elements: list | None,
|
| 827 |
previous_spatial: str | None,
|
| 828 |
layer_name: str = "Spatial Query",
|
| 829 |
-
layer_color: str = "
|
|
|
|
|
|
|
|
|
|
| 830 |
query = normalize_overpass_query(query) if 'normalize_overpass_query' in globals() else query
|
| 831 |
|
| 832 |
if not query or not query.strip():
|
|
@@ -881,10 +885,51 @@ def run_overpass_to_map(query: str,
|
|
| 881 |
previous_spatial or "Overpass sonucu: nokta verisi bulunamadı.",
|
| 882 |
all_elements,
|
| 883 |
)
|
|
|
|
| 884 |
|
| 885 |
# ---- Haritayı çiz ----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 886 |
m = folium.Map(location=[center_lat, center_lon], zoom_start=14)
|
| 887 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 888 |
# Burada tek bir "spatial" katman oluşturuyoruz
|
| 889 |
fg_nodes = folium.FeatureGroup(
|
| 890 |
name=f"{layer_name} - Noktalar", # katman adı
|
|
@@ -952,7 +997,10 @@ def run_overpass_to_map(query: str,
|
|
| 952 |
def llm_overpass_to_map(natural_prompt: str,
|
| 953 |
model_name: str,
|
| 954 |
previous_elements: list | None,
|
| 955 |
-
previous_spatial: str | None
|
|
|
|
|
|
|
|
|
|
| 956 |
if not natural_prompt or not natural_prompt.strip():
|
| 957 |
return (
|
| 958 |
"Doğal dil sorgu boş.",
|
|
@@ -976,8 +1024,9 @@ def llm_overpass_to_map(natural_prompt: str,
|
|
| 976 |
query,
|
| 977 |
previous_elements,
|
| 978 |
previous_spatial,
|
|
|
|
|
|
|
| 979 |
)
|
| 980 |
-
|
| 981 |
# 4 output: üretilen query, harita, birikmiş spatial metin, birikmiş element listesi
|
| 982 |
return query, map_html, combined_spatial, all_elements
|
| 983 |
|
|
@@ -1193,8 +1242,8 @@ with gr.Blocks() as demo:
|
|
| 1193 |
compare_state = gr.State("")
|
| 1194 |
spatial_state = gr.State("") # son Overpass özetleri
|
| 1195 |
overpass_elements_state = gr.State([]) # 👈 tüm Overpass sonuçlarını biriktireceğimiz liste
|
| 1196 |
-
|
| 1197 |
-
|
| 1198 |
|
| 1199 |
with gr.Row():
|
| 1200 |
# SOL SÜTUN: CHAT
|
|
@@ -1380,25 +1429,25 @@ with gr.Blocks() as demo:
|
|
| 1380 |
# LLM ile üret + çalıştır (birikimli)
|
| 1381 |
gen_and_run_btn.click(
|
| 1382 |
fn=llm_overpass_to_map,
|
| 1383 |
-
inputs=[osm_nl_prompt, model_dropdown, overpass_elements_state, spatial_state
|
|
|
|
| 1384 |
outputs=[overpass_box, map_html, spatial_state, overpass_elements_state],
|
| 1385 |
)
|
| 1386 |
-
|
| 1387 |
|
| 1388 |
# Manuel Overpass çalıştırma (birikimli)
|
| 1389 |
|
| 1390 |
run_overpass_btn.click(
|
| 1391 |
fn=run_overpass_to_map,
|
| 1392 |
-
inputs=[overpass_box, overpass_elements_state, spatial_state,
|
|
|
|
| 1393 |
outputs=[map_html, spatial_state, overpass_elements_state],
|
| 1394 |
)
|
| 1395 |
-
|
| 1396 |
compare_btn.click(
|
| 1397 |
fn=prepare_comparison,
|
| 1398 |
-
inputs=[city_in1, district1_in, neigh1_in,city_in1, district2_in, neigh2_in],
|
| 1399 |
-
outputs=[stats1_box, stats2_box, compare_state, map_html],
|
| 1400 |
)
|
| 1401 |
|
| 1402 |
-
|
| 1403 |
if __name__ == "__main__":
|
| 1404 |
demo.launch()
|
|
|
|
| 658 |
# Harita HTML'i
|
| 659 |
map_html = create_comparison_map(gdf1, gdf2)
|
| 660 |
|
| 661 |
+
return stats1, stats2, compare_context, map_html,gdf1, gdf2
|
| 662 |
|
| 663 |
|
| 664 |
|
|
|
|
| 822 |
return m._repr_html_()
|
| 823 |
|
| 824 |
|
| 825 |
+
|
| 826 |
def run_overpass_to_map(query: str,
|
| 827 |
previous_elements: list | None,
|
| 828 |
previous_spatial: str | None,
|
| 829 |
layer_name: str = "Spatial Query",
|
| 830 |
+
layer_color: str = "red",
|
| 831 |
+
base_gdf1=None,
|
| 832 |
+
base_gdf2=None):
|
| 833 |
+
|
| 834 |
query = normalize_overpass_query(query) if 'normalize_overpass_query' in globals() else query
|
| 835 |
|
| 836 |
if not query or not query.strip():
|
|
|
|
| 885 |
previous_spatial or "Overpass sonucu: nokta verisi bulunamadı.",
|
| 886 |
all_elements,
|
| 887 |
)
|
| 888 |
+
|
| 889 |
|
| 890 |
# ---- Haritayı çiz ----
|
| 891 |
+
# Önce merkez: mümkünse mahallelerden, yoksa Overpass noktalardan
|
| 892 |
+
if base_gdf1 is not None and len(base_gdf1) > 0:
|
| 893 |
+
c = base_gdf1.geometry.iloc[0].centroid
|
| 894 |
+
center_lat, center_lon = c.y, c.x
|
| 895 |
+
elif base_gdf2 is not None and len(base_gdf2) > 0:
|
| 896 |
+
c = base_gdf2.geometry.iloc[0].centroid
|
| 897 |
+
center_lat, center_lon = c.y, c.x
|
| 898 |
+
# (aksi halde yukarıda all_elements'tan zaten bulduk)
|
| 899 |
+
|
| 900 |
m = folium.Map(location=[center_lat, center_lon], zoom_start=14)
|
| 901 |
|
| 902 |
+
# 1. mahalleyi tekrar çiz
|
| 903 |
+
if base_gdf1 is not None and len(base_gdf1) > 0:
|
| 904 |
+
name1 = str(base_gdf1.get("neighborhood", ["Mahalle 1"]).iloc[0])
|
| 905 |
+
folium.GeoJson(
|
| 906 |
+
base_gdf1.geometry.__geo_interface__,
|
| 907 |
+
name=name1,
|
| 908 |
+
style_function=lambda feat: {
|
| 909 |
+
"color": "red",
|
| 910 |
+
"fill": False,
|
| 911 |
+
"weight": 3,
|
| 912 |
+
},
|
| 913 |
+
).add_to(m)
|
| 914 |
+
pois1 = get_pois_within(base_gdf1)
|
| 915 |
+
add_poi_markers_to_map(pois1, m, layer_prefix=f"{name1} POI")
|
| 916 |
+
|
| 917 |
+
# 2. mahalleyi tekrar çiz
|
| 918 |
+
if base_gdf2 is not None and len(base_gdf2) > 0:
|
| 919 |
+
name2 = str(base_gdf2.get("neighborhood", ["Mahalle 2"]).iloc[0])
|
| 920 |
+
folium.GeoJson(
|
| 921 |
+
base_gdf2.geometry.__geo_interface__,
|
| 922 |
+
name=name2,
|
| 923 |
+
style_function=lambda feat: {
|
| 924 |
+
"color": "blue",
|
| 925 |
+
"fill": False,
|
| 926 |
+
"weight": 3,
|
| 927 |
+
},
|
| 928 |
+
).add_to(m)
|
| 929 |
+
pois2 = get_pois_within(base_gdf2)
|
| 930 |
+
add_poi_markers_to_map(pois2, m, layer_prefix=f"{name2} POI")
|
| 931 |
+
|
| 932 |
+
|
| 933 |
# Burada tek bir "spatial" katman oluşturuyoruz
|
| 934 |
fg_nodes = folium.FeatureGroup(
|
| 935 |
name=f"{layer_name} - Noktalar", # katman adı
|
|
|
|
| 997 |
def llm_overpass_to_map(natural_prompt: str,
|
| 998 |
model_name: str,
|
| 999 |
previous_elements: list | None,
|
| 1000 |
+
previous_spatial: str | None,
|
| 1001 |
+
base_gdf1=None,
|
| 1002 |
+
base_gdf2=None):
|
| 1003 |
+
|
| 1004 |
if not natural_prompt or not natural_prompt.strip():
|
| 1005 |
return (
|
| 1006 |
"Doğal dil sorgu boş.",
|
|
|
|
| 1024 |
query,
|
| 1025 |
previous_elements,
|
| 1026 |
previous_spatial,
|
| 1027 |
+
base_gdf1=base_gdf1,
|
| 1028 |
+
base_gdf2=base_gdf2,
|
| 1029 |
)
|
|
|
|
| 1030 |
# 4 output: üretilen query, harita, birikmiş spatial metin, birikmiş element listesi
|
| 1031 |
return query, map_html, combined_spatial, all_elements
|
| 1032 |
|
|
|
|
| 1242 |
compare_state = gr.State("")
|
| 1243 |
spatial_state = gr.State("") # son Overpass özetleri
|
| 1244 |
overpass_elements_state = gr.State([]) # 👈 tüm Overpass sonuçlarını biriktireceğimiz liste
|
| 1245 |
+
gdf1_state = gr.State(None) # 1. mahalle geometri
|
| 1246 |
+
gdf2_state = gr.State(None) # 2. mahalle geometri
|
| 1247 |
|
| 1248 |
with gr.Row():
|
| 1249 |
# SOL SÜTUN: CHAT
|
|
|
|
| 1429 |
# LLM ile üret + çalıştır (birikimli)
|
| 1430 |
gen_and_run_btn.click(
|
| 1431 |
fn=llm_overpass_to_map,
|
| 1432 |
+
inputs=[osm_nl_prompt, model_dropdown, overpass_elements_state, spatial_state,
|
| 1433 |
+
gdf1_state, gdf2_state],
|
| 1434 |
outputs=[overpass_box, map_html, spatial_state, overpass_elements_state],
|
| 1435 |
)
|
|
|
|
| 1436 |
|
| 1437 |
# Manuel Overpass çalıştırma (birikimli)
|
| 1438 |
|
| 1439 |
run_overpass_btn.click(
|
| 1440 |
fn=run_overpass_to_map,
|
| 1441 |
+
inputs=[overpass_box, overpass_elements_state, spatial_state,
|
| 1442 |
+
layer_color_dd, gdf1_state, gdf2_state],
|
| 1443 |
outputs=[map_html, spatial_state, overpass_elements_state],
|
| 1444 |
)
|
| 1445 |
+
|
| 1446 |
compare_btn.click(
|
| 1447 |
fn=prepare_comparison,
|
| 1448 |
+
inputs=[city_in1, district1_in, neigh1_in, city_in1, district2_in, neigh2_in],
|
| 1449 |
+
outputs=[stats1_box, stats2_box, compare_state, map_html, gdf1_state, gdf2_state],
|
| 1450 |
)
|
| 1451 |
|
|
|
|
| 1452 |
if __name__ == "__main__":
|
| 1453 |
demo.launch()
|