mfraz commited on
Commit
50671e9
·
verified ·
1 Parent(s): ff09ffe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -30
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 (Alternative to API)
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 City Recipe Finder 🍛")
32
-
33
- city = st.selectbox("Select a City", ["Lahore", "Karachi", "Islamabad", "Peshawar", "Quetta"])
34
- query = st.text_input("Enter a Recipe Name")
35
-
36
- if st.button("Find Recipe"):
37
- if query:
38
- # Retrieve recipe info from vector DB
39
- query_embedding = model.encode(query).tolist()
40
- results = collection.query(query_embedding, n_results=3)
41
-
42
- if results["documents"]:
43
- st.subheader(f"Famous {query} Recipes in {city}")
44
- for recipe in results["documents"][0]:
45
- st.write(f"**Recipe:** {recipe['name']}")
46
- st.image(recipe["image"], caption=recipe["name"], use_column_width=True)
47
- st.write(f"Price: {recipe['price']} PKR")
48
-
49
- # Fetch restaurant data via scraping
50
- restaurants = scrape_restaurant_info(city, query)
51
- if restaurants:
52
- st.subheader("Available at These Restaurants:")
53
- for r in restaurants:
54
- st.write(f"- {r}")
 
 
 
 
 
 
55
  else:
56
- st.write("No restaurant data found.")
 
57
  else:
58
- st.write("No matching recipes found.")
 
 
 
 
 
 
 
 
 
 
 
59
  else:
60
- st.warning("Please enter a recipe name.")
 
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.")