Update app.py
Browse files
app.py
CHANGED
|
@@ -21,6 +21,7 @@ def run(img):
|
|
| 21 |
cloth_seg = generate_mask(img, net=net, palette=palette, device=device)
|
| 22 |
return cloth_seg
|
| 23 |
|
|
|
|
| 24 |
css = '''
|
| 25 |
.container {max-width: 1150px;margin: auto;padding-top: 1.5rem}
|
| 26 |
#image_upload{min-height:400px}
|
|
@@ -33,6 +34,8 @@ css = '''
|
|
| 33 |
#image_upload .touch-none{display: flex}
|
| 34 |
'''
|
| 35 |
|
|
|
|
|
|
|
| 36 |
image_dir = 'input'
|
| 37 |
image_list = [os.path.join(image_dir, file) for file in os.listdir(image_dir)]
|
| 38 |
image_list.sort()
|
|
@@ -40,48 +43,23 @@ image_list.sort()
|
|
| 40 |
with gr.Blocks(css=css) as demo:
|
| 41 |
gr.HTML(read_content("header.html"))
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
value="Upload Image"
|
| 47 |
-
)
|
| 48 |
-
|
| 49 |
-
upload_image = gr.Image(label="Upload Image", type="pil", visible=True)
|
| 50 |
-
webcam_input = gr.Camera(label="Webcam Image", visible=False)
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
)
|
| 62 |
-
|
| 63 |
-
# Logic to toggle input components based on radio selection
|
| 64 |
-
def toggle_inputs(choice):
|
| 65 |
-
return (
|
| 66 |
-
gr.update(visible=choice == "Upload Image"),
|
| 67 |
-
gr.update(visible=choice == "Use Webcam")
|
| 68 |
)
|
|
|
|
| 69 |
|
| 70 |
-
|
| 71 |
-
fn=toggle_inputs,
|
| 72 |
-
inputs=input_method,
|
| 73 |
-
outputs=[upload_image, webcam_input]
|
| 74 |
-
)
|
| 75 |
-
|
| 76 |
-
# Button logic: use the active image component
|
| 77 |
-
def conditional_run(uploaded, webcam, method):
|
| 78 |
-
return run(uploaded if method == "Upload Image" else webcam)
|
| 79 |
-
|
| 80 |
-
btn.click(
|
| 81 |
-
fn=conditional_run,
|
| 82 |
-
inputs=[upload_image, webcam_input, input_method],
|
| 83 |
-
outputs=[image_out]
|
| 84 |
-
)
|
| 85 |
|
| 86 |
gr.HTML(
|
| 87 |
"""
|
|
@@ -95,3 +73,5 @@ with gr.Blocks(css=css) as demo:
|
|
| 95 |
</div>
|
| 96 |
"""
|
| 97 |
)
|
|
|
|
|
|
|
|
|
| 21 |
cloth_seg = generate_mask(img, net=net, palette=palette, device=device)
|
| 22 |
return cloth_seg
|
| 23 |
|
| 24 |
+
# CSS styling
|
| 25 |
css = '''
|
| 26 |
.container {max-width: 1150px;margin: auto;padding-top: 1.5rem}
|
| 27 |
#image_upload{min-height:400px}
|
|
|
|
| 34 |
#image_upload .touch-none{display: flex}
|
| 35 |
'''
|
| 36 |
|
| 37 |
+
# Collect example images
|
| 38 |
+
example = {}
|
| 39 |
image_dir = 'input'
|
| 40 |
image_list = [os.path.join(image_dir, file) for file in os.listdir(image_dir)]
|
| 41 |
image_list.sort()
|
|
|
|
| 43 |
with gr.Blocks(css=css) as demo:
|
| 44 |
gr.HTML(read_content("header.html"))
|
| 45 |
|
| 46 |
+
with gr.Row():
|
| 47 |
+
with gr.Column():
|
| 48 |
+
image = gr.Image(elem_id="image_upload", type="pil", label="Input Image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
with gr.Column():
|
| 51 |
+
image_out = gr.Image(label="Output", elem_id="output-img")
|
| 52 |
|
| 53 |
+
with gr.Row():
|
| 54 |
+
gr.Examples(
|
| 55 |
+
examples=image_list,
|
| 56 |
+
inputs=[image],
|
| 57 |
+
label="Examples - Input Images",
|
| 58 |
+
examples_per_page=12
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
)
|
| 60 |
+
btn = gr.Button("Run!")
|
| 61 |
|
| 62 |
+
btn.click(fn=run, inputs=[image], outputs=[image_out])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
gr.HTML(
|
| 65 |
"""
|
|
|
|
| 73 |
</div>
|
| 74 |
"""
|
| 75 |
)
|
| 76 |
+
|
| 77 |
+
demo.launch()
|