dragynir commited on
Commit
f90b693
·
1 Parent(s): 9d5ecbc

add example app

Browse files
example_app.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()
examples/input_03615_00.jpg ADDED
examples/input_08909_00.jpg ADDED
header.html ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div style="text-align: center; max-width: 650px; margin: 0 auto;">
2
+ <div style="
3
+ display: inline-flex;
4
+ gap: 0.8rem;
5
+ font-size: 1.75rem;
6
+ justify-content: center;
7
+ margin-bottom: 10px;
8
+ ">
9
+ <h1 style="font-weight: 900; align-items: center; margin-bottom: 7px; margin-top: 20px;">
10
+ Cloth Segmentation
11
+ </h1>
12
+ </div>
13
+ <div>
14
+ <p style="align-items: center; margin-bottom: 7px;">
15
+ Cloth Segmentation gradio demo script using pre-trained U2NET. Extract fashion from Human potrait.
16
+ </p>
17
+ <p style="align-items: center; margin-bottom: 7px;">
18
+ Upload a image and wait for the model to generate the segmentation map.
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="https://github.com/wildoctopus/huggingface-cloth-segmentation">Github Repo</a> 😊.
22
+ </p>
23
+ <p>You can skip the queue by duplicating this space and upgrading to gpu in settings.
24
+
25
+ </div>
26
+ </div>