Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -81,8 +81,7 @@ def inference(user_image=None, selected_example=None):
|
|
| 81 |
input_image = process_image(user_image)
|
| 82 |
elif selected_example is not None:
|
| 83 |
print(selected_example)
|
| 84 |
-
|
| 85 |
-
input_image = process_image(example_image)
|
| 86 |
else:
|
| 87 |
return "Please upload an image or select an example image."
|
| 88 |
|
|
@@ -142,22 +141,28 @@ with gr.Blocks() as demo:
|
|
| 142 |
)
|
| 143 |
with gr.Row():
|
| 144 |
with gr.Column():
|
| 145 |
-
inp_image = gr.Image(label="Upload Image")
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
label="Click an Example Image",
|
| 150 |
type="value"
|
| 151 |
)
|
| 152 |
-
|
| 153 |
with gr.Column():
|
| 154 |
output = gr.Markdown()
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
def handle_inputs(user_image, selected_example):
|
| 157 |
return inference(user_image=user_image, selected_example=selected_example)
|
| 158 |
|
| 159 |
-
inp_image.change(handle_inputs, inputs=[inp_image, example_selection], outputs=output)
|
| 160 |
-
example_selection.change(handle_inputs, inputs=[inp_image, example_selection], outputs=output)
|
| 161 |
|
| 162 |
if __name__ == "__main__":
|
| 163 |
demo.launch()
|
|
|
|
| 81 |
input_image = process_image(user_image)
|
| 82 |
elif selected_example is not None:
|
| 83 |
print(selected_example)
|
| 84 |
+
input_image = process_image(selected_example)
|
|
|
|
| 85 |
else:
|
| 86 |
return "Please upload an image or select an example image."
|
| 87 |
|
|
|
|
| 141 |
)
|
| 142 |
with gr.Row():
|
| 143 |
with gr.Column():
|
| 144 |
+
inp_image = gr.Image(label="Upload Image", type="pil")
|
| 145 |
+
example_selection = gr.Radio(
|
| 146 |
+
choices=list(example_images.keys()),
|
| 147 |
+
label="Select Example Image",
|
|
|
|
| 148 |
type="value"
|
| 149 |
)
|
|
|
|
| 150 |
with gr.Column():
|
| 151 |
output = gr.Markdown()
|
| 152 |
|
| 153 |
+
# Handle user image input
|
| 154 |
+
inp_image.change(handle_inputs, inputs=[inp_image, example_selection], outputs=output)
|
| 155 |
+
|
| 156 |
+
# Handle example image selection
|
| 157 |
+
example_selection.change(
|
| 158 |
+
handle_inputs,
|
| 159 |
+
inputs=[inp_image, example_selection], # This allows example image selection without needing to upload
|
| 160 |
+
outputs=output
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
def handle_inputs(user_image, selected_example):
|
| 164 |
return inference(user_image=user_image, selected_example=selected_example)
|
| 165 |
|
|
|
|
|
|
|
| 166 |
|
| 167 |
if __name__ == "__main__":
|
| 168 |
demo.launch()
|