DINGOLANI commited on
Commit
171a063
·
verified ·
1 Parent(s): 3f017a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -11
app.py CHANGED
@@ -1,24 +1,43 @@
1
  import gradio as gr
2
- from transformers import pipeline
 
3
 
4
- # Load a compatible T5-based model for query parsing
5
- query_parser = pipeline("text2text-generation", model="google/flan-t5-small")
 
 
6
 
7
  def parse_query(user_query):
8
  """
9
- Parse user e-commerce search query and return structured attributes.
10
  """
11
- output = query_parser(user_query, max_length=50, do_sample=False)
12
- structured_response = output[0]['generated_text']
13
- return structured_response
14
 
15
- # Define the Gradio UI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.Textbox(label="Structured Output", placeholder="Brand: Gucci, Gender: Men, Category: Perfume, Price: 0-200 AED")
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