Spaces:
Runtime error
Runtime error
Commit
·
add8f10
1
Parent(s):
2100a52
Update app.py
Browse files
app.py
CHANGED
|
@@ -172,13 +172,13 @@ with gr.Blocks(theme=theme, title="New Look", css=css) as demo:
|
|
| 172 |
text_relevance = gr.Slider(label="Text search relevance", minimum = -5, maximum = 5, value = 1, step = 1)
|
| 173 |
text_input_1 = gr.Text(label="Search with text:", visible=False)
|
| 174 |
text_relevance_1 = gr.Slider(label="Text search relevance", minimum = -5, maximum = 5, value = 1, step = 1, visible=False)
|
| 175 |
-
more_text_search = gr.Button(value="
|
| 176 |
text_expanded = gr.State(value=False)
|
| 177 |
with gr.Column(scale=3):
|
| 178 |
best_seller_score_weight = gr.Slider(label = "Best seller relevance", minimum=-1, maximum=1, value=0, step=0.01)
|
| 179 |
search_button = gr.Button(value="Search")
|
| 180 |
with gr.Column(scale=2):
|
| 181 |
-
image_input = gr.Image(type="pil", label="Search with
|
| 182 |
image_path = gr.State(visible=False)
|
| 183 |
image_relevance = gr.Slider(label="Image search relevance", minimum = -5, maximum = 5, value = 1, step = 1)
|
| 184 |
|
|
@@ -199,33 +199,37 @@ with gr.Blocks(theme=theme, title="New Look", css=css) as demo:
|
|
| 199 |
height="400",object_fit="contain")
|
| 200 |
image_description = gr.Text(label="Description")
|
| 201 |
product_link = gr.State()
|
| 202 |
-
button_go_to_page = gr.Button(value="Go to product page")
|
|
|
|
| 203 |
|
| 204 |
-
|
| 205 |
|
| 206 |
def on_new_text_box(more_text_search): # SelectData is a subclass of EventData
|
| 207 |
-
if more_text_search == "
|
| 208 |
return gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(value="Hide extra text box")
|
| 209 |
else:
|
| 210 |
-
return gr.update(value="", visible=False, interactive=False), gr.update(visible=False, interactive=False), gr.update(value="
|
| 211 |
|
| 212 |
def on_focus(evt: gr.SelectData): # SelectData is a subclass of EventData
|
| 213 |
-
|
|
|
|
| 214 |
|
| 215 |
def on_new_image_to_search(images, evt: gr.SelectData): # SelectData is a subclass of EventData
|
| 216 |
return return_primary_item(evt.value)
|
| 217 |
|
| 218 |
-
def on_go_to_product_page(product_link):
|
| 219 |
-
|
| 220 |
-
|
|
|
|
|
|
|
| 221 |
# webbrowser.open(product_link)
|
| 222 |
# except:
|
| 223 |
# print("Not able to open product page")
|
| 224 |
|
| 225 |
more_text_search.click(on_new_text_box, more_text_search, [text_input_1, text_relevance_1, more_text_search])
|
| 226 |
-
images_gallery.select(on_focus, None, [detail_gallery, image_description, product_link])
|
| 227 |
detail_gallery.select(on_new_image_to_search, detail_gallery, image_input)
|
| 228 |
-
button_go_to_page.click(on_go_to_product_page, product_link, page)
|
| 229 |
|
| 230 |
# with gr.Tab(label="Search for images"):
|
| 231 |
# labels_input = gr.Text(label="List of labels")
|
|
|
|
| 172 |
text_relevance = gr.Slider(label="Text search relevance", minimum = -5, maximum = 5, value = 1, step = 1)
|
| 173 |
text_input_1 = gr.Text(label="Search with text:", visible=False)
|
| 174 |
text_relevance_1 = gr.Slider(label="Text search relevance", minimum = -5, maximum = 5, value = 1, step = 1, visible=False)
|
| 175 |
+
more_text_search = gr.Button(value="More text fields")
|
| 176 |
text_expanded = gr.State(value=False)
|
| 177 |
with gr.Column(scale=3):
|
| 178 |
best_seller_score_weight = gr.Slider(label = "Best seller relevance", minimum=-1, maximum=1, value=0, step=0.01)
|
| 179 |
search_button = gr.Button(value="Search")
|
| 180 |
with gr.Column(scale=2):
|
| 181 |
+
image_input = gr.Image(type="pil", label="Search with image")
|
| 182 |
image_path = gr.State(visible=False)
|
| 183 |
image_relevance = gr.Slider(label="Image search relevance", minimum = -5, maximum = 5, value = 1, step = 1)
|
| 184 |
|
|
|
|
| 199 |
height="400",object_fit="contain")
|
| 200 |
image_description = gr.Text(label="Description")
|
| 201 |
product_link = gr.State()
|
| 202 |
+
# button_go_to_page = gr.Button(value="Go to product page")
|
| 203 |
+
page = gr.HTML()
|
| 204 |
|
| 205 |
+
|
| 206 |
|
| 207 |
def on_new_text_box(more_text_search): # SelectData is a subclass of EventData
|
| 208 |
+
if more_text_search == "More text fields":
|
| 209 |
return gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(value="Hide extra text box")
|
| 210 |
else:
|
| 211 |
+
return gr.update(value="", visible=False, interactive=False), gr.update(visible=False, interactive=False), gr.update(value="More text fields")
|
| 212 |
|
| 213 |
def on_focus(evt: gr.SelectData): # SelectData is a subclass of EventData
|
| 214 |
+
item = return_item(evt.value)
|
| 215 |
+
return item[0], item[1], item[2], gr.update(value="<a href= " + item[2] + " target='_blank'> Go to product page </a>")
|
| 216 |
|
| 217 |
def on_new_image_to_search(images, evt: gr.SelectData): # SelectData is a subclass of EventData
|
| 218 |
return return_primary_item(evt.value)
|
| 219 |
|
| 220 |
+
# def on_go_to_product_page(product_link):
|
| 221 |
+
# # try:
|
| 222 |
+
# return gr.update(value='''<button onclick="window.location.href='+ product_link +';">
|
| 223 |
+
# Click Here
|
| 224 |
+
# </button>''')
|
| 225 |
# webbrowser.open(product_link)
|
| 226 |
# except:
|
| 227 |
# print("Not able to open product page")
|
| 228 |
|
| 229 |
more_text_search.click(on_new_text_box, more_text_search, [text_input_1, text_relevance_1, more_text_search])
|
| 230 |
+
images_gallery.select(on_focus, None, [detail_gallery, image_description, product_link, page])
|
| 231 |
detail_gallery.select(on_new_image_to_search, detail_gallery, image_input)
|
| 232 |
+
# button_go_to_page.click(on_go_to_product_page, product_link, page)
|
| 233 |
|
| 234 |
# with gr.Tab(label="Search for images"):
|
| 235 |
# labels_input = gr.Text(label="List of labels")
|