File size: 2,329 Bytes
ec44e4f
01f37dd
ec44e4f
 
01f37dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec44e4f
01f37dd
 
ec44e4f
01f37dd
 
 
 
 
 
 
 
 
ec44e4f
01f37dd
 
 
 
 
 
ec44e4f
01f37dd
ec44e4f
01f37dd
 
 
 
 
 
ec44e4f
01f37dd
 
 
 
 
 
 
 
ec44e4f
01f37dd
 
 
 
 
 
ec44e4f
01f37dd
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
import streamlit as st
import requests
import pandas as pd

# -----------------------
# Overpass API function
# -----------------------
def fetch_restaurants(city_name):
    query = f"""
    [out:json][timeout:25];
    area["name"="{city_name}"]->.searchArea;
    (
      node["amenity"="restaurant"](area.searchArea);
      way["amenity"="restaurant"](area.searchArea);
      relation["amenity"="restaurant"](area.searchArea);
    );
    out center tags;
    """
    url = "https://overpass-api.de/api/interpreter"
    response = requests.post(url, data={"data": query})
    if response.status_code != 200:
        return None

    data = response.json()
    restaurants = []

    for element in data["elements"]:
        tags = element.get("tags", {})
        name = tags.get("name", "Unnamed")
        cuisine = tags.get("cuisine", "Not listed")
        phone = tags.get("phone", "N/A")
        street = tags.get("addr:street", "")
        housenumber = tags.get("addr:housenumber", "")
        city = tags.get("addr:city", city_name)
        address = f"{housenumber} {street}, {city}".strip()

        restaurants.append({
            "Name": name,
            "Cuisine": cuisine,
            "Contact": phone,
            "Address": address
        })

    return pd.DataFrame(restaurants)

# -----------------------
# Streamlit UI
# -----------------------
st.set_page_config(page_title="Live City Restaurant Guide", layout="wide")
st.title("🍽️ Live City Restaurant Guide")
st.subheader("Enter a city to find real-time restaurant data (OpenStreetMap API)")

city = st.text_input("Enter city name (e.g., Lahore, Karachi, Paris, New York):").strip().title()

if city:
    with st.spinner("πŸ” Fetching data... please wait..."):
        df = fetch_restaurants(city)

    if df is None or df.empty:
        st.warning("❌ No restaurant data found or API limit reached. Try another city.")
    else:
        st.success(f"βœ… Found {len(df)} restaurants in {city}")
        for idx, row in df.iterrows():
            with st.expander(f"{row['Name']} 🍴"):
                st.markdown(f"**πŸ“ Address:** {row['Address']}")
                st.markdown(f"**🍱 Cuisine:** {row['Cuisine']}")
                st.markdown(f"**πŸ“ž Contact:** {row['Contact']}")
else:
    st.info("πŸ” Please enter a city name to search.")