Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
import chromadb
|
4 |
-
from sentence_transformers import SentenceTransformer
|
5 |
import json
|
|
|
6 |
|
7 |
-
#
|
8 |
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
|
9 |
|
10 |
# Connect to ChromaDB (Persistent)
|
@@ -12,35 +12,7 @@ DB_PATH = "./recipe_db"
|
|
12 |
client = chromadb.PersistentClient(path=DB_PATH)
|
13 |
collection = client.get_or_create_collection("recipes")
|
14 |
|
15 |
-
#
|
16 |
-
recipe_categories = {
|
17 |
-
"Desi": ["Nihari", "Karahi", "Biryani", "Haleem", "Saag"],
|
18 |
-
"Fast Food": ["Burger", "Pizza", "Fries", "Shawarma"],
|
19 |
-
"BBQ": ["Tikka", "Seekh Kebab", "Malai Boti"],
|
20 |
-
"Seafood": ["Prawn Karahi", "Grilled Fish", "Fried Fish"]
|
21 |
-
}
|
22 |
-
|
23 |
-
# Check if ChromaDB has data, if not, insert sample data
|
24 |
-
if not collection.count():
|
25 |
-
sample_recipes = [
|
26 |
-
{"name": "Nihari", "city": "Lahore", "price": 800, "image": "https://example.com/nihari.jpg"},
|
27 |
-
{"name": "Karahi", "city": "Lahore", "price": 1200, "image": "https://example.com/karahi.jpg"},
|
28 |
-
{"name": "Biryani", "city": "Karachi", "price": 500, "image": "https://example.com/biryani.jpg"},
|
29 |
-
{"name": "Chapli Kebab", "city": "Peshawar", "price": 400, "image": "https://example.com/chapli.jpg"},
|
30 |
-
{"name": "Saag", "city": "Multan", "price": 600, "image": "https://example.com/saag.jpg"}
|
31 |
-
]
|
32 |
-
|
33 |
-
for recipe in sample_recipes:
|
34 |
-
embedding = model.encode(recipe["city"]).tolist()
|
35 |
-
collection.add(
|
36 |
-
ids=[recipe["name"]],
|
37 |
-
embeddings=[embedding],
|
38 |
-
documents=[json.dumps(recipe)] # Convert dictionary to string
|
39 |
-
)
|
40 |
-
print("Sample data added to ChromaDB")
|
41 |
-
|
42 |
-
|
43 |
-
# Function to fetch restaurant data using Overpass API
|
44 |
def get_restaurants(city):
|
45 |
overpass_url = "http://overpass-api.de/api/interpreter"
|
46 |
query = f"""
|
@@ -61,65 +33,54 @@ def get_restaurants(city):
|
|
61 |
else:
|
62 |
return ["No restaurant data found."]
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
# Streamlit UI
|
66 |
-
st.title("Pakistani
|
67 |
|
68 |
-
# User inputs city
|
69 |
city = st.text_input("Enter a Pakistani City (e.g., Lahore, Karachi, Islamabad)").strip()
|
70 |
|
71 |
-
|
72 |
-
recipe_type = st.selectbox("Select Recipe Type", options=list(recipe_categories.keys()))
|
73 |
-
|
74 |
-
# Optional: User inputs recipe (not mandatory)
|
75 |
-
query = st.selectbox("Select a Recipe (Optional)", ["Any"] + recipe_categories[recipe_type])
|
76 |
-
|
77 |
-
if st.button("Find Recipes & Restaurants"):
|
78 |
if city:
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
st.
|
86 |
-
|
87 |
-
|
88 |
-
recipe = json.loads(recipe_json) # Convert back to dictionary
|
89 |
-
st.write(f"**Recipe:** {recipe['name']}")
|
90 |
-
st.image(recipe["image"], caption=recipe["name"], use_container_width=True)
|
91 |
-
st.write(f"Price: {recipe['price']} PKR")
|
92 |
-
|
93 |
-
# Fetch restaurant data
|
94 |
-
restaurants = get_restaurants(city)
|
95 |
-
if restaurants:
|
96 |
-
st.subheader("Available at These Restaurants:")
|
97 |
-
for r in restaurants:
|
98 |
-
st.write(f"- {r}")
|
99 |
-
else:
|
100 |
-
st.write("No restaurant data found.")
|
101 |
-
else:
|
102 |
-
st.write(f"No matching recipes found for '{query}' in {city}.")
|
103 |
-
|
104 |
else:
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
st.image(recipe["image"], caption=recipe["name"], use_container_width=True)
|
116 |
-
st.write(f"Price: {recipe['price']} PKR")
|
117 |
-
|
118 |
-
# Fetch restaurant data for multiple recipes
|
119 |
-
restaurants = get_restaurants(city)
|
120 |
-
if restaurants:
|
121 |
-
st.subheader("Popular Restaurants in This City:")
|
122 |
-
for r in restaurants:
|
123 |
-
st.write(f"- {r}")
|
124 |
else:
|
125 |
st.warning("Please enter a city name.")
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
import chromadb
|
|
|
4 |
import json
|
5 |
+
from sentence_transformers import SentenceTransformer
|
6 |
|
7 |
+
# Load Embedding Model
|
8 |
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
|
9 |
|
10 |
# Connect to ChromaDB (Persistent)
|
|
|
12 |
client = chromadb.PersistentClient(path=DB_PATH)
|
13 |
collection = client.get_or_create_collection("recipes")
|
14 |
|
15 |
+
# Function to Fetch Restaurant Data Using OpenStreetMap (Overpass API)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
def get_restaurants(city):
|
17 |
overpass_url = "http://overpass-api.de/api/interpreter"
|
18 |
query = f"""
|
|
|
33 |
else:
|
34 |
return ["No restaurant data found."]
|
35 |
|
36 |
+
# Sample Food Dishes (You can expand this dataset)
|
37 |
+
food_data = {
|
38 |
+
"Lahore": [
|
39 |
+
{"name": "Nihari", "price": "800 PKR"},
|
40 |
+
{"name": "Karahi", "price": "1200 PKR"},
|
41 |
+
{"name": "Haleem", "price": "600 PKR"}
|
42 |
+
],
|
43 |
+
"Karachi": [
|
44 |
+
{"name": "Biryani", "price": "500 PKR"},
|
45 |
+
{"name": "Haleem", "price": "700 PKR"},
|
46 |
+
{"name": "Kebab Roll", "price": "300 PKR"}
|
47 |
+
],
|
48 |
+
"Peshawar": [
|
49 |
+
{"name": "Chapli Kebab", "price": "400 PKR"},
|
50 |
+
{"name": "Dumpukht", "price": "1500 PKR"}
|
51 |
+
],
|
52 |
+
"Multan": [
|
53 |
+
{"name": "Sohan Halwa", "price": "1000 PKR"},
|
54 |
+
{"name": "Saag", "price": "600 PKR"}
|
55 |
+
]
|
56 |
+
}
|
57 |
|
58 |
# Streamlit UI
|
59 |
+
st.title("Famous Pakistani Food Finder 🍛")
|
60 |
|
|
|
61 |
city = st.text_input("Enter a Pakistani City (e.g., Lahore, Karachi, Islamabad)").strip()
|
62 |
|
63 |
+
if st.button("Find Food & Restaurants"):
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
if city:
|
65 |
+
st.subheader(f"Famous Foods in {city}")
|
66 |
+
|
67 |
+
# Retrieve food data for the city
|
68 |
+
dishes = food_data.get(city, [])
|
69 |
+
if dishes:
|
70 |
+
for dish in dishes:
|
71 |
+
st.write(f"**Dish:** {dish['name']}")
|
72 |
+
st.write(f"**Price:** {dish['price']}")
|
73 |
+
st.markdown("---")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
else:
|
75 |
+
st.write("No data available for this city. Please add more dishes!")
|
76 |
+
|
77 |
+
# Retrieve restaurant data
|
78 |
+
st.subheader(f"Popular Restaurants in {city}")
|
79 |
+
restaurants = get_restaurants(city)
|
80 |
+
if restaurants:
|
81 |
+
for r in restaurants:
|
82 |
+
st.write(f"- {r}")
|
83 |
+
else:
|
84 |
+
st.write("No restaurant data found.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
else:
|
86 |
st.warning("Please enter a city name.")
|