Spaces:
Sleeping
Sleeping
Daniel Varga
commited on
Commit
·
67d87f5
1
Parent(s):
8c28911
filename_textbox
Browse files
app.py
CHANGED
|
@@ -118,11 +118,15 @@ def image_retrieval_from_text(text):
|
|
| 118 |
|
| 119 |
|
| 120 |
def image_retrieval_from_image(state, selected_locally):
|
|
|
|
|
|
|
| 121 |
selected = state[int(selected_locally)]
|
| 122 |
return features_to_gallery(embeddings[selected])
|
| 123 |
|
| 124 |
|
| 125 |
def show_folder(state, selected_locally):
|
|
|
|
|
|
|
| 126 |
selected = state[int(selected_locally)]
|
| 127 |
target_folder = folders[selected]
|
| 128 |
indices = []
|
|
@@ -146,22 +150,27 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
|
|
| 146 |
).style(container=False)
|
| 147 |
text_query_button = gr.Button("Search").style(full_width=False)
|
| 148 |
|
| 149 |
-
gallery = gr.Gallery(label="Images", show_label=False, elem_id="gallery"
|
| 150 |
-
).style(columns=4, container=False)
|
| 151 |
-
|
| 152 |
with gr.Row():
|
| 153 |
show_folder_button = gr.Button("Show folder")
|
| 154 |
image_query_button = gr.Button("Show similar")
|
| 155 |
selected = gr.Number(0, show_label=False, visible=False)
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
text_query_button.click(image_retrieval_from_text, [text], [gallery, state])
|
| 158 |
image_query_button.click(image_retrieval_from_image, [state, selected], [gallery, state])
|
| 159 |
show_folder_button.click(show_folder, [state, selected], [gallery, state])
|
| 160 |
|
| 161 |
-
def get_select_index(evt: gr.SelectData):
|
| 162 |
-
|
|
|
|
|
|
|
| 163 |
|
| 164 |
-
gallery.select(get_select_index,
|
| 165 |
|
| 166 |
|
| 167 |
if __name__ == "__main__":
|
|
|
|
| 118 |
|
| 119 |
|
| 120 |
def image_retrieval_from_image(state, selected_locally):
|
| 121 |
+
if state is None or len(state) == 0:
|
| 122 |
+
return [], []
|
| 123 |
selected = state[int(selected_locally)]
|
| 124 |
return features_to_gallery(embeddings[selected])
|
| 125 |
|
| 126 |
|
| 127 |
def show_folder(state, selected_locally):
|
| 128 |
+
if state is None or len(state) == 0:
|
| 129 |
+
return [], []
|
| 130 |
selected = state[int(selected_locally)]
|
| 131 |
target_folder = folders[selected]
|
| 132 |
indices = []
|
|
|
|
| 150 |
).style(container=False)
|
| 151 |
text_query_button = gr.Button("Search").style(full_width=False)
|
| 152 |
|
|
|
|
|
|
|
|
|
|
| 153 |
with gr.Row():
|
| 154 |
show_folder_button = gr.Button("Show folder")
|
| 155 |
image_query_button = gr.Button("Show similar")
|
| 156 |
selected = gr.Number(0, show_label=False, visible=False)
|
| 157 |
|
| 158 |
+
gallery = gr.Gallery(label="Images", show_label=False, elem_id="gallery"
|
| 159 |
+
).style(columns=4, container=False)
|
| 160 |
+
|
| 161 |
+
with gr.Row():
|
| 162 |
+
filename_textbox = gr.Textbox("", show_label=False).style(container=False)
|
| 163 |
+
|
| 164 |
text_query_button.click(image_retrieval_from_text, [text], [gallery, state])
|
| 165 |
image_query_button.click(image_retrieval_from_image, [state, selected], [gallery, state])
|
| 166 |
show_folder_button.click(show_folder, [state, selected], [gallery, state])
|
| 167 |
|
| 168 |
+
def get_select_index(evt: gr.SelectData, state):
|
| 169 |
+
selected_locally = evt.index
|
| 170 |
+
selected = state[int(selected_locally)]
|
| 171 |
+
return selected_locally, filenames[selected]
|
| 172 |
|
| 173 |
+
gallery.select(get_select_index, [state], [selected, filename_textbox])
|
| 174 |
|
| 175 |
|
| 176 |
if __name__ == "__main__":
|