Liori25 commited on
Commit
e37a7e0
·
verified ·
1 Parent(s): 79bc23a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -155
app.py CHANGED
@@ -66,8 +66,11 @@ def find_similar_recipes_list(query_text):
66
  for idx in top_indices:
67
  row = df_recipes.iloc[idx]
68
  title = row['Title']
69
- desc = str(row['Raw_Output'])[:200] + "..."
70
- card_content = f"### 🏆 {title}\n\n{desc}"
 
 
 
71
  results_list.append(card_content)
72
 
73
  while len(results_list) < 3:
@@ -171,7 +174,8 @@ body, .gradio-container { background-color: #f0f2f5; }
171
  border: 1px solid #ddd;
172
  padding: 20px;
173
  margin-bottom: 20px;
174
- height: 100%; /* Important for equal height */
 
175
  }
176
 
177
  /* Similar Recipe Cards */
@@ -182,6 +186,19 @@ body, .gradio-container { background-color: #f0f2f5; }
182
  padding: 15px;
183
  height: 100%;
184
  border-top: 4px solid #1877f2;
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  }
186
 
187
  /* Right Side Trending Box */
@@ -199,156 +216,13 @@ body, .gradio-container { background-color: #f0f2f5; }
199
  .gap-fix {
200
  gap: 25px !important;
201
  }
202
- """
203
 
204
- # ==========================================
205
- # 5. LAYOUT CONSTRUCTION
206
- # ==========================================
207
- with gr.Blocks(title="Legacy Kitchen") as demo:
208
-
209
- # --- HEADER ---
210
- gr.HTML(f"""
211
- <div class="custom-header">
212
- <div class="logo-area">
213
- <img src="data:image/jpeg;base64,{logo_b64}" class="logo-img">
214
- <div class="text-area">
215
- <span class="app-name">Legacy Kitchen</span>
216
- <span class="app-slogan">Turning Handwritten Notes into a Digital Cookbook.</span>
217
- </div>
218
- </div>
219
- <div style="color: #65676b; font-weight: 600;">v3.3</div>
220
- </div>
221
- """)
222
-
223
- with gr.Row():
224
-
225
- # --- LEFT SIDEBAR ---
226
- with gr.Column(scale=1, min_width=200):
227
- gr.HTML(f"""
228
- <div style="display:flex; align-items:center; padding: 10px 10px 5px 10px;">
229
- <img src="data:image/jpeg;base64,{profile_b64}" style="width:40px; height:40px; border-radius:50%; margin-right:10px; object-fit:cover;">
230
- <b style="font-size: 16px;">My Profile</b>
231
- </div>
232
- """)
233
- gr.HTML("<hr style='border: 0; border-top: 1px solid #e4e6eb; margin: 10px 0 20px 0;'>")
234
-
235
- nav_digital = gr.Button("✨ AI Digitizer", elem_classes=["nav-btn", "selected"])
236
- nav_feed = gr.Button("📰 News Feed", elem_classes=["nav-btn"])
237
- nav_about = gr.Button("ℹ️ About", elem_classes=["nav-btn"])
238
-
239
- # --- CENTER CONTENT ---
240
- with gr.Column(scale=3):
241
-
242
- # === VIEW 1: AI DIGITALIZER ===
243
- with gr.Group(visible=True) as digitalizer_view:
244
-
245
- # SECTION 1: UPLOAD & TEXT
246
- with gr.Row(elem_classes=["gap-fix"]):
247
-
248
- # Left: Upload & Examples
249
- with gr.Column(scale=1):
250
- # FIX 1: Removed Header "1. Upload Note"
251
- with gr.Group(elem_classes=["content-card"]):
252
- input_img = gr.Image(type="filepath", label="Upload", height=300)
253
- magic_btn = gr.Button("✨ Convert to Digital", variant="primary", size="lg")
254
-
255
- # Examples Component
256
- gr.Examples(
257
- examples=[
258
- ["quick_tries_images/applecrisp.jpg"],
259
- ["quick_tries_images/meatballs recipe.jpg"],
260
- ["quick_tries_images/tofu.jfif"]
261
- ],
262
- inputs=input_img,
263
- label="Or try these examples:",
264
- cache_examples=False
265
- )
266
-
267
- # Right: Text
268
- with gr.Column(scale=1):
269
- # FIX 2: Removed Header "2. Digital Text"
270
- with gr.Group(elem_classes=["content-card"]):
271
- # FIX 3: Added Empty State Placeholder
272
- # FIX 4: Increased lines to 20 to align bottom with the left column examples
273
- out_text = gr.Textbox(
274
- label="Result",
275
- value="Here your digitalized recipe will be presented",
276
- lines=20,
277
- interactive=False,
278
- show_label=False
279
- )
280
-
281
- # Spacer
282
- gr.HTML("<div style='height: 35px;'></div>")
283
-
284
- # SECTION 2: SIMILAR RECIPES
285
- gr.Markdown("### 3. Similar Recipes from Database")
286
- with gr.Row():
287
- with gr.Column(elem_classes=["sim-card"]):
288
- sim1 = gr.Markdown("Once you will upload your scanned recipe, we will share similar recipes!")
289
- with gr.Column(elem_classes=["sim-card"]):
290
- sim2 = gr.Markdown("")
291
- with gr.Column(elem_classes=["sim-card"]):
292
- sim3 = gr.Markdown("")
293
-
294
- magic_btn.click(magic_pipeline, input_img, [out_text, sim1, sim2, sim3])
295
-
296
- # === VIEW 2: FEED ===
297
- with gr.Group(visible=False) as feed_view:
298
- with gr.Group(elem_classes=["content-card"]):
299
- with gr.Row():
300
- gr.HTML(f'<img src="data:image/jpeg;base64,{profile_b64}" style="width:40px; height:40px; border-radius:50%; object-fit:cover;">')
301
- gr.Textbox(placeholder=f"What recipe are you cooking today?", show_label=False, container=False, scale=10)
302
-
303
- if not df_recipes.empty:
304
- feed_samples = df_recipes.sample(10)
305
- for index, row in feed_samples.iterrows():
306
- user_name = random.choice(["Grandma Rose", "Chef Mike", "Sarah J."])
307
- emoji = random.choice(["🥘", "🥗", "🍰", "🌮"])
308
- with gr.Group(elem_classes=["content-card"]):
309
- gr.HTML(f"""
310
- <div style="display:flex; gap:10px; align-items:center; margin-bottom:12px;">
311
- <div style="width:40px; height:40px; background:#e4e6eb; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:20px;">{emoji}</div>
312
- <div><b>{user_name}</b><br><span style="color:gray; font-size:12px;">2h · 🌍 Public</span></div>
313
- </div>
314
- """)
315
- gr.Markdown(f"### {row['Title']}")
316
- gr.Markdown(f"{str(row['Raw_Output'])[:250]}...")
317
- with gr.Row():
318
- gr.Button("👍 Like", size="sm", variant="secondary")
319
- gr.Button("💬 Comment", size="sm", variant="secondary")
320
- gr.Button("↗️ Share", size="sm", variant="secondary")
321
- else:
322
- gr.Markdown("⚠️ Database is empty.")
323
-
324
- # === VIEW 3: ABOUT ===
325
- with gr.Group(visible=False) as about_view:
326
- with gr.Group(elem_classes=["content-card"]):
327
- gr.Markdown("# ℹ️ About Legacy Kitchen\n\n**Turning Handwritten Notes into a Digital Cookbook.**")
328
-
329
- # --- RIGHT COLUMN ---
330
- with gr.Column(scale=1, min_width=200):
331
- gr.Markdown("### Trending Recipes")
332
- def trend_box(title, likes):
333
- return f"<div class='trend-box'><b>{title}</b><br><span style='color:gray; font-size:12px;'>{likes} likes</span></div>"
334
- gr.HTML(trend_box("🍜 Ramen Hack", "12k") + trend_box("🍪 Best Cookies", "8k") + trend_box("🍰 Cheese Cake", "15k") + trend_box("🍪 Nana's Tahini Cookies", "9k"))
335
-
336
- # ==========================================
337
- # 6. JAVASCRIPT LOGIC
338
- # ==========================================
339
- def go_digi():
340
- return (gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(elem_classes=["nav-btn", "selected"]), gr.update(elem_classes=["nav-btn"]), gr.update(elem_classes=["nav-btn"]))
341
-
342
- def go_feed():
343
- return (gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), gr.update(elem_classes=["nav-btn"]), gr.update(elem_classes=["nav-btn", "selected"]), gr.update(elem_classes=["nav-btn"]))
344
-
345
- def go_about():
346
- return (gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(elem_classes=["nav-btn"]), gr.update(elem_classes=["nav-btn"]), gr.update(elem_classes=["nav-btn", "selected"]))
347
-
348
- outputs_ui = [digitalizer_view, feed_view, about_view, nav_digital, nav_feed, nav_about]
349
- nav_digital.click(go_digi, None, outputs_ui)
350
- nav_feed.click(go_feed, None, outputs_ui)
351
- nav_about.click(go_about, None, outputs_ui)
352
-
353
- if __name__ == "__main__":
354
- demo.launch(theme=theme, css=modern_css)
 
66
  for idx in top_indices:
67
  row = df_recipes.iloc[idx]
68
  title = row['Title']
69
+ # INCREASED TEXT LENGTH to 600 chars to demonstrate scrolling
70
+ desc = str(row['Raw_Output'])[:600] + "..."
71
+
72
+ # Wrapped description in a div class 'sim-scroll' for CSS styling
73
+ card_content = f"### 🏆 {title}\n\n<div class='sim-scroll'>{desc}</div>"
74
  results_list.append(card_content)
75
 
76
  while len(results_list) < 3:
 
174
  border: 1px solid #ddd;
175
  padding: 20px;
176
  margin-bottom: 20px;
177
+ height: 100%;
178
+ overflow: visible !important; /* Allow pop-ups to be seen */
179
  }
180
 
181
  /* Similar Recipe Cards */
 
186
  padding: 15px;
187
  height: 100%;
188
  border-top: 4px solid #1877f2;
189
+ display: flex;
190
+ flex-direction: column;
191
+ justify-content: space-between;
192
+ }
193
+
194
+ /* SCROLLABLE TEXT AREA for Similar Recipes */
195
+ .sim-scroll {
196
+ height: 150px; /* Fixed height */
197
+ overflow-y: auto; /* Enable Vertical Scrolling */
198
+ margin-bottom: 10px;
199
+ padding-right: 5px; /* Space for scrollbar */
200
+ font-size: 14px;
201
+ color: #4b4f56;
202
  }
203
 
204
  /* Right Side Trending Box */
 
216
  .gap-fix {
217
  gap: 25px !important;
218
  }
 
219
 
220
+ /* --- IMAGE POP HOVER EFFECT --- */
221
+ /* Targets the buttons inside the Examples component */
222
+ button.gallery-item {
223
+ transition: transform 0.2s ease, box-shadow 0.2s ease !important;
224
+ z-index: 1;
225
+ }
226
+ button.gallery-item:hover {
227
+ transform: scale(2.5) !important; /* Make it BIG */
228
+ z-index: 1000