File size: 3,910 Bytes
6cf275c
 
1c24b61
 
58201bc
1c24b61
 
58201bc
1c24b61
 
 
 
 
 
 
 
 
 
 
 
 
58201bc
 
 
 
 
 
1c24b61
58201bc
 
1c24b61
 
 
 
58201bc
1c24b61
 
 
 
 
 
1474320
 
 
 
 
 
58201bc
1c24b61
 
58201bc
1c24b61
 
 
 
58201bc
1c24b61
1474320
 
 
 
58201bc
1474320
 
58201bc
1c24b61
 
 
 
 
 
 
58201bc
1c24b61
1474320
1c24b61
1474320
1c24b61
 
 
1474320
1c24b61
 
 
 
 
 
 
 
58201bc
 
1c24b61
 
 
 
 
 
 
 
1474320
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import streamlit as st
import requests
import pandas as pd

# Set up Streamlit page
st.set_page_config(page_title="🌍 Geospatial Querying System", page_icon="πŸ“", layout="wide")

# Custom Styling
st.markdown("""
    <style>
        .stButton > button {
            background-color: #ff5a5f;
            color: white;
            font-size: 16px;
            border-radius: 10px;
        }
    </style>
""", unsafe_allow_html=True)

# Title & Instructions
st.title("πŸ“ Geospatial Querying System")
st.write("🌍 **Enter any query like:**")
st.markdown("""
- `"Find hospitals in Delhi"`
- `"Show malls near Bangalore"`
- `"Where are the police stations in Mumbai?"`
""")

# User input
query = st.text_input("πŸ” Enter your query (e.g., 'Find restaurants in Mumbai'):")

# Buttons
col1, col2 = st.columns(2)
with col1:
    find_location = st.button("πŸ“ Find Location & Category")
with col2:
    find_nearby = st.button("πŸ”Ž Find Nearby Places")

# Backend API URLs
BASE_URL = "https://geospatial-api.onrender.com"

# Global variables to store extracted data
if "location" not in st.session_state:
    st.session_state["location"] = None
if "category" not in st.session_state:
    st.session_state["category"] = None

# Step 1: Extract location & category from query
if find_location:
    if query:
        with st.spinner("πŸ” Extracting location & category..."):
            response = requests.post(f"{BASE_URL}/query", json={"text": query})
            data = response.json()
        
        if "error" in data:
            st.error("❌ Could not extract location. Try again!")
        else:
            # Store extracted data in session state
            st.session_state["location"] = data["place"]
            st.session_state["category"] = data["category"]

            # Display extracted information
            st.success(f"βœ… **Extracted Location:** `{data['place']}`")
            st.success(f"πŸ“Œ **Extracted Category:** `{data['category']}`")
            
            st.write(f"🌍 **Latitude:** `{data['latitude']}`")
            st.write(f"🌍 **Longitude:** `{data['longitude']}`")

            # Google Maps Link
            maps_link = f"https://www.google.com/maps/search/?api=1&query={data['latitude']},{data['longitude']}"
            st.markdown(f"[πŸ“ View on Google Maps]({maps_link})", unsafe_allow_html=True)

# Step 2: Find Nearby Places
if find_nearby:
    if st.session_state["location"] and st.session_state["category"]:
        with st.spinner("πŸ”Ž Searching for nearby places..."):
            response = requests.post(f"{BASE_URL}/nearby", json={"place": st.session_state["location"], "category": st.session_state["category"]})
            data = response.json()

        if "nearby_places" in data and data["nearby_places"]:
            st.success(f"βœ… **Nearby {st.session_state['category']} found in {st.session_state['location']}:**")
            
            # Show Places in a Table
            places_df = pd.DataFrame(data["nearby_places"])
            places_df = places_df.rename(columns={"name": "Place Name", "lat": "Latitude", "lon": "Longitude"})
            st.dataframe(places_df)

            # Show Google Maps Links
            for place in data["nearby_places"]:
                maps_link = f"https://www.google.com/maps/search/?api=1&query={place['lat']},{place['lon']}"
                st.markdown(f"πŸ“ **{place['name']}** [πŸ”— View on Maps]({maps_link})", unsafe_allow_html=True)

            # Show on Interactive Map
            map_data = pd.DataFrame({
                "lat": [p["lat"] for p in data["nearby_places"]],
                "lon": [p["lon"] for p in data["nearby_places"]]
            })
            st.map(map_data)
        else:
            st.error("❌ No places found in the selected category.")
    else:
        st.error("❌ Please extract location & category first by clicking 'Find Location & Category'.")