mfraz commited on
Commit
515863e
·
verified ·
1 Parent(s): 39d7666

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -3,7 +3,7 @@ import requests
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")
@@ -26,9 +26,9 @@ if not collection.count():
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
 
@@ -66,7 +66,8 @@ if st.button("Find Recipes & Restaurants"):
66
  if results and "documents" in results and results["documents"]:
67
  st.subheader(f"Famous {query} in {city}")
68
  for doc in results["documents"]:
69
- for recipe in doc:
 
70
  st.write(f"**Recipe:** {recipe['name']}")
71
  st.image(recipe["image"], caption=recipe["name"], use_column_width=True)
72
  st.write(f"Price: {recipe['price']} PKR")
@@ -90,7 +91,8 @@ if st.button("Find Recipes & Restaurants"):
90
  if results and "documents" in results and results["documents"]:
91
  st.subheader(f"Famous Recipes in {city}")
92
  for doc in results["documents"]:
93
- for recipe in doc:
 
94
  st.write(f"**Recipe:** {recipe['name']}")
95
  st.image(recipe["image"], caption=recipe["name"], use_column_width=True)
96
  st.write(f"Price: {recipe['price']} PKR")
 
3
  import chromadb
4
  from sentence_transformers import SentenceTransformer
5
  from bs4 import BeautifulSoup
6
+ import json # Import json to convert dictionary to string
7
 
8
  # Initialize embedding model
9
  model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
 
26
  for recipe in sample_recipes:
27
  embedding = model.encode(recipe["city"]).tolist()
28
  collection.add(
29
+ ids=[recipe["name"]], # IDs should be unique
30
  embeddings=[embedding],
31
+ documents=[json.dumps(recipe)] # Convert dictionary to string
32
  )
33
  print("Sample data added to ChromaDB")
34
 
 
66
  if results and "documents" in results and results["documents"]:
67
  st.subheader(f"Famous {query} in {city}")
68
  for doc in results["documents"]:
69
+ for recipe_json in doc:
70
+ recipe = json.loads(recipe_json) # Convert back to dictionary
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")
 
91
  if results and "documents" in results and results["documents"]:
92
  st.subheader(f"Famous Recipes in {city}")
93
  for doc in results["documents"]:
94
+ for recipe_json in doc:
95
+ recipe = json.loads(recipe_json) # Convert back to dictionary
96
  st.write(f"**Recipe:** {recipe['name']}")
97
  st.image(recipe["image"], caption=recipe["name"], use_column_width=True)
98
  st.write(f"Price: {recipe['price']} PKR")