Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -75,8 +75,17 @@ def process_image(image):
|
|
75 |
pooled_array = encoded_array.max(axis=-1)
|
76 |
return pooled_array # Shape: (1, n_features)
|
77 |
|
78 |
-
def inference(
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
nearest_neighbors = find_nearest_neighbors(encoded_images, input_image, top_n=5)
|
82 |
|
@@ -117,10 +126,9 @@ def inference(image):
|
|
117 |
return result
|
118 |
|
119 |
def load_example(example_name):
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
return image
|
124 |
return None
|
125 |
|
126 |
with gr.Blocks() as demo:
|
@@ -140,21 +148,14 @@ with gr.Blocks() as demo:
|
|
140 |
label="Click an Example Image",
|
141 |
)
|
142 |
|
143 |
-
with gr.
|
144 |
out = gr.Markdown()
|
145 |
|
146 |
-
def
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
return inference(image)
|
152 |
-
else:
|
153 |
-
return "Please upload an image or select an example image."
|
154 |
-
|
155 |
-
inputs = [inp_image, example_selection]
|
156 |
-
outputs = out
|
157 |
-
example_selection.select(handle_selection, inputs, outputs)
|
158 |
|
159 |
if __name__ == "__main__":
|
160 |
demo.launch()
|
|
|
75 |
pooled_array = encoded_array.max(axis=-1)
|
76 |
return pooled_array # Shape: (1, n_features)
|
77 |
|
78 |
+
def inference(user_image=None, selected_example=None)):
|
79 |
+
|
80 |
+
if user_image is not None:
|
81 |
+
input_image = process_image(user_image)
|
82 |
+
elif selected_example is not None:
|
83 |
+
example_image = load_example(selected_example)
|
84 |
+
input_image = process_image(example_image)
|
85 |
+
else:
|
86 |
+
return "Please upload an image or select an example image."
|
87 |
+
|
88 |
+
# input_image = process_image(image)
|
89 |
|
90 |
nearest_neighbors = find_nearest_neighbors(encoded_images, input_image, top_n=5)
|
91 |
|
|
|
126 |
return result
|
127 |
|
128 |
def load_example(example_name):
|
129 |
+
image_path = example_images.get(example_name)
|
130 |
+
if image_path:
|
131 |
+
return Image.open(image_path)
|
|
|
132 |
return None
|
133 |
|
134 |
with gr.Blocks() as demo:
|
|
|
148 |
label="Click an Example Image",
|
149 |
)
|
150 |
|
151 |
+
with gr.Column():
|
152 |
out = gr.Markdown()
|
153 |
|
154 |
+
def handle_inputs(user_image, selected_example):
|
155 |
+
return inference(user_image=user_image, selected_example=selected_example)
|
156 |
+
|
157 |
+
inp_image.change(handle_inputs, inputs=[inp_image, example_selection], outputs=output)
|
158 |
+
example_selection.change(handle_inputs, inputs=[inp_image, example_selection], outputs=output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
if __name__ == "__main__":
|
161 |
demo.launch()
|