Spaces:
Runtime error
Runtime error
add headers
Browse files- app.py +26 -1
- example_app.py +0 -110
- header.html +4 -4
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import numpy as np
|
2 |
import torch
|
3 |
import gradio as gr
|
@@ -24,15 +26,38 @@ def process(input_image: np.ndarray, prompt: str):
|
|
24 |
]
|
25 |
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
block = gr.Blocks().queue()
|
28 |
with block:
|
29 |
with gr.Row():
|
30 |
-
gr.
|
31 |
with gr.Row():
|
32 |
with gr.Column():
|
33 |
input_image = gr.Image(type="numpy")
|
34 |
prompt = gr.Textbox(label="Prompt")
|
35 |
run_button = gr.Button(value="Run")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
with gr.Column():
|
38 |
result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery")
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
import numpy as np
|
4 |
import torch
|
5 |
import gradio as gr
|
|
|
26 |
]
|
27 |
|
28 |
|
29 |
+
def read_content(file_path: str) -> str:
|
30 |
+
"""read the content of target file
|
31 |
+
"""
|
32 |
+
with open(file_path, 'r', encoding='utf-8') as f:
|
33 |
+
content = f.read()
|
34 |
+
|
35 |
+
return content
|
36 |
+
|
37 |
+
|
38 |
+
image_dir = 'examples'
|
39 |
+
image_list = [os.path.join(image_dir, file) for file in os.listdir(image_dir)]
|
40 |
+
|
41 |
block = gr.Blocks().queue()
|
42 |
with block:
|
43 |
with gr.Row():
|
44 |
+
gr.HTML(read_content("header.html"))
|
45 |
with gr.Row():
|
46 |
with gr.Column():
|
47 |
input_image = gr.Image(type="numpy")
|
48 |
prompt = gr.Textbox(label="Prompt")
|
49 |
run_button = gr.Button(value="Run")
|
50 |
+
gr.Examples(image_list, inputs=[input_image], label="Examples - Input Images", examples_per_page=12)
|
51 |
+
|
52 |
+
gr.HTML(
|
53 |
+
"""
|
54 |
+
<div class="footer">
|
55 |
+
|
56 |
+
<p> This repo based on Unet from <a style="text-decoration: underline;" href="https://huggingface.co/spaces/wildoctopus/cloth-segmentation">cloth-segmentation</a>
|
57 |
+
It's uses pre-trained U2NET to extract Upper body(red), Lower body(green), Full body(blue) masks, and then
|
58 |
+
run StableDiffusionXLControlNetPipeline with trained controlnet to generate image conditioned on this masks.
|
59 |
+
</p>
|
60 |
+
""")
|
61 |
|
62 |
with gr.Column():
|
63 |
result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery")
|
example_app.py
DELETED
@@ -1,110 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
|
3 |
-
import gradio as gr
|
4 |
-
|
5 |
-
|
6 |
-
def read_content(file_path: str) -> str:
|
7 |
-
"""read the content of target file
|
8 |
-
"""
|
9 |
-
with open(file_path, 'r', encoding='utf-8') as f:
|
10 |
-
content = f.read()
|
11 |
-
|
12 |
-
return content
|
13 |
-
|
14 |
-
|
15 |
-
def run(img):
|
16 |
-
return img
|
17 |
-
|
18 |
-
|
19 |
-
# Define input and output interfaces
|
20 |
-
input_image = gr.Image(label="Input Image", type="pil")
|
21 |
-
|
22 |
-
# Define the Gradio interface
|
23 |
-
cloth_seg_image = gr.Image(label="Cloth Segmentation", type="pil")
|
24 |
-
|
25 |
-
title = "Demo for Cloth Segmentation"
|
26 |
-
description = "An app for Cloth Segmentation"
|
27 |
-
inputs = [input_image]
|
28 |
-
outputs = [cloth_seg_image]
|
29 |
-
|
30 |
-
css = '''
|
31 |
-
.container {max-width: 1150px;margin: auto;padding-top: 1.5rem}
|
32 |
-
#image_upload{min-height:400px}
|
33 |
-
#image_upload [data-testid="image"], #image_upload [data-testid="image"] > div{min-height: 400px}
|
34 |
-
#mask_radio .gr-form{background:transparent; border: none}
|
35 |
-
#word_mask{margin-top: .75em !important}
|
36 |
-
#word_mask textarea:disabled{opacity: 0.3}
|
37 |
-
.footer {margin-bottom: 45px;margin-top: 35px;text-align: center;border-bottom: 1px solid #e5e5e5}
|
38 |
-
.footer>p {font-size: .8rem; display: inline-block; padding: 0 10px;transform: translateY(10px);background: white}
|
39 |
-
.dark .footer {border-color: #303030}
|
40 |
-
.dark .footer>p {background: #0b0f19}
|
41 |
-
.acknowledgments h4{margin: 1.25em 0 .25em 0;font-weight: bold;font-size: 115%}
|
42 |
-
#image_upload .touch-none{display: flex}
|
43 |
-
@keyframes spin {
|
44 |
-
from {
|
45 |
-
transform: rotate(0deg);
|
46 |
-
}
|
47 |
-
to {
|
48 |
-
transform: rotate(360deg);
|
49 |
-
}
|
50 |
-
}
|
51 |
-
#share-btn-container {
|
52 |
-
display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
|
53 |
-
}
|
54 |
-
#share-btn {
|
55 |
-
all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;
|
56 |
-
}
|
57 |
-
#share-btn * {
|
58 |
-
all: unset;
|
59 |
-
}
|
60 |
-
#share-btn-container div:nth-child(-n+2){
|
61 |
-
width: auto !important;
|
62 |
-
min-height: 0px !important;
|
63 |
-
}
|
64 |
-
#share-btn-container .wrap {
|
65 |
-
display: none !important;
|
66 |
-
}
|
67 |
-
'''
|
68 |
-
example = {}
|
69 |
-
image_dir = 'examples'
|
70 |
-
|
71 |
-
image_list = [os.path.join(image_dir, file) for file in os.listdir(image_dir)]
|
72 |
-
image_list.sort()
|
73 |
-
|
74 |
-
image_blocks = gr.Blocks(css=css)
|
75 |
-
with image_blocks as demo:
|
76 |
-
gr.HTML(read_content("header.html"))
|
77 |
-
with gr.Group():
|
78 |
-
with gr.Group():
|
79 |
-
with gr.Row():
|
80 |
-
with gr.Column():
|
81 |
-
image = gr.Image(elem_id="image_upload", type="pil", label="Input Image")
|
82 |
-
|
83 |
-
with gr.Column():
|
84 |
-
image_out = gr.Image(label="Output", elem_id="output-img")
|
85 |
-
|
86 |
-
with gr.Row():
|
87 |
-
with gr.Column():
|
88 |
-
gr.Examples(image_list, inputs=[image], label="Examples - Input Images", examples_per_page=12)
|
89 |
-
with gr.Column():
|
90 |
-
with gr.Row(elem_id="prompt-container"):
|
91 |
-
btn = gr.Button("Run!")
|
92 |
-
|
93 |
-
btn.click(fn=run, inputs=[image], outputs=[image_out])
|
94 |
-
|
95 |
-
gr.HTML(
|
96 |
-
"""
|
97 |
-
<div class="footer">
|
98 |
-
<p>Model by <a href="" style="text-decoration: underline;" target="_blank">WildOctopus</a> - Gradio Demo by π€ Hugging Face
|
99 |
-
</p>
|
100 |
-
</div>
|
101 |
-
<div class="acknowledgments">
|
102 |
-
<p><h4>ACKNOWLEDGEMENTS</h4></p>
|
103 |
-
<p>
|
104 |
-
U2net model is from original u2net repo. Thanks to <a href="https://github.com/xuebinqin/U-2-Net" style="text-decoration: underline;" target="_blank">Xuebin Qin</a> for amazing repo.</p>
|
105 |
-
<p>Codes are modified from <a href="https://github.com/levindabhi/cloth-segmentation" style="text-decoration: underline;" target="_blank">levindabhi/cloth-segmentation</a>
|
106 |
-
</p>
|
107 |
-
"""
|
108 |
-
)
|
109 |
-
|
110 |
-
image_blocks.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
header.html
CHANGED
@@ -7,18 +7,18 @@
|
|
7 |
margin-bottom: 10px;
|
8 |
">
|
9 |
<h1 style="font-weight: 900; align-items: center; margin-bottom: 7px; margin-top: 20px;">
|
10 |
-
|
11 |
</h1>
|
12 |
</div>
|
13 |
<div>
|
14 |
<p style="align-items: center; margin-bottom: 7px;">
|
15 |
-
|
16 |
</p>
|
17 |
<p style="align-items: center; margin-bottom: 7px;">
|
18 |
-
Upload
|
19 |
</p>
|
20 |
<p style="align-items: center; margin-bottom: 7px;">
|
21 |
-
If you like this demo, please help to β the <a style="text-decoration: underline;" href="
|
22 |
</p>
|
23 |
<p>You can skip the queue by duplicating this space and upgrading to gpu in settings.
|
24 |
|
|
|
7 |
margin-bottom: 10px;
|
8 |
">
|
9 |
<h1 style="font-weight: 900; align-items: center; margin-bottom: 7px; margin-top: 20px;">
|
10 |
+
Fashion Controlnet SDXL-1.0
|
11 |
</h1>
|
12 |
</div>
|
13 |
<div>
|
14 |
<p style="align-items: center; margin-bottom: 7px;">
|
15 |
+
Image generation gradio demo condition on clothes.
|
16 |
</p>
|
17 |
<p style="align-items: center; margin-bottom: 7px;">
|
18 |
+
Upload an image, enter prompt and wait for the model to generate the image.
|
19 |
</p>
|
20 |
<p style="align-items: center; margin-bottom: 7px;">
|
21 |
+
If you like this demo, please help to β the <a style="text-decoration: underline;" href="TODO">Github Repo</a> π.
|
22 |
</p>
|
23 |
<p>You can skip the queue by duplicating this space and upgrading to gpu in settings.
|
24 |
|