Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,43 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def parse_query(user_query):
|
| 8 |
"""
|
| 9 |
-
Parse
|
| 10 |
"""
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
return structured_response
|
| 14 |
|
| 15 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
with gr.Blocks() as demo:
|
| 17 |
-
gr.Markdown("# 🛍️ Luxury Fashion Query Parser")
|
| 18 |
|
| 19 |
query_input = gr.Textbox(label="Enter your search query", placeholder="e.g., Gucci men’s perfume under 200AED")
|
| 20 |
-
output_box = gr.
|
| 21 |
-
|
| 22 |
parse_button = gr.Button("Parse Query")
|
| 23 |
parse_button.click(parse_query, inputs=[query_input], outputs=[output_box])
|
| 24 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import CLIPProcessor, CLIPModel
|
| 4 |
|
| 5 |
+
# Load the FashionCLIP model
|
| 6 |
+
model_name = "patrickjohncyh/fashion-clip"
|
| 7 |
+
model = CLIPModel.from_pretrained(model_name)
|
| 8 |
+
processor = CLIPProcessor.from_pretrained(model_name)
|
| 9 |
|
| 10 |
def parse_query(user_query):
|
| 11 |
"""
|
| 12 |
+
Parse fashion-related search queries into structured data.
|
| 13 |
"""
|
| 14 |
+
# Define categories relevant to luxury fashion search
|
| 15 |
+
fashion_categories = ["Brand", "Category", "Gender", "Price Range"]
|
|
|
|
| 16 |
|
| 17 |
+
# Format user query for CLIP
|
| 18 |
+
inputs = processor(text=[user_query], images=None, return_tensors="pt", padding=True)
|
| 19 |
+
|
| 20 |
+
# Get model embeddings
|
| 21 |
+
with torch.no_grad():
|
| 22 |
+
outputs = model.get_text_features(**inputs)
|
| 23 |
+
|
| 24 |
+
# Simulated parsing output (FashionCLIP itself does not generate structured JSON)
|
| 25 |
+
parsed_output = {
|
| 26 |
+
"Brand": "Gucci" if "Gucci" in user_query else "Unknown",
|
| 27 |
+
"Category": "Perfume" if "perfume" in user_query else "Unknown",
|
| 28 |
+
"Gender": "Men" if "men" in user_query else "Women" if "women" in user_query else "Unisex",
|
| 29 |
+
"Price Range": "Under 200 AED" if "under 200" in user_query else "Above 200 AED",
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
return parsed_output
|
| 33 |
+
|
| 34 |
+
# Define Gradio UI
|
| 35 |
with gr.Blocks() as demo:
|
| 36 |
+
gr.Markdown("# 🛍️ Luxury Fashion Query Parser (FashionCLIP)")
|
| 37 |
|
| 38 |
query_input = gr.Textbox(label="Enter your search query", placeholder="e.g., Gucci men’s perfume under 200AED")
|
| 39 |
+
output_box = gr.JSON(label="Parsed Output")
|
| 40 |
+
|
| 41 |
parse_button = gr.Button("Parse Query")
|
| 42 |
parse_button.click(parse_query, inputs=[query_input], outputs=[output_box])
|
| 43 |
|