Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,10 +43,18 @@ def image_to_base64(image_path):
|
|
| 43 |
with open(image_path, "rb") as img_file:
|
| 44 |
return base64.b64encode(img_file.read()).decode('utf-8')
|
| 45 |
|
| 46 |
-
#
|
| 47 |
try:
|
|
|
|
| 48 |
logo_b64 = image_to_base64("logo.jpg")
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
process_b64 = image_to_base64("preview of process.jpg")
|
| 51 |
except:
|
| 52 |
logo_b64 = ""
|
|
@@ -145,9 +153,10 @@ footer { display: none !important; }
|
|
| 145 |
.fb-logo {
|
| 146 |
color: #1877F2;
|
| 147 |
font-size: 28px;
|
| 148 |
-
font-weight:
|
| 149 |
letter-spacing: -0.5px;
|
| 150 |
margin-right: 20px;
|
|
|
|
| 151 |
}
|
| 152 |
.fb-search {
|
| 153 |
background: #f0f2f5;
|
|
@@ -165,14 +174,19 @@ footer { display: none !important; }
|
|
| 165 |
.col-feed { width: 600px; max-width: 100%; }
|
| 166 |
.col-right { width: 300px; display: none; }
|
| 167 |
|
| 168 |
-
/* 3. CARD STYLING */
|
| 169 |
.fb-card {
|
| 170 |
background: white;
|
| 171 |
-
border-radius:
|
| 172 |
-
box-shadow: 0
|
| 173 |
-
margin-bottom:
|
| 174 |
overflow: hidden;
|
| 175 |
-
padding:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
}
|
| 177 |
|
| 178 |
/* 4. NAVIGATION BUTTONS */
|
|
@@ -228,14 +242,14 @@ footer { display: none !important; }
|
|
| 228 |
# ==========================================
|
| 229 |
# 5. LAYOUT CONSTRUCTION
|
| 230 |
# ==========================================
|
| 231 |
-
with gr.Blocks(title="
|
| 232 |
|
| 233 |
-
# --- 1.
|
| 234 |
gr.HTML(f"""
|
| 235 |
<div class="fb-navbar">
|
| 236 |
<div style="display:flex; align-items:center;">
|
| 237 |
-
<div class="fb-logo">
|
| 238 |
-
<div class="fb-search">🔍 Search
|
| 239 |
</div>
|
| 240 |
<div style="display:flex; gap:10px;">
|
| 241 |
<div style="width:40px;height:40px;background:#e4e6eb;border-radius:50%;display:flex;align-items:center;justify-content:center;">➕</div>
|
|
@@ -252,11 +266,11 @@ with gr.Blocks(title="Legacy Kitchen", css=facebook_css, theme=theme) as demo:
|
|
| 252 |
with gr.Column(elem_classes=["col-left"]):
|
| 253 |
gr.HTML(f"""
|
| 254 |
<div class="contact-row">
|
| 255 |
-
<img src="data:image/jpeg;base64,{profile_b64}" style="width:36px; height:36px; border-radius:50%;">
|
| 256 |
-
<div class="contact-name">
|
| 257 |
</div>
|
| 258 |
""")
|
| 259 |
-
nav_digital = gr.Button("✨
|
| 260 |
nav_feed = gr.Button("📰 News Feed", elem_classes=["nav-btn"])
|
| 261 |
nav_saved = gr.Button("🔖 Saved Recipes", elem_classes=["nav-btn"])
|
| 262 |
nav_about = gr.Button("ℹ️ About Project", elem_classes=["nav-btn"])
|
|
@@ -268,64 +282,71 @@ with gr.Blocks(title="Legacy Kitchen", css=facebook_css, theme=theme) as demo:
|
|
| 268 |
# === CENTER COLUMN (The Feed & App Logic) ===
|
| 269 |
with gr.Column(elem_classes=["col-feed"]):
|
| 270 |
|
| 271 |
-
# --- VIEW 1: AI DIGITIZER (
|
| 272 |
with gr.Group(visible=True) as digitalizer_view:
|
| 273 |
|
| 274 |
-
#
|
| 275 |
with gr.Group(elem_classes=["fb-card"]):
|
| 276 |
-
gr.Markdown("###
|
|
|
|
| 277 |
gr.HTML("<hr style='border:0; border-top:1px solid #e4e6eb; margin: 10px 0;'>")
|
| 278 |
|
| 279 |
with gr.Row():
|
| 280 |
-
|
|
|
|
| 281 |
|
| 282 |
-
|
| 283 |
-
|
|
|
|
| 284 |
|
| 285 |
-
# Examples
|
| 286 |
gr.Examples(
|
| 287 |
examples=[["quick_tries_images/applecrisp.jpg"], ["quick_tries_images/meatballs recipe.jpg"]],
|
| 288 |
-
inputs=input_img, label="
|
| 289 |
)
|
| 290 |
|
| 291 |
-
#
|
| 292 |
with gr.Group(elem_classes=["fb-card"]):
|
| 293 |
-
gr.HTML("""
|
| 294 |
<div class="post-header">
|
| 295 |
-
<
|
| 296 |
<div class="post-info">
|
| 297 |
-
<div class="post-author">
|
| 298 |
-
<div class="post-meta">Just now ·
|
| 299 |
</div>
|
| 300 |
</div>
|
| 301 |
""")
|
| 302 |
-
out_text = gr.Textbox(label="Transcription Result", placeholder="Your digitized recipe text will appear here...", lines=10, show_label=False)
|
| 303 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
with gr.Row(elem_classes=["post-actions"]):
|
| 305 |
gr.Button("👍 Like", elem_classes=["action-btn"], size="sm")
|
| 306 |
gr.Button("💬 Comment", elem_classes=["action-btn"], size="sm")
|
| 307 |
-
gr.Button("
|
| 308 |
|
| 309 |
-
#
|
| 310 |
-
gr.
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
gr.
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
gr.
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
gr.
|
|
|
|
| 329 |
|
| 330 |
magic_btn.click(ui_update_pipeline, input_img, [out_text, sim1, c1_btns, c2_box, sim2, c3_box, sim3])
|
| 331 |
|
|
@@ -377,7 +398,7 @@ with gr.Blocks(title="Legacy Kitchen", css=facebook_css, theme=theme) as demo:
|
|
| 377 |
# --- VIEW 4: ABOUT ---
|
| 378 |
with gr.Group(visible=False) as about_view:
|
| 379 |
with gr.Group(elem_classes=["fb-card"]):
|
| 380 |
-
gr.Markdown("# About
|
| 381 |
gr.Markdown("Developed by **Shahar Firshtman** and **Lior Feinstein**.")
|
| 382 |
gr.HTML(f"""
|
| 383 |
<div style="margin-top: 20px;">
|
|
|
|
| 43 |
with open(image_path, "rb") as img_file:
|
| 44 |
return base64.b64encode(img_file.read()).decode('utf-8')
|
| 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 = ""
|
|
|
|
| 153 |
.fb-logo {
|
| 154 |
color: #1877F2;
|
| 155 |
font-size: 28px;
|
| 156 |
+
font-weight: 800;
|
| 157 |
letter-spacing: -0.5px;
|
| 158 |
margin-right: 20px;
|
| 159 |
+
font-family: Helvetica, Arial, sans-serif;
|
| 160 |
}
|
| 161 |
.fb-search {
|
| 162 |
background: #f0f2f5;
|
|
|
|
| 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 */
|
|
|
|
| 242 |
# ==========================================
|
| 243 |
# 5. LAYOUT CONSTRUCTION
|
| 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">🔍 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>
|
|
|
|
| 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"])
|
| 274 |
nav_feed = gr.Button("📰 News Feed", elem_classes=["nav-btn"])
|
| 275 |
nav_saved = gr.Button("🔖 Saved Recipes", elem_classes=["nav-btn"])
|
| 276 |
nav_about = gr.Button("ℹ️ About Project", elem_classes=["nav-btn"])
|
|
|
|
| 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"]):
|
| 349 |
+
gr.Button("Save", elem_classes=["action-btn"], size="sm")
|
| 350 |
|
| 351 |
magic_btn.click(ui_update_pipeline, input_img, [out_text, sim1, c1_btns, c2_box, sim2, c3_box, sim3])
|
| 352 |
|
|
|
|
| 398 |
# --- VIEW 4: ABOUT ---
|
| 399 |
with gr.Group(visible=False) as about_view:
|
| 400 |
with gr.Group(elem_classes=["fb-card"]):
|
| 401 |
+
gr.Markdown("# About CookBook")
|
| 402 |
gr.Markdown("Developed by **Shahar Firshtman** and **Lior Feinstein**.")
|
| 403 |
gr.HTML(f"""
|
| 404 |
<div style="margin-top: 20px;">
|