Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,7 +56,6 @@ def get_embedding_via_api(text):
|
|
| 56 |
return np.array(response)
|
| 57 |
|
| 58 |
def find_similar_recipes_list(query_text):
|
| 59 |
-
# Matching logic remains exactly the same
|
| 60 |
if stored_embeddings is None: return ["Database error."] * 3
|
| 61 |
query_vec = get_embedding_via_api("Represent this recipe for retrieving similar dishes: " + query_text)
|
| 62 |
if len(query_vec.shape) == 1: query_vec = query_vec.reshape(1, -1)
|
|
@@ -64,7 +63,6 @@ def find_similar_recipes_list(query_text):
|
|
| 64 |
scores = cosine_similarity(query_vec, stored_embeddings)[0]
|
| 65 |
top_indices = scores.argsort()[-3:][::-1]
|
| 66 |
|
| 67 |
-
# --- UPDATED DISPLAY LOGIC STARTS HERE ---
|
| 68 |
# Identify the correct column names dynamically
|
| 69 |
cols = df_recipes.columns
|
| 70 |
ing_col = next((c for c in cols if 'ingredient' in c.lower()), None)
|
|
@@ -83,7 +81,6 @@ def find_similar_recipes_list(query_text):
|
|
| 83 |
# 1. Ingredients
|
| 84 |
if ing_col:
|
| 85 |
val = str(row[ing_col])
|
| 86 |
-
# Clean up if it looks like a python list string
|
| 87 |
if val.strip().startswith("[") and val.strip().endswith("]"):
|
| 88 |
val = val.strip()[1:-1].replace("'", "").replace('"', "")
|
| 89 |
content_parts.append(f"<b>🛒 INGREDIENTS:</b><br>{val}")
|
|
@@ -359,11 +356,14 @@ with gr.Blocks(title="CookBook AI") as demo:
|
|
| 359 |
with gr.Group(elem_classes=["content-card"]):
|
| 360 |
input_img = gr.Image(type="filepath", label="Upload", height=300)
|
| 361 |
magic_btn = gr.Button("✨ Convert to Digital", variant="primary", size="lg")
|
|
|
|
|
|
|
| 362 |
gr.Examples(
|
| 363 |
examples=[
|
| 364 |
["quick_tries_images/applecrisp.jpg"],
|
| 365 |
["quick_tries_images/meatballs recipe.jpg"],
|
| 366 |
-
["quick_tries_images/chocolateballs.png"]
|
|
|
|
| 367 |
],
|
| 368 |
inputs=input_img,
|
| 369 |
label="Or try these examples:",
|
|
|
|
| 56 |
return np.array(response)
|
| 57 |
|
| 58 |
def find_similar_recipes_list(query_text):
|
|
|
|
| 59 |
if stored_embeddings is None: return ["Database error."] * 3
|
| 60 |
query_vec = get_embedding_via_api("Represent this recipe for retrieving similar dishes: " + query_text)
|
| 61 |
if len(query_vec.shape) == 1: query_vec = query_vec.reshape(1, -1)
|
|
|
|
| 63 |
scores = cosine_similarity(query_vec, stored_embeddings)[0]
|
| 64 |
top_indices = scores.argsort()[-3:][::-1]
|
| 65 |
|
|
|
|
| 66 |
# Identify the correct column names dynamically
|
| 67 |
cols = df_recipes.columns
|
| 68 |
ing_col = next((c for c in cols if 'ingredient' in c.lower()), None)
|
|
|
|
| 81 |
# 1. Ingredients
|
| 82 |
if ing_col:
|
| 83 |
val = str(row[ing_col])
|
|
|
|
| 84 |
if val.strip().startswith("[") and val.strip().endswith("]"):
|
| 85 |
val = val.strip()[1:-1].replace("'", "").replace('"', "")
|
| 86 |
content_parts.append(f"<b>🛒 INGREDIENTS:</b><br>{val}")
|
|
|
|
| 356 |
with gr.Group(elem_classes=["content-card"]):
|
| 357 |
input_img = gr.Image(type="filepath", label="Upload", height=300)
|
| 358 |
magic_btn = gr.Button("✨ Convert to Digital", variant="primary", size="lg")
|
| 359 |
+
|
| 360 |
+
# --- UPDATED EXAMPLES HERE ---
|
| 361 |
gr.Examples(
|
| 362 |
examples=[
|
| 363 |
["quick_tries_images/applecrisp.jpg"],
|
| 364 |
["quick_tries_images/meatballs recipe.jpg"],
|
| 365 |
+
["quick_tries_images/chocolateballs.png"],
|
| 366 |
+
["quick_tries_images/Apple Dapple (aka Fresh Apple Cake).jfif"]
|
| 367 |
],
|
| 368 |
inputs=input_img,
|
| 369 |
label="Or try these examples:",
|