Liori25 commited on
Commit
b9fabbe
·
verified ·
1 Parent(s): a2f3a40

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +102 -4
app.py CHANGED
@@ -57,10 +57,17 @@ try:
57
  else:
58
  cookbook_logo_b64 = profile_b64
59
 
 
 
 
 
 
 
60
  process_b64 = image_to_base64("preview of process.jpg")
61
  except:
62
  profile_b64 = ""
63
  cookbook_logo_b64 = ""
 
64
  process_b64 = ""
65
 
66
  # ==========================================
@@ -169,7 +176,7 @@ footer { display: none !important; }
169
  align-items: center;
170
  }
171
 
172
- /* 2. LAYOUT COLUMNS - "FAT CENTER" CONFIGURATION */
173
  .main-layout { display: flex; justify-content: center; padding-top: 20px; gap: 20px; }
174
 
175
  /* Left Sidebar: Compact (220px) */
@@ -192,9 +199,9 @@ footer { display: none !important; }
192
  border: 1px solid #e4e6eb;
193
  }
194
 
195
- /* 4. NAVIGATION BUTTONS - FLUID WIDTH */
196
  .nav-btn {
197
- width: 100% !important; /* Resized to fit the new 220px container */
198
  height: 42.5px !important;
199
  text-align: left !important;
200
  justify-content: flex-start !important;
@@ -396,4 +403,95 @@ with gr.Blocks(title="CookBook", css=facebook_css, theme=theme) as demo:
396
  </div>
397
  """)
398
  gr.Markdown(f"**{row['Title']}**")
399
- gr.Markdown(f"{str(row['Raw_Output'])[:300]}... <span style='color:#1877F2;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  else:
58
  cookbook_logo_b64 = profile_b64
59
 
60
+ # 3. Sponsored Image
61
+ if os.path.exists("famous-female-chefs.webp"):
62
+ sponsored_b64 = image_to_base64("famous-female-chefs.webp")
63
+ else:
64
+ sponsored_b64 = "" # Fallback or empty
65
+
66
  process_b64 = image_to_base64("preview of process.jpg")
67
  except:
68
  profile_b64 = ""
69
  cookbook_logo_b64 = ""
70
+ sponsored_b64 = ""
71
  process_b64 = ""
72
 
73
  # ==========================================
 
176
  align-items: center;
177
  }
178
 
179
+ /* 2. LAYOUT COLUMNS */
180
  .main-layout { display: flex; justify-content: center; padding-top: 20px; gap: 20px; }
181
 
182
  /* Left Sidebar: Compact (220px) */
 
199
  border: 1px solid #e4e6eb;
200
  }
201
 
202
+ /* 4. NAVIGATION BUTTONS */
203
  .nav-btn {
204
+ width: 100% !important;
205
  height: 42.5px !important;
206
  text-align: left !important;
207
  justify-content: flex-start !important;
 
403
  </div>
404
  """)
405
  gr.Markdown(f"**{row['Title']}**")
406
+ gr.Markdown(f"{str(row['Raw_Output'])[:300]}... <span style='color:#1877F2; cursor:pointer;'>See more</span>")
407
+
408
+ with gr.Row(elem_classes=["post-actions"]):
409
+ gr.Button("👍 Like", elem_classes=["action-btn"], size="sm")
410
+ gr.Button("💬 Comment", elem_classes=["action-btn"], size="sm")
411
+ gr.Button("↪ Share", elem_classes=["action-btn"], size="sm")
412
+ else:
413
+ gr.Markdown("⚠️ Database is empty.")
414
+
415
+ # --- VIEW 3: SAVED ---
416
+ with gr.Column(visible=False) as saved_view:
417
+ gr.Markdown("### 🔖 Saved Items")
418
+ if not df_recipes.empty:
419
+ saved_batch = df_recipes.head(20)
420
+ for index, row in saved_batch.iterrows():
421
+ with gr.Group(elem_classes=["fb-card"]):
422
+ with gr.Row():
423
+ gr.HTML("<div style='width:80px; height:80px; background:#eee; border-radius:8px;'></div>")
424
+ with gr.Column():
425
+ gr.Markdown(f"**{row['Title']}**")
426
+ gr.HTML("<span style='color:#65676B; font-size:12px;'>Saved from News Feed</span>")
427
+ gr.Button("View Collection", size="sm", variant="secondary")
428
+
429
+ # --- VIEW 4: ABOUT ---
430
+ with gr.Group(visible=False) as about_view:
431
+ with gr.Group(elem_classes=["fb-card"]):
432
+ gr.Markdown("# About CookBook")
433
+ gr.Markdown("Developed by **Shahar Firshtman** and **Lior Feinstein**.")
434
+ gr.HTML(f"""
435
+ <div style="margin-top: 20px;">
436
+ <img src="data:image/jpeg;base64,{process_b64}" style="width: 100%; border-radius: 8px;">
437
+ </div>
438
+ """)
439
+
440
+ # === RIGHT COLUMN (Contacts) ===
441
+ with gr.Column(elem_classes=["col-right"]):
442
+ gr.Markdown("### Sponsored")
443
+ with gr.Group(elem_classes=["fb-card"]):
444
+ gr.Markdown("**Culinary School**\nJoin 10,000+ students learning to cook today!")
445
+ # Changed to HTML Image for cleaner look
446
+ gr.HTML(f"""
447
+ <img src="data:image/webp;base64,{sponsored_b64}" style="width:100%; height:auto; border-radius:8px; display:block; margin-top:10px;">
448
+ """)
449
+
450
+ gr.HTML("<hr style='border:0; border-top:1px solid #ced0d4; margin: 10px 0;'>")
451
+
452
+ gr.Markdown("### Contacts")
453
+ contacts = ["Elon Musk", "Gordon Ramsay", "Jamie Oliver", "Martha Stewart"]
454
+ for contact in contacts:
455
+ gr.HTML(f"""
456
+ <div class="contact-row">
457
+ <div style="position:relative;">
458
+ <img src="https://ui-avatars.com/api/?name={contact}&background=random" style="width:36px; height:36px; border-radius:50%;">
459
+ <div style="position:absolute; bottom:0; right:0; width:10px; height:10px; background:#31a24c; border-radius:50%; border:2px solid white;"></div>
460
+ </div>
461
+ <div class="contact-name">{contact}</div>
462
+ </div>
463
+ """)
464
+
465
+ # ==========================================
466
+ # 6. NAVIGATION LOGIC
467
+ # ==========================================
468
+ def go_digi():
469
+ return (
470
+ gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False),
471
+ gr.update(elem_classes=["nav-btn", "selected"]), gr.update(elem_classes=["nav-btn"]), gr.update(elem_classes=["nav-btn"]), gr.update(elem_classes=["nav-btn"])
472
+ )
473
+ def go_feed():
474
+ return (
475
+ gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False),
476
+ gr.update(elem_classes=["nav-btn"]), gr.update(elem_classes=["nav-btn", "selected"]), gr.update(elem_classes=["nav-btn"]), gr.update(elem_classes=["nav-btn"])
477
+ )
478
+ def go_saved():
479
+ return (
480
+ gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=False),
481
+ gr.update(elem_classes=["nav-btn"]), gr.update(elem_classes=["nav-btn"]), gr.update(elem_classes=["nav-btn", "selected"]), gr.update(elem_classes=["nav-btn"])
482
+ )
483
+ def go_about():
484
+ return (
485
+ gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True),
486
+ gr.update(elem_classes=["nav-btn"]), gr.update(elem_classes=["nav-btn"]), gr.update(elem_classes=["nav-btn"]), gr.update(elem_classes=["nav-btn", "selected"])
487
+ )
488
+
489
+ outputs_ui = [digitalizer_view, feed_view, saved_view, about_view, nav_digital, nav_feed, nav_saved, nav_about]
490
+
491
+ nav_digital.click(go_digi, None, outputs_ui)
492
+ nav_feed.click(go_feed, None, outputs_ui)
493
+ nav_saved.click(go_saved, None, outputs_ui)
494
+ nav_about.click(go_about, None, outputs_ui)
495
+
496
+ if __name__ == "__main__":
497
+ demo.launch()