Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,6 @@ from constants import *
|
|
16 |
|
17 |
from search import SearchItem
|
18 |
|
19 |
-
from fastapi import FastAPI
|
20 |
|
21 |
|
22 |
|
@@ -33,7 +32,7 @@ fashion_processor = SearchItem(api_key, env)
|
|
33 |
|
34 |
def retrieve_images(query, image=None):
|
35 |
if image:
|
36 |
-
# If image is provided, use retrieve_image_from_image
|
37 |
return retrieve_image_from_image(image, query)
|
38 |
else:
|
39 |
# If image is not provided, use retrieve_image_from_query function
|
@@ -59,10 +58,13 @@ def retrieve_image_from_query(query):
|
|
59 |
|
60 |
return imgs
|
61 |
|
62 |
-
|
63 |
def retrieve_image_from_image(image, query):
|
64 |
|
65 |
try:
|
|
|
|
|
|
|
66 |
# create sparse and dense vectors
|
67 |
sparse = fashion_processor.bm25.encode_queries(query)
|
68 |
w, h = 60, 80
|
@@ -98,17 +100,20 @@ with gr.Blocks() as demo:
|
|
98 |
"""
|
99 |
# Shopping Search Engine
|
100 |
|
101 |
-
Look for the ideal clothing items
|
102 |
""")
|
103 |
-
|
|
|
104 |
with gr.Row():
|
105 |
with gr.Column():
|
106 |
|
107 |
query = gr.Textbox(placeholder="Search Items")
|
108 |
-
gr.HTML("OR")
|
109 |
photo = gr.Image()
|
110 |
with gr.Row():
|
|
|
111 |
button = gr.UploadButton(label="Upload Image", file_types=["image"])
|
|
|
112 |
textbox = gr.Textbox(placeholder="Additional Details ?")
|
113 |
submit_button = gr.Button(text="Submit")
|
114 |
|
@@ -120,8 +125,7 @@ with gr.Blocks() as demo:
|
|
120 |
)
|
121 |
|
122 |
query.submit(fn=lambda query: retrieve_images(query), inputs=[query], outputs=[gallery])
|
|
|
123 |
submit_button.click(fn=lambda image, query: show_img(image), inputs=[button, textbox], outputs=[photo]) \
|
124 |
.then(fn=lambda image, query: retrieve_images(query, image), inputs=[button, textbox], outputs=[gallery])
|
125 |
-
|
126 |
-
#demo.launch(server_name="0.0.0.0", server_port=8000)
|
127 |
-
demo.launch()
|
|
|
16 |
|
17 |
from search import SearchItem
|
18 |
|
|
|
19 |
|
20 |
|
21 |
|
|
|
32 |
|
33 |
def retrieve_images(query, image=None):
|
34 |
if image:
|
35 |
+
# If image is provided, use retrieve_image_from_image function
|
36 |
return retrieve_image_from_image(image, query)
|
37 |
else:
|
38 |
# If image is not provided, use retrieve_image_from_query function
|
|
|
58 |
|
59 |
return imgs
|
60 |
|
61 |
+
|
62 |
def retrieve_image_from_image(image, query):
|
63 |
|
64 |
try:
|
65 |
+
if query is None:
|
66 |
+
query = 'No image'
|
67 |
+
|
68 |
# create sparse and dense vectors
|
69 |
sparse = fashion_processor.bm25.encode_queries(query)
|
70 |
w, h = 60, 80
|
|
|
100 |
"""
|
101 |
# Shopping Search Engine
|
102 |
|
103 |
+
Look for the ideal clothing items 😆
|
104 |
""")
|
105 |
+
|
106 |
+
|
107 |
with gr.Row():
|
108 |
with gr.Column():
|
109 |
|
110 |
query = gr.Textbox(placeholder="Search Items")
|
111 |
+
gr.HTML("OR LOAD IMAGE AND SPECIFIC TEXT DETAILS")
|
112 |
photo = gr.Image()
|
113 |
with gr.Row():
|
114 |
+
file_output = gr.File()
|
115 |
button = gr.UploadButton(label="Upload Image", file_types=["image"])
|
116 |
+
button.upload(show_img, button, file_output)
|
117 |
textbox = gr.Textbox(placeholder="Additional Details ?")
|
118 |
submit_button = gr.Button(text="Submit")
|
119 |
|
|
|
125 |
)
|
126 |
|
127 |
query.submit(fn=lambda query: retrieve_images(query), inputs=[query], outputs=[gallery])
|
128 |
+
|
129 |
submit_button.click(fn=lambda image, query: show_img(image), inputs=[button, textbox], outputs=[photo]) \
|
130 |
.then(fn=lambda image, query: retrieve_images(query, image), inputs=[button, textbox], outputs=[gallery])
|
131 |
+
demo.launch(share=True)
|
|
|
|