ilsa15 commited on
Commit
01f37dd
Β·
verified Β·
1 Parent(s): e61c43a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -19
app.py CHANGED
@@ -1,30 +1,69 @@
1
  import streamlit as st
 
2
  import pandas as pd
3
 
4
- # Load dataset
5
- @st.cache_data
6
- def load_data():
7
- return pd.read_csv("restaurants.csv")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
- data = load_data()
 
10
 
11
- st.set_page_config(page_title="City Guide", layout="wide")
 
 
 
 
 
 
 
 
12
 
13
- st.title("🍽️ City Restaurant Guide")
14
- st.write("Find top restaurants in your city!")
 
 
 
 
15
 
16
- city_input = st.text_input("Enter a city name (e.g., Lahore)", "").strip().title()
17
 
18
- if city_input:
19
- results = data[data['city'] == city_input]
 
 
 
 
20
 
21
- if results.empty:
22
- st.warning("No restaurants found for this city.")
 
 
 
 
 
 
23
  else:
24
- for _, row in results.iterrows():
25
- with st.expander(row['name']):
26
- st.markdown(f"**Address:** {row['address']}")
27
- st.markdown(f"**Cuisine:** {row['cuisine']}")
28
- st.markdown(f"**Contact:** {row['contact']}")
 
29
  else:
30
- st.info("Please enter a city name to see results.")
 
1
  import streamlit as st
2
+ import requests
3
  import pandas as pd
4
 
5
+ # -----------------------
6
+ # Overpass API function
7
+ # -----------------------
8
+ def fetch_restaurants(city_name):
9
+ query = f"""
10
+ [out:json][timeout:25];
11
+ area["name"="{city_name}"]->.searchArea;
12
+ (
13
+ node["amenity"="restaurant"](area.searchArea);
14
+ way["amenity"="restaurant"](area.searchArea);
15
+ relation["amenity"="restaurant"](area.searchArea);
16
+ );
17
+ out center tags;
18
+ """
19
+ url = "https://overpass-api.de/api/interpreter"
20
+ response = requests.post(url, data={"data": query})
21
+ if response.status_code != 200:
22
+ return None
23
 
24
+ data = response.json()
25
+ restaurants = []
26
 
27
+ for element in data["elements"]:
28
+ tags = element.get("tags", {})
29
+ name = tags.get("name", "Unnamed")
30
+ cuisine = tags.get("cuisine", "Not listed")
31
+ phone = tags.get("phone", "N/A")
32
+ street = tags.get("addr:street", "")
33
+ housenumber = tags.get("addr:housenumber", "")
34
+ city = tags.get("addr:city", city_name)
35
+ address = f"{housenumber} {street}, {city}".strip()
36
 
37
+ restaurants.append({
38
+ "Name": name,
39
+ "Cuisine": cuisine,
40
+ "Contact": phone,
41
+ "Address": address
42
+ })
43
 
44
+ return pd.DataFrame(restaurants)
45
 
46
+ # -----------------------
47
+ # Streamlit UI
48
+ # -----------------------
49
+ st.set_page_config(page_title="Live City Restaurant Guide", layout="wide")
50
+ st.title("🍽️ Live City Restaurant Guide")
51
+ st.subheader("Enter a city to find real-time restaurant data (OpenStreetMap API)")
52
 
53
+ city = st.text_input("Enter city name (e.g., Lahore, Karachi, Paris, New York):").strip().title()
54
+
55
+ if city:
56
+ with st.spinner("πŸ” Fetching data... please wait..."):
57
+ df = fetch_restaurants(city)
58
+
59
+ if df is None or df.empty:
60
+ st.warning("❌ No restaurant data found or API limit reached. Try another city.")
61
  else:
62
+ st.success(f"βœ… Found {len(df)} restaurants in {city}")
63
+ for idx, row in df.iterrows():
64
+ with st.expander(f"{row['Name']} 🍴"):
65
+ st.markdown(f"**πŸ“ Address:** {row['Address']}")
66
+ st.markdown(f"**🍱 Cuisine:** {row['Cuisine']}")
67
+ st.markdown(f"**πŸ“ž Contact:** {row['Contact']}")
68
  else:
69
+ st.info("πŸ” Please enter a city name to search.")