Liori25 commited on
Commit
1c72d79
·
verified ·
1 Parent(s): 0a1f097

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +126 -1
app.py CHANGED
@@ -206,4 +206,129 @@ body, .gradio-container { background-color: #f0f2f5; }
206
  with gr.Blocks(title="Legacy Kitchen") as demo:
207
 
208
  # --- HEADER ---
209
- gr.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  with gr.Blocks(title="Legacy Kitchen") as demo:
207
 
208
  # --- HEADER ---
209
+ gr.HTML(f"""
210
+ <div class="custom-header">
211
+ <div class="logo-area">
212
+ <img src="data:image/jpeg;base64,{logo_b64}" class="logo-img">
213
+ <div class="text-area">
214
+ <span class="app-name">Legacy Kitchen</span>
215
+ <span class="app-slogan">Turning Handwritten Notes into a Digital Cookbook.</span>
216
+ </div>
217
+ </div>
218
+ <div style="color: #65676b; font-weight: 600;">v3.1</div>
219
+ </div>
220
+ """)
221
+
222
+ with gr.Row():
223
+
224
+ # --- LEFT SIDEBAR ---
225
+ with gr.Column(scale=1, min_width=200):
226
+ gr.HTML(f"""
227
+ <div style="display:flex; align-items:center; padding: 10px 10px 5px 10px;">
228
+ <img src="data:image/jpeg;base64,{profile_b64}" style="width:40px; height:40px; border-radius:50%; margin-right:10px; object-fit:cover;">
229
+ <b style="font-size: 16px;">My Profile</b>
230
+ </div>
231
+ """)
232
+ gr.HTML("<hr style='border: 0; border-top: 1px solid #e4e6eb; margin: 10px 0 20px 0;'>")
233
+
234
+ nav_digital = gr.Button("✨ AI Digitizer", elem_classes=["nav-btn", "selected"])
235
+ nav_feed = gr.Button("📰 News Feed", elem_classes=["nav-btn"])
236
+ nav_about = gr.Button("ℹ️ About", elem_classes=["nav-btn"])
237
+
238
+ # --- CENTER CONTENT ---
239
+ with gr.Column(scale=3):
240
+
241
+ # === VIEW 1: AI DIGITALIZER (Default) ===
242
+ with gr.Group(visible=True) as digitalizer_view:
243
+
244
+ # SECTION 1: UPLOAD & TEXT (Side by Side)
245
+ # FIX 2: Added 'gap-fix' class to ensure space > 7px (set to 25px in CSS)
246
+ with gr.Row(elem_classes=["gap-fix"]):
247
+ # Left: Upload
248
+ with gr.Column(scale=1):
249
+ gr.Markdown("### 1. Upload Note", elem_classes=["content-card"])
250
+ with gr.Group(elem_classes=["content-card"]):
251
+ input_img = gr.Image(type="filepath", label="Upload", height=300)
252
+ magic_btn = gr.Button("✨ Convert to Digital", variant="primary", size="lg")
253
+
254
+ # Right: Text
255
+ with gr.Column(scale=1):
256
+ gr.Markdown("### 2. Digital Text", elem_classes=["content-card"])
257
+ with gr.Group(elem_classes=["content-card"]):
258
+ out_text = gr.Textbox(label="Result", lines=12, interactive=False, show_label=False)
259
+
260
+ # FIX 1: Added 30px Spacer (using 35px to be safe)
261
+ gr.HTML("<div style='height: 35px;'></div>")
262
+
263
+ # SECTION 2: SIMILAR RECIPES
264
+ gr.Markdown("### 3. Similar Recipes from Database")
265
+ with gr.Row():
266
+ with gr.Column(elem_classes=["sim-card"]):
267
+ # FIX 3: Default Text when no image uploaded
268
+ sim1 = gr.Markdown("Once you will upload your scanned recipe, we will share similar recipes!")
269
+ with gr.Column(elem_classes=["sim-card"]):
270
+ sim2 = gr.Markdown("")
271
+ with gr.Column(elem_classes=["sim-card"]):
272
+ sim3 = gr.Markdown("")
273
+
274
+ magic_btn.click(magic_pipeline, input_img, [out_text, sim1, sim2, sim3])
275
+
276
+ # === VIEW 2: FEED ===
277
+ with gr.Group(visible=False) as feed_view:
278
+ with gr.Group(elem_classes=["content-card"]):
279
+ with gr.Row():
280
+ gr.HTML(f'<img src="data:image/jpeg;base64,{profile_b64}" style="width:40px; height:40px; border-radius:50%; object-fit:cover;">')
281
+ gr.Textbox(placeholder=f"What recipe are you cooking today?", show_label=False, container=False, scale=10)
282
+
283
+ if not df_recipes.empty:
284
+ feed_samples = df_recipes.sample(10)
285
+ for index, row in feed_samples.iterrows():
286
+ user_name = random.choice(["Grandma Rose", "Chef Mike", "Sarah J."])
287
+ emoji = random.choice(["🥘", "🥗", "🍰", "🌮"])
288
+ with gr.Group(elem_classes=["content-card"]):
289
+ gr.HTML(f"""
290
+ <div style="display:flex; gap:10px; align-items:center; margin-bottom:12px;">
291
+ <div style="width:40px; height:40px; background:#e4e6eb; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:20px;">{emoji}</div>
292
+ <div><b>{user_name}</b><br><span style="color:gray; font-size:12px;">2h · 🌍 Public</span></div>
293
+ </div>
294
+ """)
295
+ gr.Markdown(f"### {row['Title']}")
296
+ gr.Markdown(f"{str(row['Raw_Output'])[:250]}...")
297
+ with gr.Row():
298
+ gr.Button("👍 Like", size="sm", variant="secondary")
299
+ gr.Button("💬 Comment", size="sm", variant="secondary")
300
+ gr.Button("↗️ Share", size="sm", variant="secondary")
301
+ else:
302
+ gr.Markdown("⚠️ Database is empty.")
303
+
304
+ # === VIEW 3: ABOUT ===
305
+ with gr.Group(visible=False) as about_view:
306
+ with gr.Group(elem_classes=["content-card"]):
307
+ gr.Markdown("# ℹ️ About Legacy Kitchen\n\n**Turning Handwritten Notes into a Digital Cookbook.**")
308
+
309
+ # --- RIGHT COLUMN ---
310
+ with gr.Column(scale=1, min_width=200):
311
+ gr.Markdown("### Trending Recipes")
312
+ def trend_box(title, likes):
313
+ return f"<div class='trend-box'><b>{title}</b><br><span style='color:gray; font-size:12px;'>{likes} likes</span></div>"
314
+ gr.HTML(trend_box("🍜 Ramen Hack", "12k") + trend_box("🍪 Best Cookies", "8k") + trend_box("🍰 Cheese Cake", "15k") + trend_box("🍪 Nana's Tahini Cookies", "9k"))
315
+
316
+ # ==========================================
317
+ # 6. JAVASCRIPT LOGIC
318
+ # ==========================================
319
+ def go_digi():
320
+ 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"]))
321
+
322
+ def go_feed():
323
+ 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"]))
324
+
325
+ def go_about():
326
+ 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"]))
327
+
328
+ outputs_ui = [digitalizer_view, feed_view, about_view, nav_digital, nav_feed, nav_about]
329
+ nav_digital.click(go_digi, None, outputs_ui)
330
+ nav_feed.click(go_feed, None, outputs_ui)
331
+ nav_about.click(go_about, None, outputs_ui)
332
+
333
+ if __name__ == "__main__":
334
+ demo.launch(theme=theme, css=modern_css)