Spaces:
Runtime error
Runtime error
Commit
·
67242d6
1
Parent(s):
2643d32
Temporary fix for image search examples
Browse files
app.py
CHANGED
|
@@ -90,7 +90,10 @@ def get_bar_plot(labels, probs):
|
|
| 90 |
return fig
|
| 91 |
|
| 92 |
def get_image_url_in_state(url):
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
css = """
|
| 96 |
.gradio-container {background-color: beige}
|
|
@@ -128,17 +131,22 @@ with gr.Blocks(theme=theme, title="New Look", css=css) as demo:
|
|
| 128 |
text_input = gr.Text(label="Search with text:")
|
| 129 |
text_relevance = gr.Slider(label="Text search relevance", minimum = -5, maximum = 5, value = 1, step = 1)
|
| 130 |
image_input = gr.Image(type="pil", label="Search with an image")
|
| 131 |
-
|
| 132 |
image_relevance = gr.Slider(label="Image search relevance", minimum = -5, maximum = 5, value = 1, step = 1)
|
| 133 |
with gr.Row():
|
| 134 |
gr.Examples(["Green", "Red", "Blue", "Sleeveless", "V-Neck", "Long dress, sleeveless, red"], text_input)
|
| 135 |
gr.Markdown()
|
| 136 |
gr.Examples(
|
| 137 |
-
["https://media2.newlookassets.com/i/newlook/869030934/womens/clothing/dresses/khaki-utility-mini-shirt-dress.jpg?strip=true&qlt=50&w=1400",
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
)
|
| 143 |
gr.Markdown()
|
| 144 |
# with gr.Row().style(equal_height=False):
|
|
@@ -208,7 +216,7 @@ with gr.Blocks(theme=theme, title="New Look", css=css) as demo:
|
|
| 208 |
gr.Markdown()
|
| 209 |
|
| 210 |
|
| 211 |
-
def search(text_input, image_input,
|
| 212 |
if text_input == "" and image_input == None:
|
| 213 |
empty_response = [None] * 5
|
| 214 |
empty_response.append("")
|
|
@@ -217,14 +225,14 @@ with gr.Blocks(theme=theme, title="New Look", css=css) as demo:
|
|
| 217 |
if text_input == "":
|
| 218 |
# load_image(image_input)
|
| 219 |
# query = "/images/images/img_path.jpg"
|
| 220 |
-
query =
|
| 221 |
elif image_input == None:
|
| 222 |
query = text_input
|
| 223 |
else:
|
| 224 |
query = dict()
|
| 225 |
# load_image(image_input)
|
| 226 |
# query["/images/images/img_path.jpg"] = image_relevance
|
| 227 |
-
query[
|
| 228 |
query[text_input] = text_relevance
|
| 229 |
|
| 230 |
list_image_results = []
|
|
@@ -244,7 +252,7 @@ with gr.Blocks(theme=theme, title="New Look", css=css) as demo:
|
|
| 244 |
|
| 245 |
|
| 246 |
search_button.click(
|
| 247 |
-
search, [text_input, image_input,
|
| 248 |
)
|
| 249 |
|
| 250 |
compute_button.click(
|
|
|
|
| 90 |
return fig
|
| 91 |
|
| 92 |
def get_image_url_in_state(url):
|
| 93 |
+
# print("##### URL")
|
| 94 |
+
# print(url)
|
| 95 |
+
full_url = "https://" + url
|
| 96 |
+
return full_url, full_url
|
| 97 |
|
| 98 |
css = """
|
| 99 |
.gradio-container {background-color: beige}
|
|
|
|
| 131 |
text_input = gr.Text(label="Search with text:")
|
| 132 |
text_relevance = gr.Slider(label="Text search relevance", minimum = -5, maximum = 5, value = 1, step = 1)
|
| 133 |
image_input = gr.Image(type="pil", label="Search with an image")
|
| 134 |
+
image_path = gr.State(visible=False)
|
| 135 |
image_relevance = gr.Slider(label="Image search relevance", minimum = -5, maximum = 5, value = 1, step = 1)
|
| 136 |
with gr.Row():
|
| 137 |
gr.Examples(["Green", "Red", "Blue", "Sleeveless", "V-Neck", "Long dress, sleeveless, red"], text_input)
|
| 138 |
gr.Markdown()
|
| 139 |
gr.Examples(
|
| 140 |
+
[["https://media2.newlookassets.com/i/newlook/869030934/womens/clothing/dresses/khaki-utility-mini-shirt-dress.jpg?strip=true&qlt=50&w=1400",
|
| 141 |
+
"https://media2.newlookassets.com/i/newlook/869030934/womens/clothing/dresses/khaki-utility-mini-shirt-dress.jpg?strip=true&qlt=50&w=1400"],
|
| 142 |
+
["https://media3.newlookassets.com/i/newlook/872692409/womens/clothing/dresses/black-floral-lace-trim-mini-dress.jpg?strip=true&qlt=50&w=1400",
|
| 143 |
+
"https://media3.newlookassets.com/i/newlook/872692409/womens/clothing/dresses/black-floral-lace-trim-mini-dress.jpg?strip=true&qlt=50&w=1400"]],
|
| 144 |
+
# ["media2.newlookassets.com/i/newlook/869030934/womens/clothing/dresses/khaki-utility-mini-shirt-dress.jpg?strip=true&qlt=50&w=1400",
|
| 145 |
+
# "media3.newlookassets.com/i/newlook/872692409/womens/clothing/dresses/black-floral-lace-trim-mini-dress.jpg?strip=true&qlt=50&w=1400"],
|
| 146 |
+
# image_path,
|
| 147 |
+
[image_input, image_path],
|
| 148 |
+
# get_image_url_in_state,
|
| 149 |
+
# cache_examples=True
|
| 150 |
)
|
| 151 |
gr.Markdown()
|
| 152 |
# with gr.Row().style(equal_height=False):
|
|
|
|
| 216 |
gr.Markdown()
|
| 217 |
|
| 218 |
|
| 219 |
+
def search(text_input, image_input, image_path, text_relevance, image_relevance, best_seller_score_weight):
|
| 220 |
if text_input == "" and image_input == None:
|
| 221 |
empty_response = [None] * 5
|
| 222 |
empty_response.append("")
|
|
|
|
| 225 |
if text_input == "":
|
| 226 |
# load_image(image_input)
|
| 227 |
# query = "/images/images/img_path.jpg"
|
| 228 |
+
query = image_path
|
| 229 |
elif image_input == None:
|
| 230 |
query = text_input
|
| 231 |
else:
|
| 232 |
query = dict()
|
| 233 |
# load_image(image_input)
|
| 234 |
# query["/images/images/img_path.jpg"] = image_relevance
|
| 235 |
+
query[image_path] = image_relevance
|
| 236 |
query[text_input] = text_relevance
|
| 237 |
|
| 238 |
list_image_results = []
|
|
|
|
| 252 |
|
| 253 |
|
| 254 |
search_button.click(
|
| 255 |
+
search, [text_input, image_input, image_path, text_relevance, image_relevance, best_seller_score_weight], [image_res_1, image_res_2, image_res_3, image_res_4, image_res_5, response]
|
| 256 |
)
|
| 257 |
|
| 258 |
compute_button.click(
|