Update app.py
Browse files
app.py
CHANGED
|
@@ -143,14 +143,13 @@ def pil_to_base64(img, max_size=280):
|
|
| 143 |
return base64.b64encode(buf.getvalue()).decode("utf-8")
|
| 144 |
|
| 145 |
# ---------------------------------------------------------------------------
|
| 146 |
-
# EMBEDDING + FAISS SEARCH
|
| 147 |
# ---------------------------------------------------------------------------
|
| 148 |
@torch.no_grad()
|
| 149 |
def embed_query_image(pil_image):
|
| 150 |
inputs = win_processor(images=pil_image, return_tensors="pt").to(DEVICE)
|
| 151 |
outputs = win_model(**inputs)
|
| 152 |
|
| 153 |
-
# שימוש ישיר ובטוח בחילוץ הוקטור ללא תלות בסוג העטיפה של BaseModelOutput
|
| 154 |
if hasattr(outputs, "image_embeds") and outputs.image_embeds is not None:
|
| 155 |
feats = outputs.image_embeds
|
| 156 |
elif hasattr(outputs, "pooler_output") and outputs.pooler_output is not None:
|
|
@@ -169,7 +168,6 @@ def embed_query_text(sentence):
|
|
| 169 |
inputs = win_processor(text=[sentence], return_tensors="pt", padding=True, truncation=True).to(DEVICE)
|
| 170 |
outputs = win_model(**inputs)
|
| 171 |
|
| 172 |
-
# שימוש ישיר ובטוח בחילוץ הוקטור ללא תלות בסוג העטיפה של BaseModelOutput
|
| 173 |
if hasattr(outputs, "text_embeds") and outputs.text_embeds is not None:
|
| 174 |
feats = outputs.text_embeds
|
| 175 |
elif hasattr(outputs, "pooler_output") and outputs.pooler_output is not None:
|
|
@@ -199,7 +197,8 @@ def faiss_filtered_search(query_emb, top_k=3, exclude_idx=None, gender=None, age
|
|
| 199 |
if idx == -1 or (exclude_idx is not None and idx == exclude_idx):
|
| 200 |
continue
|
| 201 |
row = df.iloc[idx]
|
| 202 |
-
|
|
|
|
| 203 |
continue
|
| 204 |
if require_age and age_group and str(row["age_group"]).lower() != str(age_group).lower():
|
| 205 |
continue
|
|
@@ -488,7 +487,6 @@ with gr.Blocks(title="Personal Color Styling") as demo:
|
|
| 488 |
[style_card_a, new_img_a, answer_a, outfit_cards_a],
|
| 489 |
)
|
| 490 |
|
| 491 |
-
# תיקון: הגדרת cache_examples=False כדי למנוע קריסות והדמיית קלט כפויה
|
| 492 |
gr.Examples(
|
| 493 |
examples=[
|
| 494 |
[SAMPLE_PHOTOS[0], "woman", "adult", "What style would suit me best?"],
|
|
|
|
| 143 |
return base64.b64encode(buf.getvalue()).decode("utf-8")
|
| 144 |
|
| 145 |
# ---------------------------------------------------------------------------
|
| 146 |
+
# EMBEDDING + FAISS SEARCH
|
| 147 |
# ---------------------------------------------------------------------------
|
| 148 |
@torch.no_grad()
|
| 149 |
def embed_query_image(pil_image):
|
| 150 |
inputs = win_processor(images=pil_image, return_tensors="pt").to(DEVICE)
|
| 151 |
outputs = win_model(**inputs)
|
| 152 |
|
|
|
|
| 153 |
if hasattr(outputs, "image_embeds") and outputs.image_embeds is not None:
|
| 154 |
feats = outputs.image_embeds
|
| 155 |
elif hasattr(outputs, "pooler_output") and outputs.pooler_output is not None:
|
|
|
|
| 168 |
inputs = win_processor(text=[sentence], return_tensors="pt", padding=True, truncation=True).to(DEVICE)
|
| 169 |
outputs = win_model(**inputs)
|
| 170 |
|
|
|
|
| 171 |
if hasattr(outputs, "text_embeds") and outputs.text_embeds is not None:
|
| 172 |
feats = outputs.text_embeds
|
| 173 |
elif hasattr(outputs, "pooler_output") and outputs.pooler_output is not None:
|
|
|
|
| 197 |
if idx == -1 or (exclude_idx is not None and idx == exclude_idx):
|
| 198 |
continue
|
| 199 |
row = df.iloc[idx]
|
| 200 |
+
# FIXED: Syntax correction changing '&&' to python's native 'and' operator
|
| 201 |
+
if require_gender and gender and str(row["gender"]).lower() != str(gender).lower():
|
| 202 |
continue
|
| 203 |
if require_age and age_group and str(row["age_group"]).lower() != str(age_group).lower():
|
| 204 |
continue
|
|
|
|
| 487 |
[style_card_a, new_img_a, answer_a, outfit_cards_a],
|
| 488 |
)
|
| 489 |
|
|
|
|
| 490 |
gr.Examples(
|
| 491 |
examples=[
|
| 492 |
[SAMPLE_PHOTOS[0], "woman", "adult", "What style would suit me best?"],
|