Liori25 commited on
Commit
72ab19b
ยท
verified ยท
1 Parent(s): e37a7e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +169 -1
app.py CHANGED
@@ -225,4 +225,172 @@ button.gallery-item {
225
  }
226
  button.gallery-item:hover {
227
  transform: scale(2.5) !important; /* Make it BIG */
228
- z-index: 1000
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  }
226
  button.gallery-item:hover {
227
  transform: scale(2.5) !important; /* Make it BIG */
228
+ z-index: 1000 !important; /* Put it on top of everything */
229
+ box-shadow: 0 10px 25px rgba(0,0,0,0.3) !important;
230
+ border: 2px solid white !important;
231
+ border-radius: 8px !important;
232
+ }
233
+ """
234
+
235
+ # ==========================================
236
+ # 5. LAYOUT CONSTRUCTION
237
+ # ==========================================
238
+ with gr.Blocks(title="Legacy Kitchen") as demo:
239
+
240
+ # --- HEADER ---
241
+ gr.HTML(f"""
242
+ <div class="custom-header">
243
+ <div class="logo-area">
244
+ <img src="data:image/jpeg;base64,{logo_b64}" class="logo-img">
245
+ <div class="text-area">
246
+ <span class="app-name">Legacy Kitchen</span>
247
+ <span class="app-slogan">Turning Handwritten Notes into a Digital Cookbook.</span>
248
+ </div>
249
+ </div>
250
+ <div style="color: #65676b; font-weight: 600;">v3.4</div>
251
+ </div>
252
+ """)
253
+
254
+ with gr.Row():
255
+
256
+ # --- LEFT SIDEBAR ---
257
+ with gr.Column(scale=1, min_width=200):
258
+ gr.HTML(f"""
259
+ <div style="display:flex; align-items:center; padding: 10px 10px 5px 10px;">
260
+ <img src="data:image/jpeg;base64,{profile_b64}" style="width:40px; height:40px; border-radius:50%; margin-right:10px; object-fit:cover;">
261
+ <b style="font-size: 16px;">My Profile</b>
262
+ </div>
263
+ """)
264
+ gr.HTML("<hr style='border: 0; border-top: 1px solid #e4e6eb; margin: 10px 0 20px 0;'>")
265
+
266
+ nav_digital = gr.Button("โœจ AI Digitizer", elem_classes=["nav-btn", "selected"])
267
+ nav_feed = gr.Button("๐Ÿ“ฐ News Feed", elem_classes=["nav-btn"])
268
+ nav_about = gr.Button("โ„น๏ธ About", elem_classes=["nav-btn"])
269
+
270
+ # --- CENTER CONTENT ---
271
+ with gr.Column(scale=3):
272
+
273
+ # === VIEW 1: AI DIGITALIZER ===
274
+ with gr.Group(visible=True) as digitalizer_view:
275
+
276
+ # SECTION 1: UPLOAD & TEXT
277
+ with gr.Row(elem_classes=["gap-fix"]):
278
+
279
+ # Left: Upload & Examples
280
+ with gr.Column(scale=1):
281
+ with gr.Group(elem_classes=["content-card"]):
282
+ input_img = gr.Image(type="filepath", label="Upload", height=300)
283
+ magic_btn = gr.Button("โœจ Convert to Digital", variant="primary", size="lg")
284
+
285
+ # Examples Component (Hover effect added in CSS)
286
+ gr.Examples(
287
+ examples=[
288
+ ["quick_tries_images/applecrisp.jpg"],
289
+ ["quick_tries_images/meatballs recipe.jpg"],
290
+ ["quick_tries_images/tofu.jfif"]
291
+ ],
292
+ inputs=input_img,
293
+ label="Or try these examples:",
294
+ cache_examples=False
295
+ )
296
+
297
+ # Right: Text
298
+ with gr.Column(scale=1):
299
+ with gr.Group(elem_classes=["content-card"]):
300
+ out_text = gr.Textbox(
301
+ label="Result",
302
+ value="Here your digitalized recipe will be presented",
303
+ lines=20,
304
+ interactive=False,
305
+ show_label=False
306
+ )
307
+
308
+ # Spacer
309
+ gr.HTML("<div style='height: 35px;'></div>")
310
+
311
+ # SECTION 2: SIMILAR RECIPES
312
+ gr.Markdown("### 3. Similar Recipes from Database")
313
+
314
+ with gr.Row():
315
+ # CARD 1
316
+ with gr.Column(elem_classes=["sim-card"]):
317
+ sim1 = gr.Markdown("Once you will upload your scanned recipe, we will share similar recipes!")
318
+ with gr.Row():
319
+ gr.Button("๐Ÿ‘ Like", size="sm", variant="secondary")
320
+ gr.Button("โ†—๏ธ Share", size="sm", variant="secondary")
321
+
322
+ # CARD 2
323
+ with gr.Column(elem_classes=["sim-card"]):
324
+ sim2 = gr.Markdown("")
325
+ with gr.Row():
326
+ gr.Button("๐Ÿ‘ Like", size="sm", variant="secondary")
327
+ gr.Button("โ†—๏ธ Share", size="sm", variant="secondary")
328
+
329
+ # CARD 3
330
+ with gr.Column(elem_classes=["sim-card"]):
331
+ sim3 = gr.Markdown("")
332
+ with gr.Row():
333
+ gr.Button("๐Ÿ‘ Like", size="sm", variant="secondary")
334
+ gr.Button("โ†—๏ธ Share", size="sm", variant="secondary")
335
+
336
+ magic_btn.click(magic_pipeline, input_img, [out_text, sim1, sim2, sim3])
337
+
338
+ # === VIEW 2: FEED ===
339
+ with gr.Group(visible=False) as feed_view:
340
+ with gr.Group(elem_classes=["content-card"]):
341
+ with gr.Row():
342
+ gr.HTML(f'<img src="data:image/jpeg;base64,{profile_b64}" style="width:40px; height:40px; border-radius:50%; object-fit:cover;">')
343
+ gr.Textbox(placeholder=f"What recipe are you cooking today?", show_label=False, container=False, scale=10)
344
+
345
+ if not df_recipes.empty:
346
+ feed_samples = df_recipes.sample(10)
347
+ for index, row in feed_samples.iterrows():
348
+ user_name = random.choice(["Grandma Rose", "Chef Mike", "Sarah J."])
349
+ emoji = random.choice(["๐Ÿฅ˜", "๐Ÿฅ—", "๐Ÿฐ", "๐ŸŒฎ"])
350
+ with gr.Group(elem_classes=["content-card"]):
351
+ gr.HTML(f"""
352
+ <div style="display:flex; gap:10px; align-items:center; margin-bottom:12px;">
353
+ <div style="width:40px; height:40px; background:#e4e6eb; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:20px;">{emoji}</div>
354
+ <div><b>{user_name}</b><br><span style="color:gray; font-size:12px;">2h ยท ๐ŸŒ Public</span></div>
355
+ </div>
356
+ """)
357
+ gr.Markdown(f"### {row['Title']}")
358
+ gr.Markdown(f"{str(row['Raw_Output'])[:250]}...")
359
+ with gr.Row():
360
+ gr.Button("๐Ÿ‘ Like", size="sm", variant="secondary")
361
+ gr.Button("๐Ÿ’ฌ Comment", size="sm", variant="secondary")
362
+ gr.Button("โ†—๏ธ Share", size="sm", variant="secondary")
363
+ else:
364
+ gr.Markdown("โš ๏ธ Database is empty.")
365
+
366
+ # === VIEW 3: ABOUT ===
367
+ with gr.Group(visible=False) as about_view:
368
+ with gr.Group(elem_classes=["content-card"]):
369
+ gr.Markdown("# โ„น๏ธ About Legacy Kitchen\n\n**Turning Handwritten Notes into a Digital Cookbook.**")
370
+
371
+ # --- RIGHT COLUMN ---
372
+ with gr.Column(scale=1, min_width=200):
373
+ gr.Markdown("### Trending Recipes")
374
+ def trend_box(title, likes):
375
+ return f"<div class='trend-box'><b>{title}</b><br><span style='color:gray; font-size:12px;'>{likes} likes</span></div>"
376
+ gr.HTML(trend_box("๐Ÿœ Ramen Hack", "12k") + trend_box("๐Ÿช Best Cookies", "8k") + trend_box("๐Ÿฐ Cheese Cake", "15k") + trend_box("๐Ÿช Nana's Tahini Cookies", "9k"))
377
+
378
+ # ==========================================
379
+ # 6. JAVASCRIPT LOGIC
380
+ # ==========================================
381
+ def go_digi():
382
+ 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"]))
383
+
384
+ def go_feed():
385
+ 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"]))
386
+
387
+ def go_about():
388
+ 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"]))
389
+
390
+ outputs_ui = [digitalizer_view, feed_view, about_view, nav_digital, nav_feed, nav_about]
391
+ nav_digital.click(go_digi, None, outputs_ui)
392
+ nav_feed.click(go_feed, None, outputs_ui)
393
+ nav_about.click(go_about, None, outputs_ui)
394
+
395
+ if __name__ == "__main__":
396
+ demo.launch(theme=theme, css=modern_css)