Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,11 +39,11 @@ except Exception as e:
|
|
| 39 |
# ==========================================
|
| 40 |
def image_to_base64(image_path):
|
| 41 |
if not os.path.exists(image_path):
|
| 42 |
-
return "
|
| 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 |
profile_b64 = image_to_base64("232px-Tv_the_muppet_show_bein_green.jpg")
|
|
@@ -54,7 +54,7 @@ except:
|
|
| 54 |
process_b64 = ""
|
| 55 |
|
| 56 |
# ==========================================
|
| 57 |
-
# 3. BACKEND LOGIC
|
| 58 |
# ==========================================
|
| 59 |
def get_embedding_via_api(text):
|
| 60 |
if not client: raise ValueError("HF_TOKEN missing")
|
|
@@ -118,7 +118,6 @@ def ui_update_pipeline(image_path):
|
|
| 118 |
# ==========================================
|
| 119 |
# 4. FACEBOOK UI THEME & CSS
|
| 120 |
# ==========================================
|
| 121 |
-
# We override the theme to be neutral so our CSS takes over
|
| 122 |
theme = gr.themes.Default(
|
| 123 |
primary_hue="blue",
|
| 124 |
radius_size="sm",
|
|
@@ -128,6 +127,7 @@ theme = gr.themes.Default(
|
|
| 128 |
facebook_css = """
|
| 129 |
body { background-color: #f0f2f5; margin: 0; padding: 0; }
|
| 130 |
.gradio-container { background-color: #f0f2f5 !important; max-width: 100% !important; margin: 0 !important; padding: 0 !important; }
|
|
|
|
| 131 |
|
| 132 |
/* 1. STICKY NAVBAR */
|
| 133 |
.fb-navbar {
|
|
@@ -165,7 +165,7 @@ body { background-color: #f0f2f5; margin: 0; padding: 0; }
|
|
| 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: 8px;
|
|
@@ -174,9 +174,8 @@ body { background-color: #f0f2f5; margin: 0; padding: 0; }
|
|
| 174 |
overflow: hidden;
|
| 175 |
padding: 12px 16px;
|
| 176 |
}
|
| 177 |
-
.no-padding { padding: 0 !important; }
|
| 178 |
|
| 179 |
-
/* 4. NAVIGATION BUTTONS
|
| 180 |
.nav-btn {
|
| 181 |
text-align: left !important;
|
| 182 |
justify-content: flex-start !important;
|
|
@@ -193,14 +192,14 @@ body { background-color: #f0f2f5; margin: 0; padding: 0; }
|
|
| 193 |
.nav-btn:hover { background-color: #e4e6eb !important; }
|
| 194 |
.nav-btn.selected { background-color: #e7f3ff !important; color: #1877f2 !important; }
|
| 195 |
|
| 196 |
-
/* 5. POST HEADER
|
| 197 |
.post-header { display: flex; align-items: center; margin-bottom: 12px; }
|
| 198 |
.user-avatar { width: 40px; height: 40px; border-radius: 50%; background: #ddd; margin-right: 10px; object-fit: cover; }
|
| 199 |
.post-info { display: flex; flex-direction: column; }
|
| 200 |
.post-author { font-weight: 600; color: #050505; font-size: 15px; }
|
| 201 |
.post-meta { font-size: 13px; color: #65676B; }
|
| 202 |
|
| 203 |
-
/* 6. POST ACTIONS
|
| 204 |
.post-actions {
|
| 205 |
border-top: 1px solid #ced0d4;
|
| 206 |
margin-top: 10px;
|
|
@@ -211,7 +210,7 @@ body { background-color: #f0f2f5; margin: 0; padding: 0; }
|
|
| 211 |
.action-btn { background: transparent !important; color: #65676B !important; box-shadow: none !important; }
|
| 212 |
.action-btn:hover { background: #f2f2f2 !important; }
|
| 213 |
|
| 214 |
-
/* 7.
|
| 215 |
.contact-row {
|
| 216 |
display: flex; align-items: center; padding: 8px; border-radius: 8px; cursor: pointer;
|
| 217 |
}
|
|
@@ -283,7 +282,7 @@ with gr.Blocks(title="Legacy Kitchen", css=facebook_css, theme=theme) as demo:
|
|
| 283 |
gr.HTML("<div style='margin-top:10px; font-size:14px; color:#65676B;'>Add to your post: 🟢 Photo/Video 👤 Tag People 📍 Location</div>")
|
| 284 |
magic_btn = gr.Button("Post", variant="primary") # Blue button
|
| 285 |
|
| 286 |
-
# Examples
|
| 287 |
gr.Examples(
|
| 288 |
examples=[["quick_tries_images/applecrisp.jpg"], ["quick_tries_images/meatballs recipe.jpg"]],
|
| 289 |
inputs=input_img, label="Quick Try (Click to load image)"
|
|
@@ -332,7 +331,7 @@ with gr.Blocks(title="Legacy Kitchen", css=facebook_css, theme=theme) as demo:
|
|
| 332 |
|
| 333 |
# --- VIEW 2: FEED ---
|
| 334 |
with gr.Column(visible=False) as feed_view:
|
| 335 |
-
if
|
| 336 |
feed_samples = df_recipes.sample(10)
|
| 337 |
for index, row in feed_samples.iterrows():
|
| 338 |
user_name = random.choice(["Grandma Rose", "Chef Mike", "Sarah J."])
|
|
|
|
| 39 |
# ==========================================
|
| 40 |
def image_to_base64(image_path):
|
| 41 |
if not os.path.exists(image_path):
|
| 42 |
+
return ""
|
| 43 |
with open(image_path, "rb") as img_file:
|
| 44 |
return base64.b64encode(img_file.read()).decode('utf-8')
|
| 45 |
|
| 46 |
+
# Load local images if they exist, otherwise use placeholders
|
| 47 |
try:
|
| 48 |
logo_b64 = image_to_base64("logo.jpg")
|
| 49 |
profile_b64 = image_to_base64("232px-Tv_the_muppet_show_bein_green.jpg")
|
|
|
|
| 54 |
process_b64 = ""
|
| 55 |
|
| 56 |
# ==========================================
|
| 57 |
+
# 3. BACKEND LOGIC
|
| 58 |
# ==========================================
|
| 59 |
def get_embedding_via_api(text):
|
| 60 |
if not client: raise ValueError("HF_TOKEN missing")
|
|
|
|
| 118 |
# ==========================================
|
| 119 |
# 4. FACEBOOK UI THEME & CSS
|
| 120 |
# ==========================================
|
|
|
|
| 121 |
theme = gr.themes.Default(
|
| 122 |
primary_hue="blue",
|
| 123 |
radius_size="sm",
|
|
|
|
| 127 |
facebook_css = """
|
| 128 |
body { background-color: #f0f2f5; margin: 0; padding: 0; }
|
| 129 |
.gradio-container { background-color: #f0f2f5 !important; max-width: 100% !important; margin: 0 !important; padding: 0 !important; }
|
| 130 |
+
footer { display: none !important; }
|
| 131 |
|
| 132 |
/* 1. STICKY NAVBAR */
|
| 133 |
.fb-navbar {
|
|
|
|
| 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: 8px;
|
|
|
|
| 174 |
overflow: hidden;
|
| 175 |
padding: 12px 16px;
|
| 176 |
}
|
|
|
|
| 177 |
|
| 178 |
+
/* 4. NAVIGATION BUTTONS */
|
| 179 |
.nav-btn {
|
| 180 |
text-align: left !important;
|
| 181 |
justify-content: flex-start !important;
|
|
|
|
| 192 |
.nav-btn:hover { background-color: #e4e6eb !important; }
|
| 193 |
.nav-btn.selected { background-color: #e7f3ff !important; color: #1877f2 !important; }
|
| 194 |
|
| 195 |
+
/* 5. POST HEADER */
|
| 196 |
.post-header { display: flex; align-items: center; margin-bottom: 12px; }
|
| 197 |
.user-avatar { width: 40px; height: 40px; border-radius: 50%; background: #ddd; margin-right: 10px; object-fit: cover; }
|
| 198 |
.post-info { display: flex; flex-direction: column; }
|
| 199 |
.post-author { font-weight: 600; color: #050505; font-size: 15px; }
|
| 200 |
.post-meta { font-size: 13px; color: #65676B; }
|
| 201 |
|
| 202 |
+
/* 6. POST ACTIONS */
|
| 203 |
.post-actions {
|
| 204 |
border-top: 1px solid #ced0d4;
|
| 205 |
margin-top: 10px;
|
|
|
|
| 210 |
.action-btn { background: transparent !important; color: #65676B !important; box-shadow: none !important; }
|
| 211 |
.action-btn:hover { background: #f2f2f2 !important; }
|
| 212 |
|
| 213 |
+
/* 7. CONTACTS */
|
| 214 |
.contact-row {
|
| 215 |
display: flex; align-items: center; padding: 8px; border-radius: 8px; cursor: pointer;
|
| 216 |
}
|
|
|
|
| 282 |
gr.HTML("<div style='margin-top:10px; font-size:14px; color:#65676B;'>Add to your post: 🟢 Photo/Video 👤 Tag People 📍 Location</div>")
|
| 283 |
magic_btn = gr.Button("Post", variant="primary") # Blue button
|
| 284 |
|
| 285 |
+
# Examples
|
| 286 |
gr.Examples(
|
| 287 |
examples=[["quick_tries_images/applecrisp.jpg"], ["quick_tries_images/meatballs recipe.jpg"]],
|
| 288 |
inputs=input_img, label="Quick Try (Click to load image)"
|
|
|
|
| 331 |
|
| 332 |
# --- VIEW 2: FEED ---
|
| 333 |
with gr.Column(visible=False) as feed_view:
|
| 334 |
+
if not df_recipes.empty:
|
| 335 |
feed_samples = df_recipes.sample(10)
|
| 336 |
for index, row in feed_samples.iterrows():
|
| 337 |
user_name = random.choice(["Grandma Rose", "Chef Mike", "Sarah J."])
|