rfmantoan commited on
Commit
e4ba163
1 Parent(s): 2bd9f7e

Change image gallery

Browse files
Files changed (1) hide show
  1. app.py +27 -15
app.py CHANGED
@@ -3,19 +3,20 @@ import pandas as pd
3
  from utils.search_functions import run_search
4
 
5
  if __name__ == "__main__":
6
- # Define the Gradio interface
7
  with gr.Blocks() as demo:
8
  gr.Markdown("### Search Demo with Side-by-Side Comparison")
 
9
  with gr.Row():
10
  with gr.Column():
11
  search_instructions = """
12
- **Choose the Type of Search**
13
  Decide how you'd like to search:
14
  - **Text**: Type in a description of the fashion item you're looking for.
15
  - **Image**: Upload an image of a fashion item you want to find similar results for.
16
  """
17
  embedding_instructions = """
18
- **Select How to Match Results**
19
  Pick the type of comparison you'd like:
20
  - **Text-based**: Find items based on the description you provided.
21
  - **Image-based**: Find items similar to the image you uploaded.
@@ -25,22 +26,22 @@ if __name__ == "__main__":
25
  gr.Markdown(search_instructions)
26
  with gr.Column():
27
  gr.Markdown(embedding_instructions)
28
-
29
  with gr.Row():
30
- query_type = gr.Radio(["text", "image"], label="Query Type")
31
  embedding_type = gr.Radio(["text", "image", "average", "weighted average"], label="Embedding Type")
32
 
33
- query_input_text = gr.Textbox(label="Text Query", placeholder="Enter text query here")
34
- query_input_image = gr.Image(label="Upload Image", type="filepath")
 
35
  search_button = gr.Button("Search")
36
-
37
  viewing_instructions = """
38
- **Viewing Your Results**
39
  The results are displayed in a scrollable gallery for each model. To explore each image more closely:
40
  - Scroll down to browse through the images.
41
  - Click on any image to open it in full view.
42
  - Once opened, you can flip through the images using the arrows or swipe gestures.
43
-
44
  Each image in the gallery contains the following information:
45
  - Similarity Score: Shows how closely the item matches your search (higher is better).
46
  - Metadata: Additional information about each item, such as category, brand, and material, is displayed beneath each image.
@@ -51,12 +52,14 @@ if __name__ == "__main__":
51
  with gr.Row():
52
  with gr.Column():
53
  gr.Markdown("#### FashionCLIP Results")
54
- fclip_output_images = gr.Gallery(label="FashionCLIP Images")
 
55
  fclip_output_results = gr.Dataframe(label="FashionCLIP Search Results")
56
 
57
  with gr.Column():
58
  gr.Markdown("#### FashionSigLip Results")
59
- siglip_output_images = gr.Gallery(label="FashionSigLIP Images")
 
60
  siglip_output_results = gr.Dataframe(label="FashionSigLIP Search Results")
61
 
62
  # Update input fields based on query type
@@ -68,12 +71,21 @@ if __name__ == "__main__":
68
 
69
  query_type.change(update_query_input, inputs=query_type, outputs=[query_input_text, query_input_image])
70
 
71
- # Search button to trigger both searches
 
 
 
 
 
 
 
 
 
72
  search_button.click(
73
- run_search,
74
  inputs=[query_type, embedding_type, query_input_text, query_input_image],
75
  outputs=[fclip_output_images, fclip_output_results, siglip_output_images, siglip_output_results]
76
  )
77
 
78
  # Launch the Gradio app
79
- demo.launch(debug=True, share=True)
 
3
  from utils.search_functions import run_search
4
 
5
  if __name__ == "__main__":
6
+ # Define the Gradio interface
7
  with gr.Blocks() as demo:
8
  gr.Markdown("### Search Demo with Side-by-Side Comparison")
9
+
10
  with gr.Row():
11
  with gr.Column():
12
  search_instructions = """
13
+ **Choose the Type of Search**
14
  Decide how you'd like to search:
15
  - **Text**: Type in a description of the fashion item you're looking for.
16
  - **Image**: Upload an image of a fashion item you want to find similar results for.
17
  """
18
  embedding_instructions = """
19
+ **Select How to Match Results**
20
  Pick the type of comparison you'd like:
21
  - **Text-based**: Find items based on the description you provided.
22
  - **Image-based**: Find items similar to the image you uploaded.
 
26
  gr.Markdown(search_instructions)
27
  with gr.Column():
28
  gr.Markdown(embedding_instructions)
29
+
30
  with gr.Row():
31
+ query_type = gr.Radio(["text", "image"], label="Query Type", value="text")
32
  embedding_type = gr.Radio(["text", "image", "average", "weighted average"], label="Embedding Type")
33
 
34
+ # Input fields
35
+ query_input_text = gr.Textbox(label="Text Query", placeholder="Enter text query here", visible=True)
36
+ query_input_image = gr.Image(label="Upload Image", type="filepath", visible=False)
37
  search_button = gr.Button("Search")
38
+
39
  viewing_instructions = """
40
+ **Viewing Your Results**
41
  The results are displayed in a scrollable gallery for each model. To explore each image more closely:
42
  - Scroll down to browse through the images.
43
  - Click on any image to open it in full view.
44
  - Once opened, you can flip through the images using the arrows or swipe gestures.
 
45
  Each image in the gallery contains the following information:
46
  - Similarity Score: Shows how closely the item matches your search (higher is better).
47
  - Metadata: Additional information about each item, such as category, brand, and material, is displayed beneath each image.
 
52
  with gr.Row():
53
  with gr.Column():
54
  gr.Markdown("#### FashionCLIP Results")
55
+ # Set the gallery to display 4 images per row (scrollable)
56
+ fclip_output_images = gr.Gallery(label="FashionCLIP Images", columns=3)
57
  fclip_output_results = gr.Dataframe(label="FashionCLIP Search Results")
58
 
59
  with gr.Column():
60
  gr.Markdown("#### FashionSigLip Results")
61
+ # Set the gallery to display 4 images per row (scrollable)
62
+ siglip_output_images = gr.Gallery(label="FashionSigLIP Images", columns=3)
63
  siglip_output_results = gr.Dataframe(label="FashionSigLIP Search Results")
64
 
65
  # Update input fields based on query type
 
71
 
72
  query_type.change(update_query_input, inputs=query_type, outputs=[query_input_text, query_input_image])
73
 
74
+ # Error handling function
75
+ def validate_and_search(query_type, embedding_type, query_input_text, query_input_image):
76
+ if query_type == "text" and not query_input_text:
77
+ return gr.Error("Please enter a text query"), None, None, None
78
+ elif query_type == "image" and not query_input_image:
79
+ return gr.Error("Please upload an image"), None, None, None
80
+ else:
81
+ return run_search(query_type, embedding_type, query_input_text, query_input_image)
82
+
83
+ # Search button to trigger both searches with validation
84
  search_button.click(
85
+ validate_and_search,
86
  inputs=[query_type, embedding_type, query_input_text, query_input_image],
87
  outputs=[fclip_output_images, fclip_output_results, siglip_output_images, siglip_output_results]
88
  )
89
 
90
  # Launch the Gradio app
91
+ demo.launch(share=True)