import streamlit as st import requests import chromadb import json from sentence_transformers import SentenceTransformer # Load Embedding Model model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2") # Connect to ChromaDB (Persistent) DB_PATH = "./recipe_db" client = chromadb.PersistentClient(path=DB_PATH) collection = client.get_or_create_collection("recipes") # Function to Fetch Restaurant Data Using OpenStreetMap (Overpass API) def get_restaurants(city): overpass_url = "http://overpass-api.de/api/interpreter" query = f""" [out:json]; area[name="{city}"]->.searchArea; node["amenity"="restaurant"](area.searchArea); out; """ response = requests.get(overpass_url, params={'data': query}) if response.status_code == 200: data = response.json() restaurants = [] for element in data.get("elements", []): name = element.get("tags", {}).get("name", "Unknown Restaurant") restaurants.append(name) return restaurants[:5] # Return top 5 results else: return ["No restaurant data found."] # Sample Food Dishes (You can expand this dataset) food_data = { "Lahore": [ {"name": "Nihari", "price": "800 PKR"}, {"name": "Karahi", "price": "1200 PKR"}, {"name": "Haleem", "price": "600 PKR"} ], "Karachi": [ {"name": "Biryani", "price": "500 PKR"}, {"name": "Haleem", "price": "700 PKR"}, {"name": "Kebab Roll", "price": "300 PKR"} ], "Peshawar": [ {"name": "Chapli Kebab", "price": "400 PKR"}, {"name": "Dumpukht", "price": "1500 PKR"} ], "Multan": [ {"name": "Sohan Halwa", "price": "1000 PKR"}, {"name": "Saag", "price": "600 PKR"} ] } # Streamlit UI st.title("Famous Pakistani Food Finder 🍛") city = st.text_input("Enter a Pakistani City (e.g., Lahore, Karachi, Islamabad)").strip() if st.button("Find Food & Restaurants"): if city: st.subheader(f"Famous Foods in {city}") # Retrieve food data for the city dishes = food_data.get(city, []) if dishes: for dish in dishes: st.write(f"**Dish:** {dish['name']}") st.write(f"**Price:** {dish['price']}") st.markdown("---") else: st.write("No data available for this city. Please add more dishes!") # Retrieve restaurant data st.subheader(f"Popular Restaurants in {city}") restaurants = get_restaurants(city) if restaurants: for r in restaurants: st.write(f"- {r}") else: st.write("No restaurant data found.") else: st.warning("Please enter a city name.")