Spaces:
Runtime error
Runtime error
Anusha806
commited on
Commit
·
590858e
1
Parent(s):
3a8669c
commit26
Browse files
app.py
CHANGED
|
@@ -679,56 +679,51 @@ def search_by_image(uploaded_image, alpha=0.5, start=0, end=12):
|
|
| 679 |
import gradio as gr
|
| 680 |
|
| 681 |
custom_css = """
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
.gr-row {
|
| 687 |
-
gap: 8px !important;
|
| 688 |
flex-wrap: wrap;
|
|
|
|
|
|
|
| 689 |
}
|
| 690 |
|
| 691 |
-
|
| 692 |
-
margin-bottom: 4px !important;
|
| 693 |
-
}
|
| 694 |
-
|
| 695 |
-
/* Default: 6 per row */
|
| 696 |
.gr-gallery-item {
|
| 697 |
-
flex:
|
| 698 |
max-width: calc(16.66% - 10px);
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
margin-bottom: 10px;
|
| 702 |
}
|
| 703 |
|
|
|
|
| 704 |
.gr-gallery-item img {
|
| 705 |
width: 100% !important;
|
| 706 |
-
height:
|
| 707 |
object-fit: cover !important;
|
| 708 |
}
|
| 709 |
|
| 710 |
-
/*
|
| 711 |
@media (max-width: 768px) {
|
| 712 |
.gr-gallery-item {
|
| 713 |
-
flex:
|
| 714 |
max-width: calc(33.33% - 10px);
|
| 715 |
}
|
| 716 |
}
|
| 717 |
"""
|
| 718 |
|
| 719 |
with gr.Blocks(css=custom_css) as demo:
|
| 720 |
-
gr.Markdown("## 🛍️ Fashion Product
|
| 721 |
|
| 722 |
-
with gr.Row(
|
| 723 |
with gr.Column(scale=5, elem_classes="query-slider"):
|
| 724 |
-
query = gr.Textbox(label="
|
| 725 |
-
alpha = gr.Slider(0, 1, value=0.5, label="Hybrid Weight
|
| 726 |
-
gender_dropdown = gr.Dropdown(["", "Men", "Women", "
|
| 727 |
with gr.Column(scale=1):
|
| 728 |
-
image_input = gr.Image(type="pil", label="Upload
|
| 729 |
|
| 730 |
search_btn = gr.Button("Search", elem_classes="search-btn")
|
| 731 |
-
gallery = gr.Gallery(label="
|
| 732 |
load_more_btn = gr.Button("Load More")
|
| 733 |
|
| 734 |
search_offset = gr.State(0)
|
|
@@ -740,7 +735,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 740 |
|
| 741 |
def unified_search(q, uploaded_image, a, offset, gender_ui):
|
| 742 |
start = 0
|
| 743 |
-
end =
|
| 744 |
filters = extract_intent_from_openai(q) if q.strip() else {}
|
| 745 |
gender_override = gender_ui if gender_ui else filters.get("gender")
|
| 746 |
|
|
@@ -754,13 +749,15 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 754 |
seen_ids = {r[1] for r in results}
|
| 755 |
return results, end, q, uploaded_image, gender_override, results, seen_ids
|
| 756 |
|
| 757 |
-
search_btn.click(
|
| 758 |
-
|
| 759 |
-
|
|
|
|
|
|
|
| 760 |
|
| 761 |
def load_more_fn(a, offset, q, img, gender_ui, prev_results, prev_ids):
|
| 762 |
start = offset
|
| 763 |
-
end = offset +
|
| 764 |
gender_override = gender_ui
|
| 765 |
|
| 766 |
if img is not None:
|
|
@@ -783,11 +780,14 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 783 |
|
| 784 |
return combined, end, combined, updated_ids
|
| 785 |
|
| 786 |
-
load_more_btn.click(
|
| 787 |
-
|
| 788 |
-
|
|
|
|
|
|
|
| 789 |
|
| 790 |
gr.Markdown("🧠 Powered by OpenAI + Hybrid AI Fashion Search")
|
| 791 |
|
| 792 |
demo.launch()
|
| 793 |
|
|
|
|
|
|
| 679 |
import gradio as gr
|
| 680 |
|
| 681 |
custom_css = """
|
| 682 |
+
/* Container */
|
| 683 |
+
.gr-gallery {
|
| 684 |
+
display: flex !important;
|
|
|
|
|
|
|
|
|
|
| 685 |
flex-wrap: wrap;
|
| 686 |
+
gap: 10px;
|
| 687 |
+
justify-content: center;
|
| 688 |
}
|
| 689 |
|
| 690 |
+
/* Each item */
|
|
|
|
|
|
|
|
|
|
|
|
|
| 691 |
.gr-gallery-item {
|
| 692 |
+
flex: 0 0 calc(16.66% - 10px); /* 6 columns on desktop */
|
| 693 |
max-width: calc(16.66% - 10px);
|
| 694 |
+
height: 256px !important;
|
| 695 |
+
overflow: hidden;
|
|
|
|
| 696 |
}
|
| 697 |
|
| 698 |
+
/* Image inside each item */
|
| 699 |
.gr-gallery-item img {
|
| 700 |
width: 100% !important;
|
| 701 |
+
height: 100% !important;
|
| 702 |
object-fit: cover !important;
|
| 703 |
}
|
| 704 |
|
| 705 |
+
/* For mobile: 3 columns */
|
| 706 |
@media (max-width: 768px) {
|
| 707 |
.gr-gallery-item {
|
| 708 |
+
flex: 0 0 calc(33.33% - 10px); /* 3 columns on mobile */
|
| 709 |
max-width: calc(33.33% - 10px);
|
| 710 |
}
|
| 711 |
}
|
| 712 |
"""
|
| 713 |
|
| 714 |
with gr.Blocks(css=custom_css) as demo:
|
| 715 |
+
gr.Markdown("## 🛍️ Responsive Fashion Product Search")
|
| 716 |
|
| 717 |
+
with gr.Row():
|
| 718 |
with gr.Column(scale=5, elem_classes="query-slider"):
|
| 719 |
+
query = gr.Textbox(label="Search", placeholder="e.g. black dress for women")
|
| 720 |
+
alpha = gr.Slider(0, 1, value=0.5, label="Hybrid Weight")
|
| 721 |
+
gender_dropdown = gr.Dropdown(["", "Men", "Women", "Unisex"], label="Gender (optional)")
|
| 722 |
with gr.Column(scale=1):
|
| 723 |
+
image_input = gr.Image(type="pil", label="Upload Image", sources=["upload", "clipboard"], height=256)
|
| 724 |
|
| 725 |
search_btn = gr.Button("Search", elem_classes="search-btn")
|
| 726 |
+
gallery = gr.Gallery(label="Results", columns=6, height=None, allow_preview=True)
|
| 727 |
load_more_btn = gr.Button("Load More")
|
| 728 |
|
| 729 |
search_offset = gr.State(0)
|
|
|
|
| 735 |
|
| 736 |
def unified_search(q, uploaded_image, a, offset, gender_ui):
|
| 737 |
start = 0
|
| 738 |
+
end = 12
|
| 739 |
filters = extract_intent_from_openai(q) if q.strip() else {}
|
| 740 |
gender_override = gender_ui if gender_ui else filters.get("gender")
|
| 741 |
|
|
|
|
| 749 |
seen_ids = {r[1] for r in results}
|
| 750 |
return results, end, q, uploaded_image, gender_override, results, seen_ids
|
| 751 |
|
| 752 |
+
search_btn.click(
|
| 753 |
+
unified_search,
|
| 754 |
+
inputs=[query, image_input, alpha, search_offset, gender_dropdown],
|
| 755 |
+
outputs=[gallery, search_offset, current_query, current_image, current_gender, shown_results, shown_ids]
|
| 756 |
+
)
|
| 757 |
|
| 758 |
def load_more_fn(a, offset, q, img, gender_ui, prev_results, prev_ids):
|
| 759 |
start = offset
|
| 760 |
+
end = offset + 12
|
| 761 |
gender_override = gender_ui
|
| 762 |
|
| 763 |
if img is not None:
|
|
|
|
| 780 |
|
| 781 |
return combined, end, combined, updated_ids
|
| 782 |
|
| 783 |
+
load_more_btn.click(
|
| 784 |
+
load_more_fn,
|
| 785 |
+
inputs=[alpha, search_offset, current_query, current_image, current_gender, shown_results, shown_ids],
|
| 786 |
+
outputs=[gallery, search_offset, shown_results, shown_ids]
|
| 787 |
+
)
|
| 788 |
|
| 789 |
gr.Markdown("🧠 Powered by OpenAI + Hybrid AI Fashion Search")
|
| 790 |
|
| 791 |
demo.launch()
|
| 792 |
|
| 793 |
+
|