Spaces:
Runtime error
Runtime error
rfmantoan
commited on
Commit
·
0b99f61
1
Parent(s):
6280314
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
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.
|
22 |
+
- **Both (Balanced)**: Search using a combination of both text and image. This balances between the two equally.
|
23 |
+
- **Both (Image-focused)**: Emphasize the image more than the text in the search for closer visual matches.
|
24 |
+
"""
|
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.
|
47 |
+
"""
|
48 |
+
with gr.Row():
|
49 |
+
gr.Markdown(viewing_instructions)
|
50 |
+
|
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
|
63 |
+
def update_query_input(query_type):
|
64 |
+
if query_type == "text":
|
65 |
+
return gr.update(visible=True), gr.update(visible=False)
|
66 |
+
else:
|
67 |
+
return gr.update(visible=False), gr.update(visible=True)
|
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)
|