Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
-
import json
|
| 4 |
-
from sentence_transformers import SentenceTransformer
|
| 5 |
import chromadb
|
|
|
|
| 6 |
from bs4 import BeautifulSoup
|
| 7 |
|
| 8 |
# Initialize embedding model (Open-Source)
|
|
@@ -12,7 +11,7 @@ model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
|
|
| 12 |
client = chromadb.PersistentClient(path="./recipe_db")
|
| 13 |
collection = client.get_or_create_collection("recipes")
|
| 14 |
|
| 15 |
-
# Function to scrape restaurant data
|
| 16 |
def scrape_restaurant_info(city, recipe):
|
| 17 |
search_url = f"https://www.foodpanda.pk/restaurants?search={recipe}+{city}"
|
| 18 |
headers = {"User-Agent": "Mozilla/5.0"}
|
|
@@ -28,33 +27,51 @@ def scrape_restaurant_info(city, recipe):
|
|
| 28 |
return restaurant_list
|
| 29 |
|
| 30 |
# Streamlit UI
|
| 31 |
-
st.title("Pakistani
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
st.
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
else:
|
| 56 |
-
st.write("No
|
|
|
|
| 57 |
else:
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
else:
|
| 60 |
-
st.warning("Please enter a
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
|
|
|
|
|
|
| 3 |
import chromadb
|
| 4 |
+
from sentence_transformers import SentenceTransformer
|
| 5 |
from bs4 import BeautifulSoup
|
| 6 |
|
| 7 |
# Initialize embedding model (Open-Source)
|
|
|
|
| 11 |
client = chromadb.PersistentClient(path="./recipe_db")
|
| 12 |
collection = client.get_or_create_collection("recipes")
|
| 13 |
|
| 14 |
+
# Function to scrape restaurant data
|
| 15 |
def scrape_restaurant_info(city, recipe):
|
| 16 |
search_url = f"https://www.foodpanda.pk/restaurants?search={recipe}+{city}"
|
| 17 |
headers = {"User-Agent": "Mozilla/5.0"}
|
|
|
|
| 27 |
return restaurant_list
|
| 28 |
|
| 29 |
# Streamlit UI
|
| 30 |
+
st.title("Pakistani Famous Recipes Finder 🍛")
|
| 31 |
+
|
| 32 |
+
# User inputs city
|
| 33 |
+
city = st.text_input("Enter a Pakistani City (e.g., Lahore, Karachi, Islamabad)")
|
| 34 |
+
|
| 35 |
+
# Optional: User inputs recipe (not mandatory)
|
| 36 |
+
query = st.text_input("Enter a Recipe Name (Optional)")
|
| 37 |
+
|
| 38 |
+
if st.button("Find Recipes & Restaurants"):
|
| 39 |
+
if city:
|
| 40 |
+
if query:
|
| 41 |
+
# Retrieve specific recipe info from vector DB
|
| 42 |
+
query_embedding = model.encode(query).tolist()
|
| 43 |
+
results = collection.query(query_embedding, n_results=3)
|
| 44 |
+
|
| 45 |
+
if results["documents"]:
|
| 46 |
+
st.subheader(f"Famous {query} in {city}")
|
| 47 |
+
for recipe in results["documents"][0]:
|
| 48 |
+
st.write(f"**Recipe:** {recipe['name']}")
|
| 49 |
+
st.image(recipe["image"], caption=recipe["name"], use_column_width=True)
|
| 50 |
+
st.write(f"Price: {recipe['price']} PKR")
|
| 51 |
+
|
| 52 |
+
# Fetch restaurant data via scraping
|
| 53 |
+
restaurants = scrape_restaurant_info(city, query)
|
| 54 |
+
if restaurants:
|
| 55 |
+
st.subheader("Available at These Restaurants:")
|
| 56 |
+
for r in restaurants:
|
| 57 |
+
st.write(f"- {r}")
|
| 58 |
+
else:
|
| 59 |
+
st.write("No restaurant data found.")
|
| 60 |
else:
|
| 61 |
+
st.write("No matching recipes found.")
|
| 62 |
+
|
| 63 |
else:
|
| 64 |
+
# Retrieve all famous recipes in the city
|
| 65 |
+
city_embedding = model.encode(city).tolist()
|
| 66 |
+
results = collection.query(city_embedding, n_results=5)
|
| 67 |
+
|
| 68 |
+
if results["documents"]:
|
| 69 |
+
st.subheader(f"Famous Recipes in {city}")
|
| 70 |
+
for recipe in results["documents"][0]:
|
| 71 |
+
st.write(f"**Recipe:** {recipe['name']}")
|
| 72 |
+
st.image(recipe["image"], caption=recipe["name"], use_column_width=True)
|
| 73 |
+
st.write(f"Price: {recipe['price']} PKR")
|
| 74 |
+
else:
|
| 75 |
+
st.write("No famous recipes found for this city.")
|
| 76 |
else:
|
| 77 |
+
st.warning("Please enter a city name.")
|