Liori25 commited on
Commit
dcc4d71
·
verified ·
1 Parent(s): 0a17909

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -48
app.py CHANGED
@@ -45,19 +45,12 @@ def image_to_base64(image_path):
45
 
46
  # LOAD IMAGES
47
  try:
48
- # 1. Logo (Using text now, but keeping placeholder just in case)
49
- logo_b64 = image_to_base64("logo.jpg")
50
-
51
- # 2. Profile Photo (UPDATED to chef.avif)
52
- # Check for chef.avif, fallback to others if missing
53
  if os.path.exists("chef.avif"):
54
  profile_b64 = image_to_base64("chef.avif")
55
  else:
56
  profile_b64 = image_to_base64("232px-Tv_the_muppet_show_bein_green.jpg")
57
-
58
  process_b64 = image_to_base64("preview of process.jpg")
59
  except:
60
- logo_b64 = ""
61
  profile_b64 = ""
62
  process_b64 = ""
63
 
@@ -85,7 +78,6 @@ def find_similar_recipes_list(query_text):
85
  desc = str(row['Raw_Output'])
86
  score_display = f"{score:.0%}"
87
 
88
- # HTML styled as a "Suggested Post"
89
  card_content = (
90
  f"<div class='suggested-header'>Suggested for you · {score_display} Match</div>"
91
  f"### 🥘 {title}\n"
@@ -124,7 +116,7 @@ def ui_update_pipeline(image_path):
124
  return f"Error: {e}", "Error", gr.update(), gr.update(), "", gr.update(), ""
125
 
126
  # ==========================================
127
- # 4. FACEBOOK UI THEME & CSS
128
  # ==========================================
129
  theme = gr.themes.Default(
130
  primary_hue="blue",
@@ -170,23 +162,19 @@ footer { display: none !important; }
170
 
171
  /* 2. LAYOUT COLUMNS */
172
  .main-layout { display: flex; justify-content: center; padding-top: 20px; gap: 20px; }
173
- .col-left { width: 300px; display: none; } /* Hidden on mobile */
174
  .col-feed { width: 600px; max-width: 100%; }
175
  .col-right { width: 300px; display: none; }
176
 
177
- /* 3. CARD STYLING - MODERN & FLOATING */
178
  .fb-card {
179
  background: white;
180
  border-radius: 10px;
181
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
182
- margin-bottom: 20px; /* Increased margin for "Floating" effect */
183
  overflow: hidden;
184
  padding: 16px;
185
- border: 1px solid #e4e6eb; /* Subtle border for definition */
186
- }
187
- .fb-card:hover {
188
- box-shadow: 0 4px 12px rgba(0,0,0,0.15); /* Slight lift on hover */
189
- transition: box-shadow 0.2s ease;
190
  }
191
 
192
  /* 4. NAVIGATION BUTTONS */
@@ -231,11 +219,29 @@ footer { display: none !important; }
231
  .contact-row:hover { background-color: #e4e6eb; }
232
  .contact-name { font-weight: 500; font-size: 14px; margin-left: 10px; color: #050505; }
233
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
  /* UTILS */
235
  .sim-scroll { height: 200px; overflow-y: auto; font-size: 13px; color: #050505; }
236
  .suggested-header { font-size: 12px; font-weight: bold; color: #65676B; margin-bottom: 5px; }
237
-
238
- /* Media Queries */
239
  @media (min-width: 1100px) { .col-left, .col-right { display: block; } }
240
  """
241
 
@@ -244,12 +250,12 @@ footer { display: none !important; }
244
  # ==========================================
245
  with gr.Blocks(title="CookBook", css=facebook_css, theme=theme) as demo:
246
 
247
- # --- 1. NAVBAR (CookBook Logo) ---
248
  gr.HTML(f"""
249
  <div class="fb-navbar">
250
  <div style="display:flex; align-items:center;">
251
  <div class="fb-logo">CookBook</div>
252
- <div class="fb-search">🔍 &nbsp; Search CookBook</div>
253
  </div>
254
  <div style="display:flex; gap:10px;">
255
  <div style="width:40px;height:40px;background:#e4e6eb;border-radius:50%;display:flex;align-items:center;justify-content:center;">➕</div>
@@ -262,12 +268,12 @@ with gr.Blocks(title="CookBook", css=facebook_css, theme=theme) as demo:
262
  # --- 2. MAIN 3-COLUMN LAYOUT ---
263
  with gr.Row(elem_classes=["main-layout"]):
264
 
265
- # === LEFT COLUMN (Sidebar Navigation) ===
266
  with gr.Column(elem_classes=["col-left"]):
267
  gr.HTML(f"""
268
  <div class="contact-row">
269
  <img src="data:image/jpeg;base64,{profile_b64}" style="width:36px; height:36px; border-radius:50%; object-fit:cover;">
270
- <div class="contact-name">Chef Admin</div>
271
  </div>
272
  """)
273
  nav_digital = gr.Button("✨ Digitalize Recipe", elem_classes=["nav-btn", "selected"])
@@ -279,70 +285,63 @@ with gr.Blocks(title="CookBook", css=facebook_css, theme=theme) as demo:
279
  gr.Markdown("### Your Shortcuts")
280
  gr.Markdown("🥘 Culinary Arts Group\n\n🥧 Grandmother's Secrets\n\n🥗 Healthy Eating")
281
 
282
- # === CENTER COLUMN (The Feed & App Logic) ===
283
  with gr.Column(elem_classes=["col-feed"]):
284
 
285
- # --- VIEW 1: AI DIGITIZER (MODERN UI) ---
286
  with gr.Group(visible=True) as digitalizer_view:
287
 
288
- # CARD 1: THE INPUT (Clean, Modern Upload)
289
  with gr.Group(elem_classes=["fb-card"]):
290
  gr.Markdown("### 📸 Digitalize Recipe")
291
- gr.HTML("<div style='font-size: 13px; color: #65676B; margin-bottom: 10px;'>Upload a photo of a handwritten note to convert it into digital text instantly.</div>")
292
  gr.HTML("<hr style='border:0; border-top:1px solid #e4e6eb; margin: 10px 0;'>")
293
 
294
  with gr.Row():
295
- # Using container=False makes it look cleaner inside the card
296
- input_img = gr.Image(type="filepath", label="Upload Recipe Image", height=250, container=False)
297
 
298
- # Modern Button styling handled by Gradio's variant='primary' + custom CSS hover
299
  gr.HTML("<div style='height:15px'></div>")
300
  magic_btn = gr.Button("✨ Convert to Text", variant="primary")
301
 
302
- # Examples in a clean row
303
  gr.Examples(
304
  examples=[["quick_tries_images/applecrisp.jpg"], ["quick_tries_images/meatballs recipe.jpg"]],
305
- inputs=input_img, label="Or try one of these:"
306
  )
307
 
308
- # CARD 2: THE OUTPUT (Looks like a new post appearing)
309
  with gr.Group(elem_classes=["fb-card"]):
310
  gr.HTML(f"""
311
  <div class="post-header">
312
  <img src="data:image/jpeg;base64,{profile_b64}" class="user-avatar">
313
  <div class="post-info">
314
  <div class="post-author">CookBook AI</div>
315
- <div class="post-meta">Just now · <span style="color:blue">Verified Transcription</span></div>
316
  </div>
317
  </div>
318
  """)
319
 
320
- # The Result Textbox
321
- out_text = gr.Textbox(label="Transcription Result", placeholder="Waiting for image...", lines=8, show_label=False)
322
 
323
- # Action Bar
324
  with gr.Row(elem_classes=["post-actions"]):
325
  gr.Button("👍 Like", elem_classes=["action-btn"], size="sm")
326
  gr.Button("💬 Comment", elem_classes=["action-btn"], size="sm")
327
- gr.Button("📥 Save to Cookbook", elem_classes=["action-btn"], size="sm")
328
 
329
- # CARD 3: SUGGESTIONS (Floating below)
330
  with gr.Group(visible=True):
331
  gr.Markdown("### Suggested Pairings")
332
 
333
- # Sim Result 1
334
  with gr.Group(elem_classes=["fb-card"], visible=False) as c1_box:
335
  sim1 = gr.Markdown("Similar Recipe 1")
336
  with gr.Row(elem_classes=["post-actions"], visible=False) as c1_btns:
337
  gr.Button("Save", elem_classes=["action-btn"], size="sm")
338
 
339
- # Sim Result 2
340
  with gr.Group(elem_classes=["fb-card"], visible=False) as c2_box:
341
  sim2 = gr.Markdown("Similar Recipe 2")
342
  with gr.Row(elem_classes=["post-actions"]):
343
  gr.Button("Save", elem_classes=["action-btn"], size="sm")
344
 
345
- # Sim Result 3
346
  with gr.Group(elem_classes=["fb-card"], visible=False) as c3_box:
347
  sim3 = gr.Markdown("Similar Recipe 3")
348
  with gr.Row(elem_classes=["post-actions"]):
@@ -360,7 +359,6 @@ with gr.Blocks(title="CookBook", css=facebook_css, theme=theme) as demo:
360
  post_time = random.choice(["2h", "3h", "6h", "Yesterday"])
361
 
362
  with gr.Group(elem_classes=["fb-card"]):
363
- # Custom HTML Header for the card
364
  gr.HTML(f"""
365
  <div class="post-header">
366
  <div class="user-avatar" style="background:#e4e6eb; display:flex; align-items:center; justify-content:center; font-size:20px;">{emoji}</div>
@@ -373,7 +371,6 @@ with gr.Blocks(title="CookBook", css=facebook_css, theme=theme) as demo:
373
  gr.Markdown(f"**{row['Title']}**")
374
  gr.Markdown(f"{str(row['Raw_Output'])[:300]}... <span style='color:#1877F2; cursor:pointer;'>See more</span>")
375
 
376
- # Action Bar
377
  with gr.Row(elem_classes=["post-actions"]):
378
  gr.Button("👍 Like", elem_classes=["action-btn"], size="sm")
379
  gr.Button("💬 Comment", elem_classes=["action-btn"], size="sm")
@@ -381,7 +378,7 @@ with gr.Blocks(title="CookBook", css=facebook_css, theme=theme) as demo:
381
  else:
382
  gr.Markdown("⚠️ Database is empty.")
383
 
384
- # --- VIEW 3: SAVED RECIPES ---
385
  with gr.Column(visible=False) as saved_view:
386
  gr.Markdown("### 🔖 Saved Items")
387
  if not df_recipes.empty:
@@ -406,7 +403,7 @@ with gr.Blocks(title="CookBook", css=facebook_css, theme=theme) as demo:
406
  </div>
407
  """)
408
 
409
- # === RIGHT COLUMN (Contacts / Sponsored) ===
410
  with gr.Column(elem_classes=["col-right"]):
411
  gr.Markdown("### Sponsored")
412
  with gr.Group(elem_classes=["fb-card"]):
@@ -416,7 +413,6 @@ with gr.Blocks(title="CookBook", css=facebook_css, theme=theme) as demo:
416
  gr.HTML("<hr style='border:0; border-top:1px solid #ced0d4; margin: 10px 0;'>")
417
 
418
  gr.Markdown("### Contacts")
419
- # Fake contacts list
420
  contacts = ["Elon Musk", "Gordon Ramsay", "Jamie Oliver", "Martha Stewart"]
421
  for contact in contacts:
422
  gr.HTML(f"""
@@ -430,7 +426,7 @@ with gr.Blocks(title="CookBook", css=facebook_css, theme=theme) as demo:
430
  """)
431
 
432
  # ==========================================
433
- # 6. JAVASCRIPT NAVIGATION LOGIC
434
  # ==========================================
435
  def go_digi():
436
  return (
 
45
 
46
  # LOAD IMAGES
47
  try:
 
 
 
 
 
48
  if os.path.exists("chef.avif"):
49
  profile_b64 = image_to_base64("chef.avif")
50
  else:
51
  profile_b64 = image_to_base64("232px-Tv_the_muppet_show_bein_green.jpg")
 
52
  process_b64 = image_to_base64("preview of process.jpg")
53
  except:
 
54
  profile_b64 = ""
55
  process_b64 = ""
56
 
 
78
  desc = str(row['Raw_Output'])
79
  score_display = f"{score:.0%}"
80
 
 
81
  card_content = (
82
  f"<div class='suggested-header'>Suggested for you · {score_display} Match</div>"
83
  f"### 🥘 {title}\n"
 
116
  return f"Error: {e}", "Error", gr.update(), gr.update(), "", gr.update(), ""
117
 
118
  # ==========================================
119
+ # 4. UI THEME & CSS
120
  # ==========================================
121
  theme = gr.themes.Default(
122
  primary_hue="blue",
 
162
 
163
  /* 2. LAYOUT COLUMNS */
164
  .main-layout { display: flex; justify-content: center; padding-top: 20px; gap: 20px; }
165
+ .col-left { width: 300px; display: none; }
166
  .col-feed { width: 600px; max-width: 100%; }
167
  .col-right { width: 300px; display: none; }
168
 
169
+ /* 3. CARD STYLING */
170
  .fb-card {
171
  background: white;
172
  border-radius: 10px;
173
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
174
+ margin-bottom: 25px; /* Spacing between separated sections */
175
  overflow: hidden;
176
  padding: 16px;
177
+ border: 1px solid #e4e6eb;
 
 
 
 
178
  }
179
 
180
  /* 4. NAVIGATION BUTTONS */
 
219
  .contact-row:hover { background-color: #e4e6eb; }
220
  .contact-name { font-weight: 500; font-size: 14px; margin-left: 10px; color: #050505; }
221
 
222
+ /* 8. EXAMPLES (QUICK TRIES) - POP & INTERACTIVE */
223
+ button.gallery-item {
224
+ border: none !important;
225
+ background: transparent !important;
226
+ padding: 4px !important;
227
+ }
228
+ button.gallery-item img {
229
+ width: 110px !important; /* Larger Size */
230
+ height: 110px !important;
231
+ border-radius: 12px !important;
232
+ transition: all 0.3s ease !important; /* Smooth animation */
233
+ object-fit: cover;
234
+ box-shadow: 0 2px 5px rgba(0,0,0,0.1);
235
+ }
236
+ button.gallery-item:hover img {
237
+ transform: scale(1.15) !important; /* Pop effect */
238
+ box-shadow: 0 8px 15px rgba(24, 119, 242, 0.3) !important; /* Blue glow */
239
+ z-index: 10;
240
+ }
241
+
242
  /* UTILS */
243
  .sim-scroll { height: 200px; overflow-y: auto; font-size: 13px; color: #050505; }
244
  .suggested-header { font-size: 12px; font-weight: bold; color: #65676B; margin-bottom: 5px; }
 
 
245
  @media (min-width: 1100px) { .col-left, .col-right { display: block; } }
246
  """
247
 
 
250
  # ==========================================
251
  with gr.Blocks(title="CookBook", css=facebook_css, theme=theme) as demo:
252
 
253
+ # --- 1. NAVBAR ---
254
  gr.HTML(f"""
255
  <div class="fb-navbar">
256
  <div style="display:flex; align-items:center;">
257
  <div class="fb-logo">CookBook</div>
258
+ <div class="fb-search">🔍 &nbsp; Search Recipe...</div>
259
  </div>
260
  <div style="display:flex; gap:10px;">
261
  <div style="width:40px;height:40px;background:#e4e6eb;border-radius:50%;display:flex;align-items:center;justify-content:center;">➕</div>
 
268
  # --- 2. MAIN 3-COLUMN LAYOUT ---
269
  with gr.Row(elem_classes=["main-layout"]):
270
 
271
+ # === LEFT COLUMN (Sidebar) ===
272
  with gr.Column(elem_classes=["col-left"]):
273
  gr.HTML(f"""
274
  <div class="contact-row">
275
  <img src="data:image/jpeg;base64,{profile_b64}" style="width:36px; height:36px; border-radius:50%; object-fit:cover;">
276
+ <div class="contact-name">Welcome Chef</div>
277
  </div>
278
  """)
279
  nav_digital = gr.Button("✨ Digitalize Recipe", elem_classes=["nav-btn", "selected"])
 
285
  gr.Markdown("### Your Shortcuts")
286
  gr.Markdown("🥘 Culinary Arts Group\n\n🥧 Grandmother's Secrets\n\n🥗 Healthy Eating")
287
 
288
+ # === CENTER COLUMN (Feed) ===
289
  with gr.Column(elem_classes=["col-feed"]):
290
 
291
+ # --- VIEW 1: AI DIGITIZER ---
292
  with gr.Group(visible=True) as digitalizer_view:
293
 
294
+ # SECTION A: USER INPUT (SEPARATE CARD)
295
  with gr.Group(elem_classes=["fb-card"]):
296
  gr.Markdown("### 📸 Digitalize Recipe")
297
+ gr.HTML("<div style='font-size: 13px; color: #65676B; margin-bottom: 10px;'>Upload a photo of a handwritten note to convert it into digital text.</div>")
298
  gr.HTML("<hr style='border:0; border-top:1px solid #e4e6eb; margin: 10px 0;'>")
299
 
300
  with gr.Row():
301
+ input_img = gr.Image(type="filepath", label="Upload Recipe", height=250, container=False)
 
302
 
 
303
  gr.HTML("<div style='height:15px'></div>")
304
  magic_btn = gr.Button("✨ Convert to Text", variant="primary")
305
 
306
+ # Quick Tries - The CSS handles the Pop/Zoom effect
307
  gr.Examples(
308
  examples=[["quick_tries_images/applecrisp.jpg"], ["quick_tries_images/meatballs recipe.jpg"]],
309
+ inputs=input_img, label="Quick Try (Click to load):"
310
  )
311
 
312
+ # SECTION B: TEXT OUTPUT (SEPARATE CARD)
313
  with gr.Group(elem_classes=["fb-card"]):
314
  gr.HTML(f"""
315
  <div class="post-header">
316
  <img src="data:image/jpeg;base64,{profile_b64}" class="user-avatar">
317
  <div class="post-info">
318
  <div class="post-author">CookBook AI</div>
319
+ <div class="post-meta">Just now · <span style="color:blue">Verified</span></div>
320
  </div>
321
  </div>
322
  """)
323
 
324
+ out_text = gr.Textbox(label="Transcription Result", placeholder="Result will appear here...", lines=8, show_label=False)
 
325
 
 
326
  with gr.Row(elem_classes=["post-actions"]):
327
  gr.Button("👍 Like", elem_classes=["action-btn"], size="sm")
328
  gr.Button("💬 Comment", elem_classes=["action-btn"], size="sm")
329
+ gr.Button("📥 Save", elem_classes=["action-btn"], size="sm")
330
 
331
+ # SECTION C: SUGGESTIONS (SEPARATE CARDS)
332
  with gr.Group(visible=True):
333
  gr.Markdown("### Suggested Pairings")
334
 
 
335
  with gr.Group(elem_classes=["fb-card"], visible=False) as c1_box:
336
  sim1 = gr.Markdown("Similar Recipe 1")
337
  with gr.Row(elem_classes=["post-actions"], visible=False) as c1_btns:
338
  gr.Button("Save", elem_classes=["action-btn"], size="sm")
339
 
 
340
  with gr.Group(elem_classes=["fb-card"], visible=False) as c2_box:
341
  sim2 = gr.Markdown("Similar Recipe 2")
342
  with gr.Row(elem_classes=["post-actions"]):
343
  gr.Button("Save", elem_classes=["action-btn"], size="sm")
344
 
 
345
  with gr.Group(elem_classes=["fb-card"], visible=False) as c3_box:
346
  sim3 = gr.Markdown("Similar Recipe 3")
347
  with gr.Row(elem_classes=["post-actions"]):
 
359
  post_time = random.choice(["2h", "3h", "6h", "Yesterday"])
360
 
361
  with gr.Group(elem_classes=["fb-card"]):
 
362
  gr.HTML(f"""
363
  <div class="post-header">
364
  <div class="user-avatar" style="background:#e4e6eb; display:flex; align-items:center; justify-content:center; font-size:20px;">{emoji}</div>
 
371
  gr.Markdown(f"**{row['Title']}**")
372
  gr.Markdown(f"{str(row['Raw_Output'])[:300]}... <span style='color:#1877F2; cursor:pointer;'>See more</span>")
373
 
 
374
  with gr.Row(elem_classes=["post-actions"]):
375
  gr.Button("👍 Like", elem_classes=["action-btn"], size="sm")
376
  gr.Button("💬 Comment", elem_classes=["action-btn"], size="sm")
 
378
  else:
379
  gr.Markdown("⚠️ Database is empty.")
380
 
381
+ # --- VIEW 3: SAVED ---
382
  with gr.Column(visible=False) as saved_view:
383
  gr.Markdown("### 🔖 Saved Items")
384
  if not df_recipes.empty:
 
403
  </div>
404
  """)
405
 
406
+ # === RIGHT COLUMN (Contacts) ===
407
  with gr.Column(elem_classes=["col-right"]):
408
  gr.Markdown("### Sponsored")
409
  with gr.Group(elem_classes=["fb-card"]):
 
413
  gr.HTML("<hr style='border:0; border-top:1px solid #ced0d4; margin: 10px 0;'>")
414
 
415
  gr.Markdown("### Contacts")
 
416
  contacts = ["Elon Musk", "Gordon Ramsay", "Jamie Oliver", "Martha Stewart"]
417
  for contact in contacts:
418
  gr.HTML(f"""
 
426
  """)
427
 
428
  # ==========================================
429
+ # 6. NAVIGATION LOGIC
430
  # ==========================================
431
  def go_digi():
432
  return (