Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -13,20 +13,18 @@ from functools import partial
|
|
13 |
from tsr.system import TSR
|
14 |
from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation
|
15 |
|
16 |
-
#HF_TOKEN = os.getenv("HF_TOKEN")
|
17 |
|
18 |
HEADER = """
|
19 |
-
|
20 |
"""
|
21 |
|
22 |
-
|
23 |
if torch.cuda.is_available():
|
24 |
device = "cuda:0"
|
25 |
else:
|
26 |
device = "cpu"
|
27 |
|
28 |
d = os.environ.get("DEVICE", None)
|
29 |
-
if d
|
30 |
device = d
|
31 |
|
32 |
model = TSR.from_pretrained(
|
@@ -80,56 +78,109 @@ def run_example(image_pil):
|
|
80 |
mesh_name, mesn_name2 = generate(preprocessed)
|
81 |
return preprocessed, mesh_name, mesh_name2
|
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 |
submit.click(fn=check_input_image, inputs=[input_image]).success(
|
134 |
fn=preprocess,
|
135 |
inputs=[input_image, do_remove_background, foreground_ratio],
|
@@ -141,4 +192,4 @@ with gr.Blocks() as demo:
|
|
141 |
)
|
142 |
|
143 |
demo.queue(max_size=10)
|
144 |
-
demo.launch()
|
|
|
13 |
from tsr.system import TSR
|
14 |
from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation
|
15 |
|
16 |
+
# HF_TOKEN = os.getenv("HF_TOKEN")
|
17 |
|
18 |
HEADER = """
|
|
|
19 |
"""
|
20 |
|
|
|
21 |
if torch.cuda.is_available():
|
22 |
device = "cuda:0"
|
23 |
else:
|
24 |
device = "cpu"
|
25 |
|
26 |
d = os.environ.get("DEVICE", None)
|
27 |
+
if d!= None:
|
28 |
device = d
|
29 |
|
30 |
model = TSR.from_pretrained(
|
|
|
78 |
mesh_name, mesn_name2 = generate(preprocessed)
|
79 |
return preprocessed, mesh_name, mesh_name2
|
80 |
|
81 |
+
class CustomTheme(gr.themes.Base):
|
82 |
+
def __init__(self):
|
83 |
+
super().__init__()
|
84 |
+
self.primary_hue = "#191a1e"
|
85 |
+
self.background_fill_primary = "#191a1e"
|
86 |
+
self.background_fill_secondary = "#191a1e"
|
87 |
+
self.background_fill_tertiary = "#191a1e"
|
88 |
+
self.text_color_primary = "#FFFFFF"
|
89 |
+
self.text_color_secondary = "#FFFFFF"
|
90 |
+
self.text_color_tertiary = "#FFFFFF"
|
91 |
+
self.input_background_fill = "#191a1e"
|
92 |
+
self.input_text_color = "#FFFFFF"
|
93 |
+
|
94 |
+
css = """
|
95 |
+
/* Скрываем нижний колонтитул */
|
96 |
+
footer {
|
97 |
+
visibility: hidden;
|
98 |
+
height: 0;
|
99 |
+
margin: 0;
|
100 |
+
padding: 0;
|
101 |
+
overflow: hidden;
|
102 |
+
}
|
103 |
+
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&display=swap');
|
104 |
+
/* Применяем шрифты */
|
105 |
+
body, input, button, textarea, select,.gr-button {
|
106 |
+
font-family: 'Poppins', sans-serif;
|
107 |
+
background-color: #191a1e!important;
|
108 |
+
color: #FFFFFF;
|
109 |
+
}
|
110 |
+
/* Настройки заголовков */
|
111 |
+
h1, h2, h3, h4, h5, h6 {
|
112 |
+
font-family: 'Poppins', sans-serif;
|
113 |
+
font-weight: 700;
|
114 |
+
color: #FFFFFF;
|
115 |
+
}
|
116 |
+
/* Стиль для текстовых полей и кнопок */
|
117 |
+
input[type="text"], textarea {
|
118 |
+
background-color: #191a1e!important;
|
119 |
+
color: #FFFFFF;
|
120 |
+
border: 1px solid #FFFFFF;
|
121 |
+
}
|
122 |
+
/* Цвет кнопки Generate */
|
123 |
+
.generate-button {
|
124 |
+
background-color: #5271FF!important;
|
125 |
+
color: #FFFFFF!important;
|
126 |
+
border: none;
|
127 |
+
font-weight: bold;
|
128 |
+
}
|
129 |
+
.generate-button:hover {
|
130 |
+
background-color: #405BBF!important; /* Цвет при наведении */
|
131 |
+
}
|
132 |
+
/* Выделяем текст для Prompt */
|
133 |
+
.prompt-text {
|
134 |
+
font-weight: bold;
|
135 |
+
color: #FFFFFF;
|
136 |
+
}
|
137 |
+
"""
|
138 |
+
|
139 |
+
with gr.Blocks(theme=CustomTheme(), css=css) as demo:
|
140 |
+
with gr.Column(elem_id="col-container"):
|
141 |
+
gr.Markdown("**Input Image**", elem_classes="prompt-text")
|
142 |
+
|
143 |
+
with gr.Row():
|
144 |
+
input_image = gr.Image(
|
145 |
+
label="",
|
146 |
+
image_mode="RGBA",
|
147 |
+
sources="upload",
|
148 |
+
type="pil",
|
149 |
+
container=False,
|
150 |
+
)
|
151 |
+
with gr.Group():
|
152 |
+
do_remove_background = gr.Checkbox(
|
153 |
+
label="Remove Background", value=True
|
154 |
)
|
155 |
+
foreground_ratio = gr.Slider(
|
156 |
+
label="Foreground Ratio",
|
157 |
+
minimum=0.5,
|
158 |
+
maximum=1.0,
|
159 |
+
value=0.85,
|
160 |
+
step=0.05,
|
161 |
)
|
162 |
+
|
163 |
+
processed_image = gr.Image(label="Processed Image", interactive=False)
|
164 |
+
|
165 |
+
with gr.Row():
|
166 |
+
submit = gr.Button(
|
167 |
+
"Generate",
|
168 |
+
scale=0,
|
169 |
+
variant="primary",
|
170 |
+
elem_classes="generate-button",
|
171 |
+
)
|
172 |
+
|
173 |
+
with gr.Tab("obj"):
|
174 |
+
output_model = gr.Model3D(
|
175 |
+
label="Output Model",
|
176 |
+
interactive=False,
|
177 |
+
)
|
178 |
+
with gr.Tab("glb"):
|
179 |
+
output_model2 = gr.Model3D(
|
180 |
+
label="Output Model",
|
181 |
+
interactive=False,
|
182 |
+
)
|
183 |
+
|
184 |
submit.click(fn=check_input_image, inputs=[input_image]).success(
|
185 |
fn=preprocess,
|
186 |
inputs=[input_image, do_remove_background, foreground_ratio],
|
|
|
192 |
)
|
193 |
|
194 |
demo.queue(max_size=10)
|
195 |
+
demo.launch()
|