Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import pickle
|
|
| 4 |
import numpy as np
|
| 5 |
import os
|
| 6 |
import random
|
|
|
|
| 7 |
from huggingface_hub import InferenceClient
|
| 8 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 9 |
from IO_pipeline import RecipeDigitalizerPipeline
|
|
@@ -24,7 +25,6 @@ try:
|
|
| 24 |
if isinstance(data, dict):
|
| 25 |
stored_embeddings = np.array(data['embeddings'])
|
| 26 |
elif isinstance(data, pd.DataFrame):
|
| 27 |
-
# Fallback for dataframe format
|
| 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 +36,19 @@ except Exception as e:
|
|
| 36 |
stored_embeddings = None
|
| 37 |
|
| 38 |
# ==========================================
|
| 39 |
-
# 2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# ==========================================
|
| 41 |
def get_embedding_via_api(text):
|
| 42 |
if not client: raise ValueError("HF_TOKEN missing")
|
|
@@ -79,7 +91,7 @@ def magic_pipeline(image_path):
|
|
| 79 |
return f"Error: {e}", f"Error: {e}"
|
| 80 |
|
| 81 |
# ==========================================
|
| 82 |
-
#
|
| 83 |
# ==========================================
|
| 84 |
fb_css = """
|
| 85 |
body {background-color: #f0f2f5 !important; font-family: Helvetica, Arial, sans-serif;}
|
|
@@ -136,15 +148,15 @@ body {background-color: #f0f2f5 !important; font-family: Helvetica, Arial, sans-
|
|
| 136 |
"""
|
| 137 |
|
| 138 |
# ==========================================
|
| 139 |
-
#
|
| 140 |
# ==========================================
|
| 141 |
with gr.Blocks(css=fb_css, title="Legacy Kitchen") as demo:
|
| 142 |
|
| 143 |
-
|
| 144 |
-
#
|
| 145 |
-
gr.HTML("""
|
| 146 |
<div class="fb-header">
|
| 147 |
-
<img src="/
|
| 148 |
Legacy Kitchen
|
| 149 |
</div>
|
| 150 |
""")
|
|
@@ -224,5 +236,4 @@ with gr.Blocks(css=fb_css, title="Legacy Kitchen") as demo:
|
|
| 224 |
nav_saved.click(lambda: (gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)), None, [feed_view, digitalizer_view, saved_view])
|
| 225 |
|
| 226 |
if __name__ == "__main__":
|
| 227 |
-
|
| 228 |
-
demo.launch(allowed_paths=["."])
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import os
|
| 6 |
import random
|
| 7 |
+
import base64
|
| 8 |
from huggingface_hub import InferenceClient
|
| 9 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 10 |
from IO_pipeline import RecipeDigitalizerPipeline
|
|
|
|
| 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 |
stored_embeddings = None
|
| 37 |
|
| 38 |
# ==========================================
|
| 39 |
+
# 2. HELPER: IMAGE TO BASE64 (The Fix)
|
| 40 |
+
# ==========================================
|
| 41 |
+
def image_to_base64(image_path):
|
| 42 |
+
if not os.path.exists(image_path):
|
| 43 |
+
return ""
|
| 44 |
+
with open(image_path, "rb") as img_file:
|
| 45 |
+
return base64.b64encode(img_file.read()).decode('utf-8')
|
| 46 |
+
|
| 47 |
+
# Pre-load the logo
|
| 48 |
+
logo_b64 = image_to_base64("logo.jpg")
|
| 49 |
+
|
| 50 |
+
# ==========================================
|
| 51 |
+
# 3. BACKEND LOGIC
|
| 52 |
# ==========================================
|
| 53 |
def get_embedding_via_api(text):
|
| 54 |
if not client: raise ValueError("HF_TOKEN missing")
|
|
|
|
| 91 |
return f"Error: {e}", f"Error: {e}"
|
| 92 |
|
| 93 |
# ==========================================
|
| 94 |
+
# 4. CSS STYLING
|
| 95 |
# ==========================================
|
| 96 |
fb_css = """
|
| 97 |
body {background-color: #f0f2f5 !important; font-family: Helvetica, Arial, sans-serif;}
|
|
|
|
| 148 |
"""
|
| 149 |
|
| 150 |
# ==========================================
|
| 151 |
+
# 5. LAYOUT
|
| 152 |
# ==========================================
|
| 153 |
with gr.Blocks(css=fb_css, title="Legacy Kitchen") as demo:
|
| 154 |
|
| 155 |
+
# --- HEADER WITH EMBEDDED LOGO ---
|
| 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 |
Legacy Kitchen
|
| 161 |
</div>
|
| 162 |
""")
|
|
|
|
| 236 |
nav_saved.click(lambda: (gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)), None, [feed_view, digitalizer_view, saved_view])
|
| 237 |
|
| 238 |
if __name__ == "__main__":
|
| 239 |
+
demo.launch()
|
|
|