Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,6 +25,7 @@ try:
|
|
| 25 |
if isinstance(data, dict):
|
| 26 |
stored_embeddings = np.array(data['embeddings'])
|
| 27 |
elif isinstance(data, pd.DataFrame):
|
|
|
|
| 28 |
target_col = next((c for c in ['embedding', 'embeddings', 'vectors'] if c in data.columns), None)
|
| 29 |
stored_embeddings = np.vstack(data[target_col].values) if target_col else data
|
| 30 |
else:
|
|
@@ -36,7 +37,7 @@ except Exception as e:
|
|
| 36 |
stored_embeddings = None
|
| 37 |
|
| 38 |
# ==========================================
|
| 39 |
-
# 2. HELPER: IMAGE TO BASE64
|
| 40 |
# ==========================================
|
| 41 |
def image_to_base64(image_path):
|
| 42 |
if not os.path.exists(image_path):
|
|
@@ -99,9 +100,7 @@ body {background-color: #f0f2f5 !important; font-family: Helvetica, Arial, sans-
|
|
| 99 |
.fb-header {
|
| 100 |
background-color: #ffffff;
|
| 101 |
color: #1877f2;
|
| 102 |
-
padding:
|
| 103 |
-
font-size: 28px;
|
| 104 |
-
font-weight: 900;
|
| 105 |
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 106 |
border-bottom: 1px solid #ddd;
|
| 107 |
margin-bottom: 20px;
|
|
@@ -111,10 +110,30 @@ body {background-color: #f0f2f5 !important; font-family: Helvetica, Arial, sans-
|
|
| 111 |
|
| 112 |
.logo-img {
|
| 113 |
height: 40px;
|
|
|
|
|
|
|
| 114 |
margin-right: 15px;
|
| 115 |
border-radius: 5px;
|
| 116 |
}
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
.sidebar-btn {
|
| 119 |
background-color: transparent !important;
|
| 120 |
color: #050505 !important;
|
|
@@ -152,12 +171,14 @@ body {background-color: #f0f2f5 !important; font-family: Helvetica, Arial, sans-
|
|
| 152 |
# ==========================================
|
| 153 |
with gr.Blocks(css=fb_css, title="Legacy Kitchen") as demo:
|
| 154 |
|
| 155 |
-
# --- HEADER
|
| 156 |
-
# We inject the Base64 string directly into the HTML
|
| 157 |
gr.HTML(f"""
|
| 158 |
<div class="fb-header">
|
| 159 |
<img src="data:image/jpeg;base64,{logo_b64}" class="logo-img" alt="Logo">
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
| 161 |
</div>
|
| 162 |
""")
|
| 163 |
|
|
@@ -169,7 +190,9 @@ with gr.Blocks(css=fb_css, title="Legacy Kitchen") as demo:
|
|
| 169 |
|
| 170 |
nav_feed = gr.Button("馃摪 Feed", elem_classes=["sidebar-btn"])
|
| 171 |
nav_digital = gr.Button("馃摳 Digitizer", elem_classes=["sidebar-btn"])
|
| 172 |
-
|
|
|
|
|
|
|
| 173 |
|
| 174 |
gr.Markdown("---")
|
| 175 |
gr.Markdown("Privacy 路 Terms 路 Cookies")
|
|
@@ -225,15 +248,25 @@ with gr.Blocks(css=fb_css, title="Legacy Kitchen") as demo:
|
|
| 225 |
|
| 226 |
magic_btn.click(magic_pipeline, input_img, [out_text, out_sim])
|
| 227 |
|
| 228 |
-
# VIEW 3:
|
| 229 |
-
with gr.Group(visible=False) as
|
| 230 |
-
gr.Markdown("###
|
| 231 |
-
gr.
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
if __name__ == "__main__":
|
| 239 |
demo.launch()
|
|
|
|
| 25 |
if isinstance(data, dict):
|
| 26 |
stored_embeddings = np.array(data['embeddings'])
|
| 27 |
elif isinstance(data, pd.DataFrame):
|
| 28 |
+
# Fallback for dataframe format
|
| 29 |
target_col = next((c for c in ['embedding', 'embeddings', 'vectors'] if c in data.columns), None)
|
| 30 |
stored_embeddings = np.vstack(data[target_col].values) if target_col else data
|
| 31 |
else:
|
|
|
|
| 37 |
stored_embeddings = None
|
| 38 |
|
| 39 |
# ==========================================
|
| 40 |
+
# 2. HELPER: IMAGE TO BASE64
|
| 41 |
# ==========================================
|
| 42 |
def image_to_base64(image_path):
|
| 43 |
if not os.path.exists(image_path):
|
|
|
|
| 100 |
.fb-header {
|
| 101 |
background-color: #ffffff;
|
| 102 |
color: #1877f2;
|
| 103 |
+
padding: 12px 20px;
|
|
|
|
|
|
|
| 104 |
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 105 |
border-bottom: 1px solid #ddd;
|
| 106 |
margin-bottom: 20px;
|
|
|
|
| 110 |
|
| 111 |
.logo-img {
|
| 112 |
height: 40px;
|
| 113 |
+
width: 40px;
|
| 114 |
+
object-fit: cover;
|
| 115 |
margin-right: 15px;
|
| 116 |
border-radius: 5px;
|
| 117 |
}
|
| 118 |
|
| 119 |
+
.header-text-col {
|
| 120 |
+
display: flex;
|
| 121 |
+
flex-direction: column;
|
| 122 |
+
justify-content: center;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
.app-title {
|
| 126 |
+
font-size: 24px;
|
| 127 |
+
font-weight: 900;
|
| 128 |
+
line-height: 1.1;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
.app-slogan {
|
| 132 |
+
font-size: 14px;
|
| 133 |
+
font-weight: normal;
|
| 134 |
+
color: #606770;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
.sidebar-btn {
|
| 138 |
background-color: transparent !important;
|
| 139 |
color: #050505 !important;
|
|
|
|
| 171 |
# ==========================================
|
| 172 |
with gr.Blocks(css=fb_css, title="Legacy Kitchen") as demo:
|
| 173 |
|
| 174 |
+
# --- HEADER ---
|
|
|
|
| 175 |
gr.HTML(f"""
|
| 176 |
<div class="fb-header">
|
| 177 |
<img src="data:image/jpeg;base64,{logo_b64}" class="logo-img" alt="Logo">
|
| 178 |
+
<div class="header-text-col">
|
| 179 |
+
<span class="app-title">Legacy Kitchen</span>
|
| 180 |
+
<span class="app-slogan">Your Family Cookbook</span>
|
| 181 |
+
</div>
|
| 182 |
</div>
|
| 183 |
""")
|
| 184 |
|
|
|
|
| 190 |
|
| 191 |
nav_feed = gr.Button("馃摪 Feed", elem_classes=["sidebar-btn"])
|
| 192 |
nav_digital = gr.Button("馃摳 Digitizer", elem_classes=["sidebar-btn"])
|
| 193 |
+
|
| 194 |
+
# --- UPDATED BUTTON ---
|
| 195 |
+
nav_about = gr.Button("鈩癸笍 About Us", elem_classes=["sidebar-btn"])
|
| 196 |
|
| 197 |
gr.Markdown("---")
|
| 198 |
gr.Markdown("Privacy 路 Terms 路 Cookies")
|
|
|
|
| 248 |
|
| 249 |
magic_btn.click(magic_pipeline, input_img, [out_text, out_sim])
|
| 250 |
|
| 251 |
+
# VIEW 3: ABOUT US (Updated View)
|
| 252 |
+
with gr.Group(visible=False) as about_view:
|
| 253 |
+
gr.Markdown("### 鈩癸笍 About Us", elem_classes=["fb-card"])
|
| 254 |
+
with gr.Group(elem_classes=["fb-card"]):
|
| 255 |
+
gr.Markdown("""
|
| 256 |
+
**Legacy Kitchen** is a project dedicated to preserving culinary history.
|
| 257 |
+
|
| 258 |
+
We believe that every handwritten recipe tells a story. Our AI-powered platform helps you:
|
| 259 |
+
1. **Digitize** old handwritten notes into clear text.
|
| 260 |
+
2. **Discover** similar dishes from a database of 10,000+ recipes.
|
| 261 |
+
3. **Connect** with a community of food lovers.
|
| 262 |
+
|
| 263 |
+
*Preserving the Past, Cooking for the Future.*
|
| 264 |
+
""")
|
| 265 |
+
|
| 266 |
+
# Nav Logic (Updated for About Us)
|
| 267 |
+
nav_feed.click(lambda: (gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)), None, [feed_view, digitalizer_view, about_view])
|
| 268 |
+
nav_digital.click(lambda: (gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)), None, [feed_view, digitalizer_view, about_view])
|
| 269 |
+
nav_about.click(lambda: (gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)), None, [feed_view, digitalizer_view, about_view])
|
| 270 |
|
| 271 |
if __name__ == "__main__":
|
| 272 |
demo.launch()
|