File size: 6,644 Bytes
7e0376e
 
 
 
 
 
 
 
 
 
a9e44d5
7e0376e
 
 
 
4d1882c
2e4f4c8
79b27c9
4d1882c
79b27c9
 
 
4d1882c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79b27c9
4d1882c
 
 
 
 
 
 
 
 
 
 
 
 
 
7e0376e
4d1882c
 
 
fbbd4eb
4d1882c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb59e95
79b27c9
4d1882c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79b27c9
4d1882c
 
 
 
 
 
 
79b27c9
4d1882c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79b27c9
4d1882c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7e0376e
 
4d1882c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import logging
import os
import tempfile
import time

import gradio as gr
import numpy as np
import rembg
import torch
from PIL import Image
from functools import partial

from tsr.system import TSR
from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation

#...

css = """
/*... */
"""

with gr.Blocks(theme=CustomTheme(), css=css) as demo:
    #...

    with gr.Column():
        gr.Markdown("**Input Image**")
        input_image = gr.Image(
            label="",
            image_mode="RGBA",
            sources="upload",
            type="pil",
            elem_id="content_image",
            width=500,  # Увеличена ширина входных изображений
        )
        with gr.Column():
            do_remove_background = gr.Checkbox(
                label="Remove Background",
                value=True,
                elem_id="remove_background",
            )
            foreground_ratio = gr.Slider(
                label="Foreground Ratio",
                minimum=0.5,
                maximum=1.0,
                value=0.85,
                step=0.05,
                elem_id="foreground_ratio",
            )
            with gr.Row():
                submit = gr.Button(
                    label="Generate",
                    scale=0,
                    variant="primary",
                    elem_classes="generate-button",
                )
                output_model = gr.Model3D(
                    label="Output Model",
                    interactive=False,
                )
                output_model2 = gr.Model3D(
                    label="Output Model",
                    interactive=False,
                )
            with gr.Tab("obj"):
                output_model = gr.Model3D(
                    label="Output Model",
                    interactive=False,
                )
            with gr.Tab("glb"):
                output_model2 = gr.Model3D(
                    label="Output Model",
                    interactive=False,
                )
            #...

    with gr.Row():
        output_model = gr.Model3D(
            label="Output Model",
            interactive=False,
        )
        output_model2 = gr.Model3D(
            label="Output Model",
            interactive=False,
        )
   

    with gr.Column():
        gr.Markdown("**Input Image**")
        input_image = gr.Image(
            label="",
            image_mode="RGBA",
            sources="upload",
            type="pil",
            elem_id="content_image",
            width=500,  # Увеличена ширина входных изображений
        )
        with gr.Column():
            do_remove_background = gr.Checkbox(
                label="Remove Background",
                value=True,
                elem_id="remove_background",
            )
            foreground_ratio = gr.Slider(
                label="Foreground Ratio",
                minimum=0.5,
                maximum=1.0,
                value=0.85,
                step=0.05,
                elem_id="foreground_ratio",
            )
            with gr.Row():
                submit = gr.Button(
                    label="Generate",
                    scale=0,
                    variant="primary",
                    elem_classes="generate-button",
                )
                output_model = gr.Model3D(
                    label="Output Model",
                    interactive=False,
                )
                output_model2 = gr.Model3D(
                    label="Output Model",
                    interactive=False,
                )
            with gr.Tab("obj"):
                output_model = gr.Model3D(
                    label="Output Model",
                    interactive=False,
                )
                output_model2 = gr.Model3D(
                    label="Output Model",
                    interactive=False,
                )
            with gr.Tab("glb"):
                output_model2 = gr.Model3D(
                    label="Output Model",
                    interactive=False,
                )

    with gr.Column():
        gr.Markdown("**Output Models**")
        output_model = gr.Model3D(label="Output Model", interactive=False)
        output_model2 = gr.Model3D(label="Output Model", interactive=False)

    with gr.Row():
        #...

    with gr.Button("Download Example", elem_id="download_example", fn=partial(run_example, inputs=[input_image], outputs=[input_image, output_model]):
        #...

    with gr.Column():
        gr.Examples(
            examples=[
                "examples/1.png",
                "examples/2.png",
            ],
            inputs=[input_image],
            outputs=[output_model, output_model2],
            fn=partial(run_example),
            label="Examples",
            examples_per_page=20,
        )
        submit.click(
            fn=partial(run_example),
            inputs=[input_image],
            outputs=[output_model, output_model2],
        )

    with gr.Button("Generate", elem_id="generate", variant="primary", fn=generate, inputs=[output_model, output_model2]):
        #...

    with gr.Row():
        output_model = gr.Model3D(
            label="Output Model",
            interactive=False,
        )
        output_model2 = gr.Model3D(
            label="Output Model",
            interactive=False,
        )
    )

    with gr.Column():
        gr.Markdown("**Input Image**")
        input_image = gr.Image(
            label="",
            image_mode="RGBA",
            sources="upload",
            type="pil",
            elem_id="content_image",
            width=500,  # Увеличена ширина входных изображений
        )
        with gr.Column():
            do_remove_background = gr.Checkbox(
                label="Remove Background",
                value=True,
                elem_id="remove_background",
            )
            foreground_ratio = gr.Slider(
                label="Foreground Ratio",
                minimum=0.5,
                maximum=1.0,
                value=0.85,
                step=0.05,
                elem_id="foreground_ratio",
            )
            with gr.Row():
                submit = gr.Button(
                    label="Generate",
                    scale=0,
                    variant="primary",
                    elem_classes="generate-button",
                )
                output_model = gr.Model3D(
                    label="Output Model",
                    interactive=False,
                )
                output_model2