Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,14 +3,35 @@ import requests
|
|
3 |
import chromadb
|
4 |
from sentence_transformers import SentenceTransformer
|
5 |
from bs4 import BeautifulSoup
|
|
|
6 |
|
7 |
-
# Initialize embedding model
|
8 |
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
|
9 |
|
10 |
-
# Connect to ChromaDB (
|
11 |
-
|
|
|
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}"
|
|
|
3 |
import chromadb
|
4 |
from sentence_transformers import SentenceTransformer
|
5 |
from bs4 import BeautifulSoup
|
6 |
+
import os
|
7 |
|
8 |
+
# Initialize embedding model
|
9 |
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
|
10 |
|
11 |
+
# Connect to ChromaDB (Persistent)
|
12 |
+
DB_PATH = "./recipe_db"
|
13 |
+
client = chromadb.PersistentClient(path=DB_PATH)
|
14 |
collection = client.get_or_create_collection("recipes")
|
15 |
|
16 |
+
# Check if ChromaDB has data, if not, insert sample data
|
17 |
+
if not collection.count():
|
18 |
+
sample_recipes = [
|
19 |
+
{"name": "Nihari", "city": "Lahore", "price": 800, "image": "https://example.com/nihari.jpg"},
|
20 |
+
{"name": "Karahi", "city": "Lahore", "price": 1200, "image": "https://example.com/karahi.jpg"},
|
21 |
+
{"name": "Biryani", "city": "Karachi", "price": 500, "image": "https://example.com/biryani.jpg"},
|
22 |
+
{"name": "Chapli Kebab", "city": "Peshawar", "price": 400, "image": "https://example.com/chapli.jpg"},
|
23 |
+
{"name": "Saag", "city": "Multan", "price": 600, "image": "https://example.com/saag.jpg"}
|
24 |
+
]
|
25 |
+
|
26 |
+
for recipe in sample_recipes:
|
27 |
+
embedding = model.encode(recipe["city"]).tolist()
|
28 |
+
collection.add(
|
29 |
+
ids=[recipe["name"]],
|
30 |
+
embeddings=[embedding],
|
31 |
+
documents=[recipe]
|
32 |
+
)
|
33 |
+
print("Sample data added to ChromaDB")
|
34 |
+
|
35 |
# Function to scrape restaurant data
|
36 |
def scrape_restaurant_info(city, recipe):
|
37 |
search_url = f"https://www.foodpanda.pk/restaurants?search={recipe}+{city}"
|