Liori25 commited on
Commit
39198c6
·
verified ·
1 Parent(s): 6750a8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -111
app.py CHANGED
@@ -129,7 +129,7 @@ def ui_update_pipeline(image_path):
129
  return f"Error: {e}", "Error", gr.update(), gr.update(), "", gr.update(), ""
130
 
131
  # ==========================================
132
- # 4. PREMIUM UI THEME & CSS
133
  # ==========================================
134
  theme = gr.themes.Default(
135
  primary_hue="blue",
@@ -137,27 +137,14 @@ theme = gr.themes.Default(
137
  font=['Helvetica', 'Arial', 'sans-serif']
138
  )
139
 
140
- # Inspired by the Professor's Netflix code, but adapted for Facebook Light Mode
141
  facebook_css = """
142
- :root {
143
- --fb-bg: #f0f2f5;
144
- --fb-white: #ffffff;
145
- --fb-blue: #1877F2;
146
- --fb-text: #050505;
147
- --fb-gray: #65676B;
148
- --fb-hover: #f2f2f2;
149
- --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
150
- --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
151
- }
152
-
153
- body { background-color: var(--fb-bg); margin: 0; padding: 0; color: var(--fb-text); }
154
- .gradio-container { background-color: var(--fb-bg) !important; max-width: 100% !important; margin: 0 !important; padding: 0 !important; }
155
  footer { display: none !important; }
156
 
157
- /* 1. GLASSMORPHISM NAVBAR */
158
  .fb-navbar {
159
- background: rgba(255, 255, 255, 0.95);
160
- backdrop-filter: blur(10px); /* The Netflix effect */
161
  height: 56px;
162
  padding: 0 16px;
163
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
@@ -167,29 +154,24 @@ footer { display: none !important; }
167
  top: 0;
168
  z-index: 999;
169
  justify-content: space-between;
170
- border-bottom: 1px solid rgba(0,0,0,0.05);
171
  }
172
  .fb-logo {
173
- color: var(--fb-blue);
174
  font-size: 28px;
175
  font-weight: 800;
176
  letter-spacing: -0.5px;
177
  margin-right: 20px;
178
  font-family: Helvetica, Arial, sans-serif;
179
- text-shadow: 0 2px 10px rgba(24, 119, 242, 0.2);
180
  }
181
  .fb-search {
182
  background: #f0f2f5;
183
  border-radius: 50px;
184
  padding: 10px 20px;
185
- color: var(--fb-gray);
186
  width: 250px;
187
  display: flex;
188
  align-items: center;
189
- border: 1px solid transparent;
190
- transition: all 0.2s ease;
191
  }
192
- .fb-search:hover { background: #e4e6eb; }
193
 
194
  /* 2. LAYOUT COLUMNS */
195
  .main-layout {
@@ -200,58 +182,49 @@ footer { display: none !important; }
200
  max-width: 1600px;
201
  margin: 0 auto;
202
  }
203
- .col-left { width: 220px !important; min-width: 220px !important; flex-shrink: 0; display: none; }
 
204
  .col-feed { flex-grow: 1; min-width: 600px; max-width: 1000px; }
205
- .col-right { width: 280px !important; min-width: 280px !important; flex-shrink: 0; display: none; }
206
 
207
- /* 3. PREMIUM CARD STYLING */
208
  .fb-card {
209
- background: var(--fb-white);
210
- border-radius: 12px;
211
- box-shadow: var(--shadow-sm);
212
  margin-bottom: 25px;
213
  overflow: hidden;
214
  padding: 16px;
215
- border: 1px solid rgba(0,0,0,0.08);
216
- transition: transform 0.2s ease, box-shadow 0.2s ease;
217
- }
218
- /* Subtle interaction */
219
- .fb-card:hover {
220
- box-shadow: var(--shadow-md);
221
  }
222
 
223
  /* 4. NAVIGATION BUTTONS */
224
  .nav-btn {
225
  width: 100% !important;
226
- height: 48px !important; /* Slightly taller */
227
  text-align: left !important;
228
  justify-content: flex-start !important;
229
  background: transparent !important;
230
  border: none !important;
231
  box-shadow: none !important;
232
- color: var(--fb-text) !important;
233
  font-weight: 600 !important;
234
  font-size: 15px !important;
235
  padding: 0 12px !important;
236
- border-radius: 10px !important;
237
  margin-bottom: 5px !important;
238
  display: flex !important;
239
  align-items: center !important;
240
- transition: background-color 0.2s;
241
  }
242
  .nav-btn:hover { background-color: #e4e6eb !important; }
243
- .nav-btn.selected { background-color: #e7f3ff !important; color: var(--fb-blue) !important; }
244
 
245
  /* 5. POST HEADER */
246
  .post-header { display: flex; align-items: center; margin-bottom: 12px; }
247
- .user-avatar {
248
- width: 40px; height: 40px; border-radius: 50%;
249
- background: #ddd; margin-right: 10px; object-fit: cover;
250
- border: 1px solid rgba(0,0,0,0.1);
251
- }
252
  .post-info { display: flex; flex-direction: column; }
253
- .post-author { font-weight: 600; color: var(--fb-text); font-size: 15px; }
254
- .post-meta { font-size: 13px; color: var(--fb-gray); }
255
 
256
  /* 6. POST ACTIONS */
257
  .post-actions {
@@ -261,54 +234,48 @@ footer { display: none !important; }
261
  display: flex;
262
  justify-content: space-around;
263
  }
264
- .action-btn {
265
- background: transparent !important;
266
- color: var(--fb-gray) !important;
267
- box-shadow: none !important;
268
- font-weight: 600 !important;
269
- transition: background 0.2s !important;
270
- }
271
- .action-btn:hover { background: #f2f2f2 !important; border-radius: 6px; }
272
 
273
  /* 7. CONTACTS */
274
  .contact-row {
275
- display: flex; align-items: center; padding: 10px; border-radius: 8px; cursor: pointer; transition: background 0.2s;
276
  }
277
  .contact-row:hover { background-color: #e4e6eb; }
278
- .contact-name { font-weight: 500; font-size: 14px; margin-left: 12px; color: var(--fb-text); }
279
- .profile-row { display: flex; align-items: center; padding: 10px; border-radius: 8px; }
280
-
281
- /* 8. STORIES / QUICK TRIES (The Premium Improvement) */
282
- /* This makes the gallery look like "Stories" */
283
- button.gallery-item {
284
- border: none !important;
285
- background: transparent !important;
286
- padding: 6px !important;
287
- overflow: visible !important;
288
- }
289
  button.gallery-item img {
290
- width: 120px !important;
291
- height: 120px !important;
292
- border-radius: 15px !important; /* Rounded Rectangle like Stories */
293
- transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important; /* Bouncy effect */
294
- object-fit: cover;
295
- box-shadow: 0 4px 6px rgba(0,0,0,0.1);
296
- border: 3px solid white;
297
- outline: 2px solid var(--fb-blue); /* Facebook Story Ring */
298
  }
299
  button.gallery-item:hover img {
300
- transform: scale(1.1) rotate(2deg) !important;
301
- box-shadow: 0 10px 20px rgba(24, 119, 242, 0.4) !important;
302
- z-index: 100;
303
  }
304
 
305
  /* 9. SEE MORE LOGIC */
306
  details[open] > summary { display: none !important; }
307
 
308
- /* UTILS */
309
- .sim-scroll { height: 200px; overflow-y: auto; font-size: 13px; color: var(--fb-text); scrollbar-width: thin; }
310
- .suggested-header { font-size: 12px; font-weight: bold; color: var(--fb-gray); margin-bottom: 5px; }
 
 
 
 
 
 
 
 
 
 
 
311
 
 
 
 
312
  @media (min-width: 1100px) { .col-left, .col-right { display: block; } }
313
  """
314
 
@@ -324,10 +291,10 @@ with gr.Blocks(title="CookBook") as demo:
324
  <div class="fb-logo">CookBook</div>
325
  <div class="fb-search">🔍 &nbsp; Search Recipe...</div>
326
  </div>
327
- <div style="display:flex; gap:12px;">
328
- <div style="width:40px;height:40px;background:#e4e6eb;border-radius:50%;display:flex;align-items:center;justify-content:center;cursor:pointer;">➕</div>
329
- <div style="width:40px;height:40px;background:#e4e6eb;border-radius:50%;display:flex;align-items:center;justify-content:center;cursor:pointer;">💬</div>
330
- <img src="data:image/jpeg;base64,{profile_b64}" style="width:40px; height:40px; border-radius:50%; object-fit:cover; border:1px solid #ddd; cursor:pointer;">
331
  </div>
332
  </div>
333
  """)
@@ -343,16 +310,22 @@ with gr.Blocks(title="CookBook") as demo:
343
  <div class="contact-name">Welcome Chef</div>
344
  </div>
345
  """)
346
- gr.HTML("<hr style='border:0; border-top:1px solid #ced0d4; margin: 8px 10px 16px 10px;'>")
347
 
348
  nav_digital = gr.Button("✨ Digitalize Recipe", elem_classes=["nav-btn", "selected"])
349
  nav_feed = gr.Button("📰 News Feed", elem_classes=["nav-btn"])
350
  nav_saved = gr.Button("🔖 Saved Recipes", elem_classes=["nav-btn"])
351
  nav_about = gr.Button("ℹ️ About Project", elem_classes=["nav-btn"])
352
 
353
- gr.HTML("<hr style='border:0; border-top:1px solid #ced0d4; margin: 16px 10px;'>")
354
- gr.Markdown("### Your Shortcuts")
355
- gr.Markdown("🥘 Culinary Arts Group\n\n🥧 Grandmother's Secrets\n\n🥗 Healthy Eating")
 
 
 
 
 
 
356
 
357
  # === CENTER COLUMN (Feed) ===
358
  with gr.Column(elem_classes=["col-feed"]):
@@ -363,27 +336,34 @@ with gr.Blocks(title="CookBook") as demo:
363
  # SECTION A: USER INPUT
364
  with gr.Group(elem_classes=["fb-card"]):
365
  gr.Markdown("### 📸 Digitalize Recipe")
366
- gr.HTML("<div style='font-size: 13px; color: #65676B; margin-bottom: 12px;'>Upload a photo of a handwritten note to convert it into digital text.</div>")
367
- gr.HTML("<hr style='border:0; border-top:1px solid #e4e6eb; margin: 0 0 16px 0;'>")
368
 
369
  with gr.Row():
370
- input_img = gr.Image(type="filepath", label="Upload Recipe", height=250, container=False)
 
 
 
 
 
 
 
 
 
 
 
371
 
372
- gr.HTML("<div style='height:20px'></div>")
373
- gr.Markdown("#### Quick Tries (Stories)")
374
 
375
- # 1. Quick Start Images (Styled as Stories)
376
  gr.Examples(
377
  examples=[
378
  ["quick_tries_images/applecrisp.jpg"],
379
  ["quick_tries_images/chocolateballs.png"],
380
  ["quick_tries_images/tofu.jfif"]
381
  ],
382
- inputs=input_img, label=None
383
  )
384
- gr.HTML("<div style='height:15px'></div>")
385
-
386
- # 2. Convert Button (Styled Primary)
387
  magic_btn = gr.Button("✨ Convert to Text", variant="primary")
388
 
389
  # --- 9 PIXEL SPACER ---
@@ -408,7 +388,7 @@ with gr.Blocks(title="CookBook") as demo:
408
  gr.Button("💬 Comment", elem_classes=["action-btn"], size="sm")
409
  gr.Button("📥 Save", elem_classes=["action-btn"], size="sm")
410
 
411
- # SECTION C: SUGGESTIONS (SEPARATE DIV/GROUP)
412
  with gr.Group(visible=True):
413
  gr.HTML("<br><hr style='border:0; border-top:1px solid #ced0d4; margin: 15px 0;'><br>")
414
  gr.Markdown("### Suggested Pairings")
@@ -442,8 +422,12 @@ with gr.Blocks(title="CookBook") as demo:
442
  post_time = random.choice(["2h", "3h", "6h", "Yesterday"])
443
 
444
  full_content = str(row['Raw_Output'])
445
- preview_text = full_content[:200]
446
- hidden_text = full_content[200:]
 
 
 
 
447
 
448
  with gr.Group(elem_classes=["fb-card"]):
449
  gr.HTML(f"""
@@ -457,13 +441,7 @@ with gr.Blocks(title="CookBook") as demo:
457
  """)
458
  gr.Markdown(f"**{row['Title']}**")
459
  gr.HTML(f"""
460
- <div style="font-family: inherit; font-size: 14px; line-height: 1.5;">
461
- {preview_text}
462
- <details style="display:inline;">
463
- <summary style="cursor:pointer; color:#1877F2; font-weight:600; list-style:none; display:inline;">... See more</summary>
464
- <span style="display:inline;">{hidden_text}</span>
465
- </details>
466
- </div>
467
  """)
468
 
469
  with gr.Row(elem_classes=["post-actions"]):
 
129
  return f"Error: {e}", "Error", gr.update(), gr.update(), "", gr.update(), ""
130
 
131
  # ==========================================
132
+ # 4. UI THEME & CSS
133
  # ==========================================
134
  theme = gr.themes.Default(
135
  primary_hue="blue",
 
137
  font=['Helvetica', 'Arial', 'sans-serif']
138
  )
139
 
 
140
  facebook_css = """
141
+ body { background-color: #f0f2f5; margin: 0; padding: 0; }
142
+ .gradio-container { background-color: #f0f2f5 !important; max-width: 100% !important; margin: 0 !important; padding: 0 !important; }
 
 
 
 
 
 
 
 
 
 
 
143
  footer { display: none !important; }
144
 
145
+ /* 1. STICKY NAVBAR */
146
  .fb-navbar {
147
+ background: white;
 
148
  height: 56px;
149
  padding: 0 16px;
150
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
 
154
  top: 0;
155
  z-index: 999;
156
  justify-content: space-between;
 
157
  }
158
  .fb-logo {
159
+ color: #1877F2;
160
  font-size: 28px;
161
  font-weight: 800;
162
  letter-spacing: -0.5px;
163
  margin-right: 20px;
164
  font-family: Helvetica, Arial, sans-serif;
 
165
  }
166
  .fb-search {
167
  background: #f0f2f5;
168
  border-radius: 50px;
169
  padding: 10px 20px;
170
+ color: #65676B;
171
  width: 250px;
172
  display: flex;
173
  align-items: center;
 
 
174
  }
 
175
 
176
  /* 2. LAYOUT COLUMNS */
177
  .main-layout {
 
182
  max-width: 1600px;
183
  margin: 0 auto;
184
  }
185
+
186
+ .col-left { width: 200px !important; min-width: 200px !important; flex-shrink: 0; display: none; }
187
  .col-feed { flex-grow: 1; min-width: 600px; max-width: 1000px; }
188
+ .col-right { width: 240px !important; min-width: 240px !important; flex-shrink: 0; display: none; }
189
 
190
+ /* 3. CARD STYLING */
191
  .fb-card {
192
+ background: white;
193
+ border-radius: 10px;
194
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
195
  margin-bottom: 25px;
196
  overflow: hidden;
197
  padding: 16px;
198
+ border: 1px solid #e4e6eb;
 
 
 
 
 
199
  }
200
 
201
  /* 4. NAVIGATION BUTTONS */
202
  .nav-btn {
203
  width: 100% !important;
204
+ height: 42.5px !important;
205
  text-align: left !important;
206
  justify-content: flex-start !important;
207
  background: transparent !important;
208
  border: none !important;
209
  box-shadow: none !important;
210
+ color: #050505 !important;
211
  font-weight: 600 !important;
212
  font-size: 15px !important;
213
  padding: 0 12px !important;
214
+ border-radius: 8px !important;
215
  margin-bottom: 5px !important;
216
  display: flex !important;
217
  align-items: center !important;
 
218
  }
219
  .nav-btn:hover { background-color: #e4e6eb !important; }
220
+ .nav-btn.selected { background-color: #e7f3ff !important; color: #1877f2 !important; }
221
 
222
  /* 5. POST HEADER */
223
  .post-header { display: flex; align-items: center; margin-bottom: 12px; }
224
+ .user-avatar { width: 40px; height: 40px; border-radius: 50%; background: #ddd; margin-right: 10px; object-fit: cover; }
 
 
 
 
225
  .post-info { display: flex; flex-direction: column; }
226
+ .post-author { font-weight: 600; color: #050505; font-size: 15px; }
227
+ .post-meta { font-size: 13px; color: #65676B; }
228
 
229
  /* 6. POST ACTIONS */
230
  .post-actions {
 
234
  display: flex;
235
  justify-content: space-around;
236
  }
237
+ .action-btn { background: transparent !important; color: #65676B !important; box-shadow: none !important; }
238
+ .action-btn:hover { background: #f2f2f2 !important; }
 
 
 
 
 
 
239
 
240
  /* 7. CONTACTS */
241
  .contact-row {
242
+ display: flex; align-items: center; padding: 8px; border-radius: 8px; cursor: pointer;
243
  }
244
  .contact-row:hover { background-color: #e4e6eb; }
245
+ .contact-name { font-weight: 500; font-size: 14px; margin-left: 10px; color: #050505; }
246
+ .profile-row { display: flex; align-items: center; padding: 8px; border-radius: 8px; }
247
+
248
+ /* 8. EXAMPLES */
249
+ button.gallery-item { border: none !important; background: transparent !important; padding: 4px !important; }
 
 
 
 
 
 
250
  button.gallery-item img {
251
+ width: 110px !important; height: 110px !important; border-radius: 12px !important;
252
+ transition: all 0.3s ease !important; object-fit: cover; box-shadow: 0 2px 5px rgba(0,0,0,0.1);
 
 
 
 
 
 
253
  }
254
  button.gallery-item:hover img {
255
+ transform: scale(1.15) !important; box-shadow: 0 8px 15px rgba(24, 119, 242, 0.3) !important; z-index: 10;
 
 
256
  }
257
 
258
  /* 9. SEE MORE LOGIC */
259
  details[open] > summary { display: none !important; }
260
 
261
+ /* 10. MODERN UPLOAD IMAGE (No border dashed, clean look) */
262
+ .modern-image-container button {
263
+ border-radius: 8px !important;
264
+ overflow: hidden !important;
265
+ border: 1px solid #e4e6eb !important;
266
+ box-shadow: 0 1px 2px rgba(0,0,0,0.05) !important;
267
+ padding: 0 !important;
268
+ }
269
+ .modern-image-container img {
270
+ border-radius: 8px !important;
271
+ width: 100% !important;
272
+ max-height: 400px !important;
273
+ object-fit: cover !important;
274
+ }
275
 
276
+ /* UTILS */
277
+ .sim-scroll { height: 200px; overflow-y: auto; font-size: 13px; color: #050505; }
278
+ .suggested-header { font-size: 12px; font-weight: bold; color: #65676B; margin-bottom: 5px; }
279
  @media (min-width: 1100px) { .col-left, .col-right { display: block; } }
280
  """
281
 
 
291
  <div class="fb-logo">CookBook</div>
292
  <div class="fb-search">🔍 &nbsp; Search Recipe...</div>
293
  </div>
294
+ <div style="display:flex; gap:10px;">
295
+ <div style="width:40px;height:40px;background:#e4e6eb;border-radius:50%;display:flex;align-items:center;justify-content:center;">➕</div>
296
+ <div style="width:40px;height:40px;background:#e4e6eb;border-radius:50%;display:flex;align-items:center;justify-content:center;">💬</div>
297
+ <img src="data:image/jpeg;base64,{profile_b64}" style="width:40px; height:40px; border-radius:50%; object-fit:cover;">
298
  </div>
299
  </div>
300
  """)
 
310
  <div class="contact-name">Welcome Chef</div>
311
  </div>
312
  """)
313
+ gr.HTML("<hr style='border:0; border-top:1px solid #ced0d4; margin: 10px 0;'>")
314
 
315
  nav_digital = gr.Button("✨ Digitalize Recipe", elem_classes=["nav-btn", "selected"])
316
  nav_feed = gr.Button("📰 News Feed", elem_classes=["nav-btn"])
317
  nav_saved = gr.Button("🔖 Saved Recipes", elem_classes=["nav-btn"])
318
  nav_about = gr.Button("ℹ️ About Project", elem_classes=["nav-btn"])
319
 
320
+ gr.HTML("<hr style='border:0; border-top:1px solid #ced0d4; margin: 10px 0;'>")
321
+
322
+ gr.HTML("""
323
+ <div style="color: #65676B; font-size: 13px; margin-top: 10px; padding-left: 10px;">
324
+ <div style="margin-bottom: 8px; cursor: pointer; font-weight: 500;">Support</div>
325
+ <div style="margin-bottom: 8px; cursor: pointer; font-weight: 500;">Terms of use</div>
326
+ <div>© 2025 All rights preserved</div>
327
+ </div>
328
+ """)
329
 
330
  # === CENTER COLUMN (Feed) ===
331
  with gr.Column(elem_classes=["col-feed"]):
 
336
  # SECTION A: USER INPUT
337
  with gr.Group(elem_classes=["fb-card"]):
338
  gr.Markdown("### 📸 Digitalize Recipe")
339
+ 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>")
340
+ gr.HTML("<hr style='border:0; border-top:1px solid #e4e6eb; margin: 10px 0;'>")
341
 
342
  with gr.Row():
343
+ # Added class for Facebook-like Image Style
344
+ input_img = gr.Image(
345
+ type="filepath",
346
+ label="Upload Recipe",
347
+ height=300,
348
+ container=False,
349
+ elem_classes=["modern-image-container"],
350
+ sources=["upload"], # REMOVES WEBCAM
351
+ show_download_button=False, # REMOVES COPY/DOWNLOAD
352
+ show_share_button=False,
353
+ interactive=True
354
+ )
355
 
356
+ gr.HTML("<div style='height:15px'></div>")
 
357
 
 
358
  gr.Examples(
359
  examples=[
360
  ["quick_tries_images/applecrisp.jpg"],
361
  ["quick_tries_images/chocolateballs.png"],
362
  ["quick_tries_images/tofu.jfif"]
363
  ],
364
+ inputs=input_img, label="Quick Try (Click to load):"
365
  )
366
+ gr.HTML("<div style='height:10px'></div>")
 
 
367
  magic_btn = gr.Button("✨ Convert to Text", variant="primary")
368
 
369
  # --- 9 PIXEL SPACER ---
 
388
  gr.Button("💬 Comment", elem_classes=["action-btn"], size="sm")
389
  gr.Button("📥 Save", elem_classes=["action-btn"], size="sm")
390
 
391
+ # SECTION C: SUGGESTIONS
392
  with gr.Group(visible=True):
393
  gr.HTML("<br><hr style='border:0; border-top:1px solid #ced0d4; margin: 15px 0;'><br>")
394
  gr.Markdown("### Suggested Pairings")
 
422
  post_time = random.choice(["2h", "3h", "6h", "Yesterday"])
423
 
424
  full_content = str(row['Raw_Output'])
425
+ # Smart Split
426
+ split_idx = full_content[:200].rfind(" ")
427
+ if split_idx == -1: split_idx = 200
428
+
429
+ preview_text = full_content[:split_idx]
430
+ hidden_text = full_content[split_idx:]
431
 
432
  with gr.Group(elem_classes=["fb-card"]):
433
  gr.HTML(f"""
 
441
  """)
442
  gr.Markdown(f"**{row['Title']}**")
443
  gr.HTML(f"""
444
+ <div style="font-family: inherit; font-size: 14px; white-space: pre-wrap;">{preview_text}<details style="display:inline;"><summary style="cursor:pointer; color:#1877F2; font-weight:600; list-style:none; display:inline;">... See more</summary><span style="display:inline;">{hidden_text}</span></details></div>
 
 
 
 
 
 
445
  """)
446
 
447
  with gr.Row(elem_classes=["post-actions"]):