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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import plotly.express as px
|
5 |
+
import plotly.graph_objects as go
|
6 |
+
from datetime import datetime, timedelta
|
7 |
+
import folium
|
8 |
+
from streamlit_folium import st_folium
|
9 |
+
import requests
|
10 |
+
from geopy.distance import geodesic
|
11 |
+
import time
|
12 |
+
|
13 |
+
# Page configuration
|
14 |
+
st.set_page_config(
|
15 |
+
page_title="AI City Companion",
|
16 |
+
page_icon="π",
|
17 |
+
layout="wide",
|
18 |
+
initial_sidebar_state="expanded"
|
19 |
+
)
|
20 |
+
|
21 |
+
# Custom CSS for modern styling
|
22 |
+
st.markdown("""
|
23 |
+
<style>
|
24 |
+
.main-header {
|
25 |
+
font-size: 3rem;
|
26 |
+
font-weight: bold;
|
27 |
+
text-align: center;
|
28 |
+
background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
|
29 |
+
-webkit-background-clip: text;
|
30 |
+
-webkit-text-fill-color: transparent;
|
31 |
+
margin-bottom: 2rem;
|
32 |
+
}
|
33 |
+
|
34 |
+
.feature-card {
|
35 |
+
background: white;
|
36 |
+
padding: 1.5rem;
|
37 |
+
border-radius: 10px;
|
38 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
39 |
+
margin: 1rem 0;
|
40 |
+
border-left: 4px solid #667eea;
|
41 |
+
}
|
42 |
+
|
43 |
+
.emergency-alert {
|
44 |
+
background: #fee2e2;
|
45 |
+
border: 1px solid #fecaca;
|
46 |
+
border-radius: 8px;
|
47 |
+
padding: 1rem;
|
48 |
+
margin: 1rem 0;
|
49 |
+
color: #991b1b;
|
50 |
+
}
|
51 |
+
|
52 |
+
.success-alert {
|
53 |
+
background: #dcfce7;
|
54 |
+
border: 1px solid #bbf7d0;
|
55 |
+
border-radius: 8px;
|
56 |
+
padding: 1rem;
|
57 |
+
margin: 1rem 0;
|
58 |
+
color: #166534;
|
59 |
+
}
|
60 |
+
|
61 |
+
.metric-card {
|
62 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
63 |
+
color: white;
|
64 |
+
padding: 1rem;
|
65 |
+
border-radius: 10px;
|
66 |
+
text-align: center;
|
67 |
+
margin: 0.5rem;
|
68 |
+
}
|
69 |
+
</style>
|
70 |
+
""", unsafe_allow_html=True)
|
71 |
+
|
72 |
+
# Initialize session state
|
73 |
+
if 'user_location' not in st.session_state:
|
74 |
+
st.session_state.user_location = [24.8607, 67.0011] # Karachi, Pakistan
|
75 |
+
if 'user_preferences' not in st.session_state:
|
76 |
+
st.session_state.user_preferences = {}
|
77 |
+
if 'search_history' not in st.session_state:
|
78 |
+
st.session_state.search_history = []
|
79 |
+
if 'current_itinerary' not in st.session_state:
|
80 |
+
st.session_state.current_itinerary = []
|
81 |
+
|
82 |
+
# Mock data for demonstration
|
83 |
+
@st.cache_data
|
84 |
+
def load_mock_data():
|
85 |
+
# Healthcare & Emergency
|
86 |
+
healthcare_data = pd.DataFrame({
|
87 |
+
'name': ['City Hospital', 'Emergency Clinic 24/7', 'Al-Shifa Medical Center', 'Quick Care Pharmacy', 'Blood Bank Center'],
|
88 |
+
'category': ['Hospital', 'Clinic', 'Hospital', 'Pharmacy', 'Blood Bank'],
|
89 |
+
'lat': [24.8615, 24.8590, 24.8625, 24.8580, 24.8635],
|
90 |
+
'lon': [67.0020, 67.0000, 67.0040, 66.9990, 67.0050],
|
91 |
+
'rating': [4.5, 4.2, 4.7, 4.0, 4.3],
|
92 |
+
'distance': [0.5, 0.8, 0.3, 1.2, 0.7],
|
93 |
+
'phone': ['+92-21-111-222', '+92-21-333-444', '+92-21-555-666', '+92-21-777-888', '+92-21-999-000'],
|
94 |
+
'open_24h': [True, True, False, False, True]
|
95 |
+
})
|
96 |
+
|
97 |
+
# Food & Restaurants
|
98 |
+
food_data = pd.DataFrame({
|
99 |
+
'name': ['Halal Biryani House', 'Vegetarian Delight', 'Quick Bites Cafe', 'Traditional Karahi', 'Fresh Juice Corner'],
|
100 |
+
'category': ['Pakistani', 'Vegetarian', 'Fast Food', 'Pakistani', 'Beverages'],
|
101 |
+
'lat': [24.8600, 24.8620, 24.8585, 24.8640, 24.8575],
|
102 |
+
'lon': [67.0015, 67.0035, 66.9995, 67.0055, 66.9985],
|
103 |
+
'rating': [4.6, 4.3, 4.1, 4.8, 4.2],
|
104 |
+
'price_range': ['$$', '$', '$', '$$$', '$'],
|
105 |
+
'dietary': ['Halal', 'Vegetarian', 'Mixed', 'Halal', 'Vegan'],
|
106 |
+
'crowd_level': ['Medium', 'Low', 'High', 'Medium', 'Low'],
|
107 |
+
'noise_level': ['Medium', 'Low', 'High', 'Medium', 'Low']
|
108 |
+
})
|
109 |
+
|
110 |
+
# Electronics & Repairs
|
111 |
+
electronics_data = pd.DataFrame({
|
112 |
+
'name': ['TechMart Electronics', 'Mobile Repair Hub', 'Laptop Service Center', 'Gadget World', 'SIM Card Center'],
|
113 |
+
'category': ['Electronics Store', 'Repair Shop', 'Repair Shop', 'Electronics Store', 'Telecom'],
|
114 |
+
'lat': [24.8610, 24.8595, 24.8630, 24.8570, 24.8645],
|
115 |
+
'lon': [67.0025, 67.0005, 67.0045, 66.9980, 67.0060],
|
116 |
+
'rating': [4.4, 4.1, 4.5, 4.3, 4.0],
|
117 |
+
'services': ['Phones, Laptops, Accessories', 'Phone Repair', 'Laptop Repair', 'All Electronics', 'SIM Cards, Top-up'],
|
118 |
+
'price_fair': [True, True, False, True, True]
|
119 |
+
})
|
120 |
+
|
121 |
+
# Attractions & Places
|
122 |
+
attractions_data = pd.DataFrame({
|
123 |
+
'name': ['Clifton Beach', 'Quaid Mausoleum', 'Empress Market', 'Karachi Zoo', 'Port Grand'],
|
124 |
+
'category': ['Beach', 'Monument', 'Market', 'Zoo', 'Entertainment'],
|
125 |
+
'lat': [24.8138, 24.8738, 24.8615, 24.9056, 24.8406],
|
126 |
+
'lon': [67.0299, 67.0362, 67.0099, 67.0516, 67.0219],
|
127 |
+
'rating': [4.2, 4.7, 4.0, 3.8, 4.1],
|
128 |
+
'best_time': ['Evening', 'Morning', 'Morning', 'Morning', 'Evening'],
|
129 |
+
'crowd_level': ['High', 'Medium', 'High', 'Medium', 'Medium'],
|
130 |
+
'entry_fee': [0, 0, 0, 50, 0]
|
131 |
+
})
|
132 |
+
|
133 |
+
return healthcare_data, food_data, electronics_data, attractions_data
|
134 |
+
|
135 |
+
# Load data
|
136 |
+
healthcare_df, food_df, electronics_df, attractions_df = load_mock_data()
|
137 |
+
|
138 |
+
# Helper functions
|
139 |
+
def calculate_distance(lat1, lon1, lat2, lon2):
|
140 |
+
return geodesic((lat1, lon1), (lat2, lon2)).kilometers
|
141 |
+
|
142 |
+
def get_recommendations(category, user_prefs=None):
|
143 |
+
if category == "healthcare":
|
144 |
+
return healthcare_df.sort_values('rating', ascending=False)
|
145 |
+
elif category == "food":
|
146 |
+
df = food_df.copy()
|
147 |
+
if user_prefs and 'dietary' in user_prefs:
|
148 |
+
df = df[df['dietary'].str.contains(user_prefs['dietary'], case=False, na=False)]
|
149 |
+
if user_prefs and 'crowd_preference' in user_prefs:
|
150 |
+
if user_prefs['crowd_preference'] == 'Low':
|
151 |
+
df = df[df['crowd_level'] == 'Low']
|
152 |
+
return df.sort_values('rating', ascending=False)
|
153 |
+
elif category == "electronics":
|
154 |
+
return electronics_df.sort_values('rating', ascending=False)
|
155 |
+
elif category == "attractions":
|
156 |
+
return attractions_df.sort_values('rating', ascending=False)
|
157 |
+
|
158 |
+
def create_map(data_df, center_lat, center_lon):
|
159 |
+
m = folium.Map(location=[center_lat, center_lon], zoom_start=13)
|
160 |
+
|
161 |
+
# Add user location
|
162 |
+
folium.Marker(
|
163 |
+
[center_lat, center_lon],
|
164 |
+
popup="Your Location",
|
165 |
+
icon=folium.Icon(color='red', icon='user')
|
166 |
+
).add_to(m)
|
167 |
+
|
168 |
+
# Add points of interest
|
169 |
+
colors = {'Hospital': 'green', 'Clinic': 'blue', 'Pharmacy': 'orange',
|
170 |
+
'Pakistani': 'red', 'Vegetarian': 'green', 'Fast Food': 'orange',
|
171 |
+
'Electronics Store': 'purple', 'Repair Shop': 'darkblue',
|
172 |
+
'Beach': 'lightblue', 'Monument': 'gray', 'Market': 'orange'}
|
173 |
+
|
174 |
+
for idx, row in data_df.iterrows():
|
175 |
+
color = colors.get(row.get('category', 'Unknown'), 'gray')
|
176 |
+
folium.Marker(
|
177 |
+
[row['lat'], row['lon']],
|
178 |
+
popup=f"<b>{row['name']}</b><br>Rating: {row.get('rating', 'N/A')}<br>Category: {row.get('category', 'N/A')}",
|
179 |
+
icon=folium.Icon(color=color)
|
180 |
+
).add_to(m)
|
181 |
+
|
182 |
+
return m
|
183 |
+
|
184 |
+
# Main App
|
185 |
+
def main():
|
186 |
+
# Header
|
187 |
+
st.markdown('<h1 class="main-header">π AI City Companion</h1>', unsafe_allow_html=True)
|
188 |
+
st.markdown('<p style="text-align: center; font-size: 1.2rem; color: #666;">Your Smart Travel Guide for Safe & Smart City Navigation</p>', unsafe_allow_html=True)
|
189 |
+
|
190 |
+
# Sidebar for user preferences
|
191 |
+
with st.sidebar:
|
192 |
+
st.header("π― Your Preferences")
|
193 |
+
|
194 |
+
# Location input
|
195 |
+
st.subheader("π Current Location")
|
196 |
+
col1, col2 = st.columns(2)
|
197 |
+
with col1:
|
198 |
+
user_lat = st.number_input("Latitude", value=24.8607, format="%.4f")
|
199 |
+
with col2:
|
200 |
+
user_lon = st.number_input("Longitude", value=67.0011, format="%.4f")
|
201 |
+
|
202 |
+
st.session_state.user_location = [user_lat, user_lon]
|
203 |
+
|
204 |
+
# Personal preferences
|
205 |
+
st.subheader("π€ Personal Preferences")
|
206 |
+
dietary_pref = st.selectbox("Dietary Preference", ["Any", "Halal", "Vegetarian", "Vegan"])
|
207 |
+
crowd_pref = st.selectbox("Crowd Preference", ["Any", "Low", "Medium", "High"])
|
208 |
+
budget_pref = st.selectbox("Budget Range", ["Any", "$", "$$", "$$$"])
|
209 |
+
|
210 |
+
st.session_state.user_preferences = {
|
211 |
+
'dietary': dietary_pref,
|
212 |
+
'crowd_preference': crowd_pref,
|
213 |
+
'budget': budget_pref
|
214 |
+
}
|
215 |
+
|
216 |
+
# Emergency contacts
|
217 |
+
st.subheader("π¨ Quick Emergency")
|
218 |
+
if st.button("π₯ Nearest Hospital", use_container_width=True):
|
219 |
+
st.session_state.emergency_mode = True
|
220 |
+
if st.button("π Police Station", use_container_width=True):
|
221 |
+
st.info("Emergency: 15 (Police)")
|
222 |
+
if st.button("π Ambulance", use_container_width=True):
|
223 |
+
st.info("Emergency: 1122 (Rescue)")
|
224 |
+
|
225 |
+
# Main content tabs
|
226 |
+
tab1, tab2, tab3, tab4, tab5 = st.tabs(["πΊοΈ Smart Map", "π AI Search", "π Itinerary Builder", "π City Insights", "βοΈ Settings"])
|
227 |
+
|
228 |
+
with tab1:
|
229 |
+
st.header("πΊοΈ Smart Contextual City Map")
|
230 |
+
|
231 |
+
# Map controls
|
232 |
+
col1, col2, col3, col4 = st.columns(4)
|
233 |
+
with col1:
|
234 |
+
map_category = st.selectbox("Show Category", ["All", "Healthcare", "Food", "Electronics", "Attractions"])
|
235 |
+
with col2:
|
236 |
+
time_filter = st.selectbox("Time Filter", ["Current", "Morning", "Afternoon", "Evening", "Night"])
|
237 |
+
with col3:
|
238 |
+
radius_km = st.slider("Search Radius (km)", 0.5, 10.0, 2.0)
|
239 |
+
with col4:
|
240 |
+
show_traffic = st.checkbox("Show Traffic Info")
|
241 |
+
|
242 |
+
# Create and display map
|
243 |
+
if map_category == "All":
|
244 |
+
all_data = pd.concat([healthcare_df, food_df, electronics_df, attractions_df], ignore_index=True)
|
245 |
+
elif map_category == "Healthcare":
|
246 |
+
all_data = healthcare_df
|
247 |
+
elif map_category == "Food":
|
248 |
+
all_data = get_recommendations("food", st.session_state.user_preferences)
|
249 |
+
elif map_category == "Electronics":
|
250 |
+
all_data = electronics_df
|
251 |
+
elif map_category == "Attractions":
|
252 |
+
all_data = attractions_df
|
253 |
+
|
254 |
+
# Filter by radius
|
255 |
+
all_data['distance_calc'] = all_data.apply(
|
256 |
+
lambda row: calculate_distance(user_lat, user_lon, row['lat'], row['lon']), axis=1
|
257 |
+
)
|
258 |
+
filtered_data = all_data[all_data['distance_calc'] <= radius_km]
|
259 |
+
|
260 |
+
if not filtered_data.empty:
|
261 |
+
map_obj = create_map(filtered_data, user_lat, user_lon)
|
262 |
+
st_folium(map_obj, width=700, height=500)
|
263 |
+
|
264 |
+
# Show nearby places
|
265 |
+
st.subheader(f"π Nearby Places ({len(filtered_data)} found)")
|
266 |
+
for idx, row in filtered_data.head(5).iterrows():
|
267 |
+
with st.expander(f"{row['name']} - {row.get('category', 'Unknown')} ({row['distance_calc']:.1f}km)"):
|
268 |
+
col1, col2 = st.columns(2)
|
269 |
+
with col1:
|
270 |
+
st.write(f"β Rating: {row.get('rating', 'N/A')}")
|
271 |
+
st.write(f"π Phone: {row.get('phone', 'N/A')}")
|
272 |
+
with col2:
|
273 |
+
if 'services' in row:
|
274 |
+
st.write(f"π§ Services: {row['services']}")
|
275 |
+
if 'dietary' in row:
|
276 |
+
st.write(f"π½οΈ Dietary: {row['dietary']}")
|
277 |
+
else:
|
278 |
+
st.warning("No places found in the selected radius. Try increasing the search area.")
|
279 |
+
|
280 |
+
with tab2:
|
281 |
+
st.header("π AI-Powered Smart Search")
|
282 |
+
|
283 |
+
# Multi-modal search
|
284 |
+
search_type = st.radio("Search Type", ["Text Query", "Voice Command (Simulated)", "Image Upload (Simulated)"])
|
285 |
+
|
286 |
+
if search_type == "Text Query":
|
287 |
+
query = st.text_input("Ask me anything about the city:",
|
288 |
+
placeholder="e.g., 'Find halal biryani that's not crowded' or 'Where can I fix my laptop?'")
|
289 |
+
|
290 |
+
if query:
|
291 |
+
st.session_state.search_history.append({"query": query, "timestamp": datetime.now()})
|
292 |
+
|
293 |
+
# Simple AI simulation
|
294 |
+
results = []
|
295 |
+
query_lower = query.lower()
|
296 |
+
|
297 |
+
if any(word in query_lower for word in ['hospital', 'doctor', 'medical', 'emergency']):
|
298 |
+
results = healthcare_df.head(3).to_dict('records')
|
299 |
+
st.success("π₯ Found healthcare facilities for you!")
|
300 |
+
elif any(word in query_lower for word in ['food', 'eat', 'restaurant', 'biryani', 'halal']):
|
301 |
+
results = get_recommendations("food", st.session_state.user_preferences).head(3).to_dict('records')
|
302 |
+
st.success("π½οΈ Found great food options!")
|
303 |
+
elif any(word in query_lower for word in ['laptop', 'phone', 'repair', 'electronics', 'charger']):
|
304 |
+
results = electronics_df.head(3).to_dict('records')
|
305 |
+
st.success("π§ Found electronics and repair services!")
|
306 |
+
elif any(word in query_lower for word in ['visit', 'see', 'attraction', 'tourist']):
|
307 |
+
results = attractions_df.head(3).to_dict('records')
|
308 |
+
st.success("π― Found amazing places to visit!")
|
309 |
+
else:
|
310 |
+
st.info("π€ I'm learning! Try asking about healthcare, food, electronics, or attractions.")
|
311 |
+
|
312 |
+
# Display results
|
313 |
+
if results:
|
314 |
+
for result in results:
|
315 |
+
with st.container():
|
316 |
+
st.markdown(f"""
|
317 |
+
<div class="feature-card">
|
318 |
+
<h4>{result['name']}</h4>
|
319 |
+
<p><strong>Category:</strong> {result.get('category', 'N/A')}</p>
|
320 |
+
<p><strong>Rating:</strong> β {result.get('rating', 'N/A')}</p>
|
321 |
+
<p><strong>Distance:</strong> {result.get('distance', calculate_distance(user_lat, user_lon, result['lat'], result['lon'])):.1f} km</p>
|
322 |
+
</div>
|
323 |
+
""", unsafe_allow_html=True)
|
324 |
+
|
325 |
+
elif search_type == "Voice Command (Simulated)":
|
326 |
+
st.info("π€ Voice search simulation - Click to 'speak'")
|
327 |
+
if st.button("ποΈ Start Voice Search"):
|
328 |
+
with st.spinner("Listening..."):
|
329 |
+
time.sleep(2)
|
330 |
+
st.success("Voice recognized: 'Find nearest pharmacy'")
|
331 |
+
results = healthcare_df[healthcare_df['category'] == 'Pharmacy']
|
332 |
+
for idx, row in results.iterrows():
|
333 |
+
st.write(f"π {row['name']} - {row['distance']}km away")
|
334 |
+
|
335 |
+
else: # Image Upload
|
336 |
+
st.info("πΈ Image search simulation")
|
337 |
+
uploaded_file = st.file_uploader("Upload an image of what you're looking for", type=['jpg', 'jpeg', 'png'])
|
338 |
+
if uploaded_file:
|
339 |
+
st.image(uploaded_file, caption="Analyzing image...", width=300)
|
340 |
+
with st.spinner("AI analyzing image..."):
|
341 |
+
time.sleep(2)
|
342 |
+
st.success("π Detected: Broken phone charger")
|
343 |
+
st.write("Found electronics repair shops nearby:")
|
344 |
+
repair_shops = electronics_df[electronics_df['category'] == 'Repair Shop']
|
345 |
+
for idx, row in repair_shops.iterrows():
|
346 |
+
st.write(f"π§ {row['name']} - {row['services']}")
|
347 |
+
|
348 |
+
with tab3:
|
349 |
+
st.header("π Smart Itinerary Builder")
|
350 |
+
|
351 |
+
# Itinerary preferences
|
352 |
+
st.subheader("π― Tell me about your day")
|
353 |
+
col1, col2 = st.columns(2)
|
354 |
+
|
355 |
+
with col1:
|
356 |
+
duration = st.selectbox("Trip Duration", ["Half Day (4 hours)", "Full Day (8 hours)", "Weekend (2 days)"])
|
357 |
+
walking_pref = st.selectbox("Walking Preference", ["Minimal walking", "Moderate walking", "Lots of walking"])
|
358 |
+
interests = st.multiselect("Interests", ["Food", "Shopping", "Culture", "Nature", "Technology", "Healthcare"])
|
359 |
+
|
360 |
+
with col2:
|
361 |
+
budget = st.selectbox("Budget Range", ["Budget ($)", "Mid-range ($$)", "Premium ($$$)"])
|
362 |
+
group_size = st.number_input("Group Size", min_value=1, max_value=10, value=1)
|
363 |
+
special_needs = st.multiselect("Special Requirements", ["Wheelchair accessible", "Halal food only", "Quiet places", "Female-friendly"])
|
364 |
+
|
365 |
+
if st.button("π Generate Smart Itinerary", use_container_width=True):
|
366 |
+
with st.spinner("AI is crafting your perfect day..."):
|
367 |
+
time.sleep(3)
|
368 |
+
|
369 |
+
# Generate sample itinerary
|
370 |
+
itinerary = [
|
371 |
+
{"time": "09:00 AM", "activity": "Breakfast at Halal Biryani House", "duration": "1 hour", "type": "food"},
|
372 |
+
{"time": "10:30 AM", "activity": "Visit Quaid Mausoleum", "duration": "1.5 hours", "type": "culture"},
|
373 |
+
{"time": "12:30 PM", "activity": "Electronics shopping at TechMart", "duration": "1 hour", "type": "shopping"},
|
374 |
+
{"time": "02:00 PM", "activity": "Lunch at Traditional Karahi", "duration": "1 hour", "type": "food"},
|
375 |
+
{"time": "04:00 PM", "activity": "Relax at Clifton Beach", "duration": "2 hours", "type": "nature"},
|
376 |
+
{"time": "06:30 PM", "activity": "Dinner at Port Grand", "duration": "1.5 hours", "type": "food"}
|
377 |
+
]
|
378 |
+
|
379 |
+
st.session_state.current_itinerary = itinerary
|
380 |
+
|
381 |
+
st.success("β
Your personalized itinerary is ready!")
|
382 |
+
|
383 |
+
# Display itinerary
|
384 |
+
for i, item in enumerate(itinerary):
|
385 |
+
with st.expander(f"{item['time']} - {item['activity']} ({item['duration']})"):
|
386 |
+
col1, col2, col3 = st.columns(3)
|
387 |
+
with col1:
|
388 |
+
st.write(f"β° Duration: {item['duration']}")
|
389 |
+
with col2:
|
390 |
+
st.write(f"π·οΈ Type: {item['type'].title()}")
|
391 |
+
with col3:
|
392 |
+
if st.button(f"Get Directions", key=f"dir_{i}"):
|
393 |
+
st.info("πΊοΈ Opening navigation...")
|
394 |
+
|
395 |
+
# Itinerary summary
|
396 |
+
st.subheader("π Itinerary Summary")
|
397 |
+
col1, col2, col3, col4 = st.columns(4)
|
398 |
+
with col1:
|
399 |
+
st.markdown('<div class="metric-card"><h3>6</h3><p>Total Stops</p></div>', unsafe_allow_html=True)
|
400 |
+
with col2:
|
401 |
+
st.markdown('<div class="metric-card"><h3>8.5h</h3><p>Total Duration</p></div>', unsafe_allow_html=True)
|
402 |
+
with col3:
|
403 |
+
st.markdown('<div class="metric-card"><h3>5.2km</h3><p>Total Distance</p></div>', unsafe_allow_html=True)
|
404 |
+
with col4:
|
405 |
+
st.markdown('<div class="metric-card"><h3>$$</h3><p>Est. Budget</p></div>', unsafe_allow_html=True)
|
406 |
+
|
407 |
+
with tab4:
|
408 |
+
st.header("π City Insights & Analytics")
|
409 |
+
|
410 |
+
# Real-time city stats
|
411 |
+
col1, col2, col3, col4 = st.columns(4)
|
412 |
+
with col1:
|
413 |
+
st.metric("π‘οΈ Temperature", "28Β°C", "2Β°C")
|
414 |
+
with col2:
|
415 |
+
st.metric("π¦ Traffic Level", "Medium", "β 15%")
|
416 |
+
with col3:
|
417 |
+
st.metric("π₯ Crowd Density", "Low", "β 5%")
|
418 |
+
with col4:
|
419 |
+
st.metric("π° Price Index", "Moderate", "β 2%")
|
420 |
+
|
421 |
+
# Charts and analytics
|
422 |
+
col1, col2 = st.columns(2)
|
423 |
+
|
424 |
+
with col1:
|
425 |
+
st.subheader("π Popular Categories")
|
426 |
+
category_data = pd.DataFrame({
|
427 |
+
'Category': ['Food', 'Healthcare', 'Electronics', 'Attractions', 'Shopping'],
|
428 |
+
'Searches': [45, 23, 18, 32, 28]
|
429 |
+
})
|
430 |
+
fig = px.bar(category_data, x='Category', y='Searches',
|
431 |
+
title="Most Searched Categories Today")
|
432 |
+
st.plotly_chart(fig, use_container_width=True)
|
433 |
+
|
434 |
+
with col2:
|
435 |
+
st.subheader("β° Best Times to Visit")
|
436 |
+
time_data = pd.DataFrame({
|
437 |
+
'Hour': list(range(6, 23)),
|
438 |
+
'Crowd_Level': [20, 30, 45, 60, 70, 85, 90, 95, 80, 70, 60, 50, 45, 55, 70, 85, 90]
|
439 |
+
})
|
440 |
+
fig = px.line(time_data, x='Hour', y='Crowd_Level',
|
441 |
+
title="Crowd Levels Throughout the Day")
|
442 |
+
st.plotly_chart(fig, use_container_width=True)
|
443 |
+
|
444 |
+
# Safety alerts
|
445 |
+
st.subheader("π‘οΈ Safety & Alerts")
|
446 |
+
alerts = [
|
447 |
+
{"type": "warning", "message": "Heavy traffic on Shahrah-e-Faisal (avoid 5-7 PM)"},
|
448 |
+
{"type": "info", "message": "New electronics market opened in Saddar"},
|
449 |
+
{"type": "success", "message": "All hospitals report normal capacity"},
|
450 |
+
]
|
451 |
+
|
452 |
+
for alert in alerts:
|
453 |
+
if alert["type"] == "warning":
|
454 |
+
st.warning(f"β οΈ {alert['message']}")
|
455 |
+
elif alert["type"] == "info":
|
456 |
+
st.info(f"βΉοΈ {alert['message']}")
|
457 |
+
else:
|
458 |
+
st.success(f"β
{alert['message']}")
|
459 |
+
|
460 |
+
with tab5:
|
461 |
+
st.header("βοΈ Settings & Preferences")
|
462 |
+
|
463 |
+
col1, col2 = st.columns(2)
|
464 |
+
|
465 |
+
with col1:
|
466 |
+
st.subheader("π Notifications")
|
467 |
+
st.checkbox("Emergency alerts", value=True)
|
468 |
+
st.checkbox("Traffic updates", value=True)
|
469 |
+
st.checkbox("Price alerts", value=False)
|
470 |
+
st.checkbox("New place recommendations", value=True)
|
471 |
+
|
472 |
+
st.subheader("π Language & Region")
|
473 |
+
language = st.selectbox("Language", ["English", "Urdu", "Arabic"])
|
474 |
+
currency = st.selectbox("Currency", ["PKR", "USD", "EUR"])
|
475 |
+
|
476 |
+
with col2:
|
477 |
+
st.subheader("π Privacy & Safety")
|
478 |
+
st.checkbox("Share location for better recommendations", value=True)
|
479 |
+
st.checkbox("Save search history", value=True)
|
480 |
+
st.checkbox("Anonymous usage analytics", value=False)
|
481 |
+
|
482 |
+
st.subheader("π± App Preferences")
|
483 |
+
theme = st.selectbox("Theme", ["Auto", "Light", "Dark"])
|
484 |
+
map_style = st.selectbox("Map Style", ["Standard", "Satellite", "Terrain"])
|
485 |
+
|
486 |
+
# Export data
|
487 |
+
st.subheader("π€ Export Your Data")
|
488 |
+
if st.button("Download Search History"):
|
489 |
+
if st.session_state.search_history:
|
490 |
+
df = pd.DataFrame(st.session_state.search_history)
|
491 |
+
st.download_button(
|
492 |
+
label="π₯ Download CSV",
|
493 |
+
data=df.to_csv(index=False),
|
494 |
+
file_name="search_history.csv",
|
495 |
+
mime="text/csv"
|
496 |
+
)
|
497 |
+
else:
|
498 |
+
st.info("No search history to export yet!")
|
499 |
+
|
500 |
+
if st.button("Download Current Itinerary"):
|
501 |
+
if st.session_state.current_itinerary:
|
502 |
+
df = pd.DataFrame(st.session_state.current_itinerary)
|
503 |
+
st.download_button(
|
504 |
+
label="π₯ Download Itinerary",
|
505 |
+
data=df.to_csv(index=False),
|
506 |
+
file_name="my_itinerary.csv",
|
507 |
+
mime="text/csv"
|
508 |
+
)
|
509 |
+
else:
|
510 |
+
st.info("No itinerary created yet!")
|
511 |
+
|
512 |
+
# Footer
|
513 |
+
st.markdown("---")
|
514 |
+
st.markdown("""
|
515 |
+
<div style="text-align: center; color: #666; padding: 2rem;">
|
516 |
+
<p>π <strong>AI City Companion</strong> - Your Smart Travel Guide</p>
|
517 |
+
<p>Built with β€οΈ for safe and smart city navigation | Hackathon MVP 2024</p>
|
518 |
+
<p>π¨ Emergency: Police (15) | Rescue (1122) | Fire (16)</p>
|
519 |
+
</div>
|
520 |
+
""", unsafe_allow_html=True)
|
521 |
+
|
522 |
+
if __name__ == "__main__":
|
523 |
+
main()
|