Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ import random
|
|
| 9 |
from sentence_transformers import SentenceTransformer
|
| 10 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 11 |
|
| 12 |
-
# --- 1. 讛讻谞转 转诪讜谞讜转
|
| 13 |
IMAGE_DIR = "extracted_images"
|
| 14 |
if os.path.exists('images.zip'):
|
| 15 |
with zipfile.ZipFile('images.zip', 'r') as zip_ref:
|
|
@@ -40,7 +40,7 @@ def load_data():
|
|
| 40 |
main_df, dish_embeddings, user_embeddings = load_data()
|
| 41 |
NAMES = ["James Miller", "Sarah Johnson", "Michael Brown", "Emily Davis", "Robert Wilson"]
|
| 42 |
|
| 43 |
-
# --- 3. 诪谞讜注 讛讞讬驻讜砖
|
| 44 |
def run_discovery(query, origin, hobbies, style):
|
| 45 |
q_vec = model.encode([str(query)])
|
| 46 |
u_dna = f"Origin: {origin}, Hobbies: {hobbies}, Style: {style}"
|
|
@@ -69,22 +69,20 @@ def run_discovery(query, origin, hobbies, style):
|
|
| 69 |
img_url = find_dish_image(original_idx)
|
| 70 |
|
| 71 |
html_output += f"""
|
| 72 |
-
<div style="border: 1px solid #C4A484;
|
| 73 |
<img src="{img_url}" style="width: 250px; height: 250px; object-fit: cover; border: 1px solid #D2B48C; padding: 4px; background: white;">
|
| 74 |
<div style="flex: 1;">
|
| 75 |
<div style="display: flex; justify-content: space-between; align-items: center;">
|
| 76 |
-
<h2 style="margin: 0; color: #3E2723; font-family: 'Playfair Display', serif; font-size: 2em;">{row['dish_name']}</h2>
|
| 77 |
-
<span style="background: #3E2723; color: white; padding: 2px 12px; font-weight: bold; border-radius: 20px;
|
| 78 |
</div>
|
| 79 |
<p style="color: #7F4F24; margin: 8px 0; font-family: 'Courier New', monospace; font-weight: bold;">馃搷 {row['restaurant_name']} | {row.get('cuisine_type', 'Gourmet')}</p>
|
| 80 |
-
<p style="font-family: 'Playfair Display', serif; font-style: italic; color: #4E342E; margin: 15px 0; font-size: 1.1em;
|
| 81 |
-
|
| 82 |
<div style="display: flex; gap: 10px; margin-bottom: 15px;">
|
| 83 |
-
<span style="background: #EEDDCC; color: #3E2723; padding: 4px 10px;
|
| 84 |
-
<span style="background: #EEDDCC; color: #3E2723; padding: 4px 10px;
|
| 85 |
</div>
|
| 86 |
-
|
| 87 |
-
<div style="background: #F5F1EE; padding: 12px; border-radius: 4px; font-size: 0.9em; color: #5D4037;">
|
| 88 |
<b>Twin:</b> {u_name} from {row['user_origin']} | <b>Rating:</b> {row['rating']}/5.0
|
| 89 |
</div>
|
| 90 |
</div>
|
|
@@ -92,44 +90,56 @@ def run_discovery(query, origin, hobbies, style):
|
|
| 92 |
"""
|
| 93 |
return html_output
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
# --- 4. 讛诪诪砖拽 讛诪注讜爪讘 (3 诪住讻讬诐) ---
|
| 98 |
custom_css = """
|
| 99 |
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,700;1,400&display=swap');
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
| 103 |
"""
|
| 104 |
|
| 105 |
with gr.Blocks(css=custom_css) as demo:
|
| 106 |
gr.HTML("<h1 style='text-align: center; color: #3E2723; font-family: \"Playfair Display\", serif; font-size: 4em; font-style: italic; border-bottom: 2px double #D2B48C; margin-bottom: 40px;'>BiteWise</h1>")
|
| 107 |
|
| 108 |
with gr.Tabs() as tabs:
|
| 109 |
-
|
|
|
|
| 110 |
with gr.Row():
|
| 111 |
-
u_n = gr.Textbox(label="IDENTIFICATION
|
| 112 |
u_o = gr.Dropdown(list(main_df['user_origin'].unique()), label="ORIGIN", value="Tel Aviv")
|
| 113 |
with gr.Row():
|
| 114 |
u_h = gr.Dropdown(list(main_df['user_hobbies'].unique()), label="INTERESTS")
|
| 115 |
-
u_s = gr.Dropdown(list(main_df['user_fashion_style'].unique()) + ["Vintage/Retro"], label="
|
| 116 |
btn1 = gr.Button("SYNC PERSONALITY", variant="primary")
|
| 117 |
-
btn1.click(lambda: gr.
|
| 118 |
|
| 119 |
-
|
|
|
|
| 120 |
q_in = gr.Textbox(label="CRAVING", placeholder="What are you in the mood for?")
|
| 121 |
-
btn2 = gr.Button("
|
| 122 |
out_html = gr.HTML()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
btn2.click(run_discovery, [q_in, u_o, u_h, u_s], out_html)
|
|
|
|
|
|
|
| 124 |
|
| 125 |
-
|
|
|
|
| 126 |
gr.Markdown("### ARCHIVE A NEW CULINARY DISCOVERY")
|
| 127 |
with gr.Row():
|
| 128 |
gr.Textbox(label="DISH")
|
| 129 |
gr.Textbox(label="ESTABLISHMENT")
|
| 130 |
gr.Textbox(label="REVIEW", lines=3)
|
| 131 |
-
s_btn = gr.Button("SUBMIT
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
demo.launch(allowed_paths=["."])
|
|
|
|
| 9 |
from sentence_transformers import SentenceTransformer
|
| 10 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 11 |
|
| 12 |
+
# --- 1. 讛讻谞转 转诪讜谞讜转 ---
|
| 13 |
IMAGE_DIR = "extracted_images"
|
| 14 |
if os.path.exists('images.zip'):
|
| 15 |
with zipfile.ZipFile('images.zip', 'r') as zip_ref:
|
|
|
|
| 40 |
main_df, dish_embeddings, user_embeddings = load_data()
|
| 41 |
NAMES = ["James Miller", "Sarah Johnson", "Michael Brown", "Emily Davis", "Robert Wilson"]
|
| 42 |
|
| 43 |
+
# --- 3. 诪谞讜注 讛讞讬驻讜砖 ---
|
| 44 |
def run_discovery(query, origin, hobbies, style):
|
| 45 |
q_vec = model.encode([str(query)])
|
| 46 |
u_dna = f"Origin: {origin}, Hobbies: {hobbies}, Style: {style}"
|
|
|
|
| 69 |
img_url = find_dish_image(original_idx)
|
| 70 |
|
| 71 |
html_output += f"""
|
| 72 |
+
<div style="border: 1px solid #C4A484; padding: 25px; margin-bottom: 30px; background: #FFF9F5; border-left: 10px solid #3E2723; display: flex; gap: 25px; color: #3E2723;">
|
| 73 |
<img src="{img_url}" style="width: 250px; height: 250px; object-fit: cover; border: 1px solid #D2B48C; padding: 4px; background: white;">
|
| 74 |
<div style="flex: 1;">
|
| 75 |
<div style="display: flex; justify-content: space-between; align-items: center;">
|
| 76 |
+
<h2 style="margin: 0; color: #3E2723; font-family: 'Playfair Display', serif; font-size: 2.2em;">{row['dish_name']}</h2>
|
| 77 |
+
<span style="background: #3E2723; color: white; padding: 2px 12px; font-weight: bold; border-radius: 20px;">{pct} MATCH</span>
|
| 78 |
</div>
|
| 79 |
<p style="color: #7F4F24; margin: 8px 0; font-family: 'Courier New', monospace; font-weight: bold;">馃搷 {row['restaurant_name']} | {row.get('cuisine_type', 'Gourmet')}</p>
|
| 80 |
+
<p style="font-family: 'Playfair Display', serif; font-style: italic; color: #4E342E; margin: 15px 0; font-size: 1.1em;">"{row['taste_review']}"</p>
|
|
|
|
| 81 |
<div style="display: flex; gap: 10px; margin-bottom: 15px;">
|
| 82 |
+
<span style="background: #EEDDCC; color: #3E2723; padding: 4px 10px; border: 1px solid #D2B48C;">馃挵 PRICE: {row.get('price_range', '$$')}</span>
|
| 83 |
+
<span style="background: #EEDDCC; color: #3E2723; padding: 4px 10px; border: 1px solid #D2B48C;">馃懃 BEST FOR: {row.get('best_for', 'Friends')}</span>
|
| 84 |
</div>
|
| 85 |
+
<div style="background: #F5F1EE; padding: 12px; font-size: 0.9em; border-radius: 4px;">
|
|
|
|
| 86 |
<b>Twin:</b> {u_name} from {row['user_origin']} | <b>Rating:</b> {row['rating']}/5.0
|
| 87 |
</div>
|
| 88 |
</div>
|
|
|
|
| 90 |
"""
|
| 91 |
return html_output
|
| 92 |
|
| 93 |
+
# --- 4. 诪诪砖拽 VINTAGE SOUL (讟讗讘讬诐 诪讜住转专讬诐) ---
|
|
|
|
|
|
|
| 94 |
custom_css = """
|
| 95 |
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,700;1,400&display=swap');
|
| 96 |
+
/* 讛住转专转 讛讟讗讘讬诐 诇诪专讗讛 砖诇 讗驻诇讬拽爪讬讛 讗讞转 讞诇拽讛 */
|
| 97 |
+
.tabs > .tab-nav { display: none !important; }
|
| 98 |
+
.gradio-container { background-color: #FDFCF8 !important; color: #3E2723; }
|
| 99 |
+
button.primary { background: #3E2723 !important; border-radius: 0px !important; color: white !important; font-family: 'Courier New', monospace; text-transform: uppercase; }
|
| 100 |
+
input, .dropdown { border-radius: 0px !important; border: 1px solid #D2B48C !important; }
|
| 101 |
"""
|
| 102 |
|
| 103 |
with gr.Blocks(css=custom_css) as demo:
|
| 104 |
gr.HTML("<h1 style='text-align: center; color: #3E2723; font-family: \"Playfair Display\", serif; font-size: 4em; font-style: italic; border-bottom: 2px double #D2B48C; margin-bottom: 40px;'>BiteWise</h1>")
|
| 105 |
|
| 106 |
with gr.Tabs() as tabs:
|
| 107 |
+
# 诪住讱 DNA
|
| 108 |
+
with gr.TabItem("DNA", id=0):
|
| 109 |
with gr.Row():
|
| 110 |
+
u_n = gr.Textbox(label="IDENTIFICATION")
|
| 111 |
u_o = gr.Dropdown(list(main_df['user_origin'].unique()), label="ORIGIN", value="Tel Aviv")
|
| 112 |
with gr.Row():
|
| 113 |
u_h = gr.Dropdown(list(main_df['user_hobbies'].unique()), label="INTERESTS")
|
| 114 |
+
u_s = gr.Dropdown(list(main_df['user_fashion_style'].unique()) + ["Vintage/Retro"], label="STYLE", value="Vintage/Retro")
|
| 115 |
btn1 = gr.Button("SYNC PERSONALITY", variant="primary")
|
| 116 |
+
btn1.click(lambda: gr.Tabs(selected=1), None, tabs)
|
| 117 |
|
| 118 |
+
# 诪住讱 DISCOVERY
|
| 119 |
+
with gr.TabItem("DISCOVERY", id=1):
|
| 120 |
q_in = gr.Textbox(label="CRAVING", placeholder="What are you in the mood for?")
|
| 121 |
+
btn2 = gr.Button("SEARCH ARCHIVE", variant="primary")
|
| 122 |
out_html = gr.HTML()
|
| 123 |
+
with gr.Row():
|
| 124 |
+
btn_back = gr.Button("BACK TO DNA")
|
| 125 |
+
btn_to_archive = gr.Button("ADD NEW DISCOVERY")
|
| 126 |
+
|
| 127 |
btn2.click(run_discovery, [q_in, u_o, u_h, u_s], out_html)
|
| 128 |
+
btn_back.click(lambda: gr.Tabs(selected=0), None, tabs)
|
| 129 |
+
btn_to_archive.click(lambda: gr.Tabs(selected=2), None, tabs)
|
| 130 |
|
| 131 |
+
# 诪住讱 ARCHIVE
|
| 132 |
+
with gr.TabItem("ARCHIVE", id=2):
|
| 133 |
gr.Markdown("### ARCHIVE A NEW CULINARY DISCOVERY")
|
| 134 |
with gr.Row():
|
| 135 |
gr.Textbox(label="DISH")
|
| 136 |
gr.Textbox(label="ESTABLISHMENT")
|
| 137 |
gr.Textbox(label="REVIEW", lines=3)
|
| 138 |
+
s_btn = gr.Button("SUBMIT TO ARCHIVE", variant="primary")
|
| 139 |
+
status_msg = gr.Markdown()
|
| 140 |
+
btn_back_disc = gr.Button("BACK TO DISCOVERY")
|
| 141 |
+
|
| 142 |
+
s_btn.click(lambda: "### Thank you! \nYour review has been successfully shared.", None, status_msg)
|
| 143 |
+
btn_back_disc.click(lambda: gr.Tabs(selected=1), None, tabs)
|
| 144 |
|
| 145 |
demo.launch(allowed_paths=["."])
|