Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -98,13 +98,29 @@ def update_textbox(choice):
|
|
98 |
return choice
|
99 |
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
# Gradio interface
|
102 |
with gr.Blocks() as demo:
|
103 |
-
gr.Markdown("# Get Fashion Items Recommended Based On Your Search
|
|
|
104 |
|
105 |
with gr.Row():
|
106 |
-
|
107 |
-
|
|
|
|
|
108 |
slider = gr.Slider(minimum=0, maximum=1, step=0.1, value=0.5, label="Adjust the Slider to get better recommendations that suit what you are looking for..", interactive=True)
|
109 |
|
110 |
# Automatically update the text input when a dropdown selection is made
|
@@ -113,8 +129,11 @@ with gr.Blocks() as demo:
|
|
113 |
# HTML output box to display images
|
114 |
html_output = gr.HTML(label="Relevant Images")
|
115 |
|
|
|
|
|
116 |
# Process and display images based on text input or slider changes
|
117 |
text_input.change(fn=process_input, inputs=[text_input, slider], outputs=html_output)
|
|
|
118 |
slider.change(fn=process_input, inputs=[text_input, slider], outputs=html_output)
|
119 |
|
120 |
demo.launch(debug=True, share=True)
|
|
|
98 |
return choice
|
99 |
|
100 |
|
101 |
+
def text_process(search_string):
|
102 |
+
# Split the search string into words
|
103 |
+
search_words = search_string.title().split()
|
104 |
+
|
105 |
+
# Create a regex pattern that matches all words in any order
|
106 |
+
pattern = r"(?=.*\b" + r"\b)(?=.*\b".join(map(re.escape, search_words)) + r"\b)"
|
107 |
+
|
108 |
+
# Filter the master list to find items matching the pattern
|
109 |
+
filtered_items = [item for item in item_list if re.search(pattern, item)]
|
110 |
+
|
111 |
+
return gr.update(visible=True), gr.update(choices=filtered_items, value=filtered_items[0] if filtered_items else "")
|
112 |
+
|
113 |
+
|
114 |
# Gradio interface
|
115 |
with gr.Blocks() as demo:
|
116 |
+
gr.Markdown("# Get Fashion Items Recommended Based On Your Search..\n"
|
117 |
+
"## Recommender System implemented based Pinecone Vector Database with Dense & Sparse Embeddings and Hybrid Search..")
|
118 |
|
119 |
with gr.Row():
|
120 |
+
text_input = gr.Textbox(label="Type-in what you are looking for..")
|
121 |
+
submit_btn = gr.Button("Click this button for further filtering..")
|
122 |
+
dropdown = gr.Dropdown(label="Click here and select to narrow your serach..",
|
123 |
+
value= "Select an item from this list or start typing", allow_custom_value=True, interactive=True, visible=False)
|
124 |
slider = gr.Slider(minimum=0, maximum=1, step=0.1, value=0.5, label="Adjust the Slider to get better recommendations that suit what you are looking for..", interactive=True)
|
125 |
|
126 |
# Automatically update the text input when a dropdown selection is made
|
|
|
129 |
# HTML output box to display images
|
130 |
html_output = gr.HTML(label="Relevant Images")
|
131 |
|
132 |
+
submit_btn.click(fn=text_process, inputs=[text_input], outputs=[dropdown, dropdown])
|
133 |
+
|
134 |
# Process and display images based on text input or slider changes
|
135 |
text_input.change(fn=process_input, inputs=[text_input, slider], outputs=html_output)
|
136 |
+
|
137 |
slider.change(fn=process_input, inputs=[text_input, slider], outputs=html_output)
|
138 |
|
139 |
demo.launch(debug=True, share=True)
|