Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import time # Для эмуляции времени загрузки
|
3 |
import tempfile
|
@@ -57,13 +59,19 @@ def generate(image):
|
|
57 |
return mesh_path2.name
|
58 |
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
64 |
|
65 |
-
def stop_loading():
|
66 |
-
return "
|
|
|
|
|
|
|
67 |
|
68 |
|
69 |
# Настройка темы и CSS
|
@@ -82,8 +90,7 @@ class CustomTheme(gr.themes.Base):
|
|
82 |
|
83 |
|
84 |
css = """
|
85 |
-
|
86 |
-
footer {
|
87 |
visibility: hidden;
|
88 |
height: 0;
|
89 |
margin: 0;
|
@@ -115,23 +122,23 @@ input[type="text"], textarea {
|
|
115 |
|
116 |
/* Слайдер */
|
117 |
.gr-slider {
|
118 |
-
height: 40px !important;
|
119 |
-
transition: all 0.3s ease !important;
|
120 |
}
|
121 |
|
122 |
.gr-slider .slider-value {
|
123 |
-
display: none !important;
|
124 |
}
|
125 |
|
126 |
.gr-slider .slider::-webkit-slider-thumb {
|
127 |
height: 15px !important;
|
128 |
width: 15px !important;
|
129 |
-
background-color: #5271FF !important;
|
130 |
border-radius: 50%;
|
131 |
}
|
132 |
|
133 |
.gr-slider .slider::-webkit-slider-runnable-track {
|
134 |
-
background: #5271FF !important;
|
135 |
}
|
136 |
|
137 |
/* Кнопка Generate */
|
@@ -143,7 +150,7 @@ input[type="text"], textarea {
|
|
143 |
}
|
144 |
|
145 |
.generate-button:hover {
|
146 |
-
background-color: #405BBF !important;
|
147 |
}
|
148 |
|
149 |
/* Выделяем текст для Prompt */
|
@@ -152,9 +159,16 @@ input[type="text"], textarea {
|
|
152 |
color: #FFFFFF;
|
153 |
}
|
154 |
|
155 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
#loading-bar {
|
157 |
-
display: none;
|
158 |
position: absolute;
|
159 |
top: 50%;
|
160 |
left: 50%;
|
@@ -162,9 +176,10 @@ input[type="text"], textarea {
|
|
162 |
width: 60px;
|
163 |
height: 60px;
|
164 |
border: 8px solid #f3f3f3;
|
165 |
-
border-top: 8px solid #5271FF;
|
166 |
border-radius: 50%;
|
167 |
animation: spin 1s linear infinite;
|
|
|
168 |
}
|
169 |
|
170 |
/* Анимация вращения */
|
@@ -177,6 +192,19 @@ input[type="text"], textarea {
|
|
177 |
.gr-checkbox label {
|
178 |
color: #FFFFFF !important;
|
179 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
"""
|
181 |
|
182 |
# Интерфейс
|
@@ -184,20 +212,26 @@ with gr.Blocks(theme=CustomTheme(), css=css) as demo:
|
|
184 |
with gr.Column():
|
185 |
gr.Markdown("<span style='color: white; font-weight: bold;'>Upload and Process Your Image</span>")
|
186 |
with gr.Row():
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
foreground_ratio = gr.Slider(
|
202 |
label="Foreground Ratio",
|
203 |
minimum=0.5,
|
@@ -206,42 +240,59 @@ with gr.Blocks(theme=CustomTheme(), css=css) as demo:
|
|
206 |
step=0.05,
|
207 |
)
|
208 |
do_remove_background = gr.Checkbox(
|
209 |
-
label="Remove Background",
|
210 |
value=True,
|
211 |
)
|
212 |
submit = gr.Button("Generate", elem_classes="generate-button")
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
|
|
219 |
|
|
|
220 |
submit.click(
|
221 |
-
fn=
|
222 |
-
|
223 |
-
|
224 |
).then(
|
225 |
fn=check_input_image,
|
226 |
inputs=[input_image],
|
227 |
-
outputs=[]
|
|
|
|
|
|
|
|
|
228 |
).then(
|
229 |
fn=preprocess,
|
230 |
inputs=[input_image, do_remove_background, foreground_ratio],
|
231 |
-
outputs=[processed_image]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
).then(
|
233 |
fn=generate,
|
234 |
inputs=[processed_image],
|
235 |
-
outputs=[output_model]
|
|
|
|
|
|
|
|
|
236 |
).then(
|
237 |
-
fn=
|
238 |
-
|
239 |
-
|
240 |
)
|
241 |
-
|
242 |
# Запуск приложения
|
243 |
demo.launch(
|
244 |
server_name="0.0.0.0",
|
245 |
server_port=7860,
|
246 |
share=True,
|
247 |
-
)
|
|
|
1 |
+
|
2 |
+
|
3 |
import gradio as gr
|
4 |
import time # Для эмуляции времени загрузки
|
5 |
import tempfile
|
|
|
59 |
return mesh_path2.name
|
60 |
|
61 |
|
62 |
+
def start_loading(container_id):
|
63 |
+
return f"""
|
64 |
+
<div class="loader" id="loader-{container_id}"></div>
|
65 |
+
<script>
|
66 |
+
document.getElementById('loader-{container_id}').style.display = 'block';
|
67 |
+
</script>
|
68 |
+
"""
|
69 |
|
70 |
+
def stop_loading(container_id):
|
71 |
+
return f"""
|
72 |
+
<script>
|
73 |
+
document.getElementById('loader-{container_id}').style.display = 'none';
|
74 |
+
</script>
|
75 |
|
76 |
|
77 |
# Настройка темы и CSS
|
|
|
90 |
|
91 |
|
92 |
css = """
|
93 |
+
ooter {
|
|
|
94 |
visibility: hidden;
|
95 |
height: 0;
|
96 |
margin: 0;
|
|
|
122 |
|
123 |
/* Слайдер */
|
124 |
.gr-slider {
|
125 |
+
height: 40px !important;
|
126 |
+
transition: all 0.3s ease !important;
|
127 |
}
|
128 |
|
129 |
.gr-slider .slider-value {
|
130 |
+
display: none !important;
|
131 |
}
|
132 |
|
133 |
.gr-slider .slider::-webkit-slider-thumb {
|
134 |
height: 15px !important;
|
135 |
width: 15px !important;
|
136 |
+
background-color: #5271FF !important;
|
137 |
border-radius: 50%;
|
138 |
}
|
139 |
|
140 |
.gr-slider .slider::-webkit-slider-runnable-track {
|
141 |
+
background: #5271FF !important;
|
142 |
}
|
143 |
|
144 |
/* Кнопка Generate */
|
|
|
150 |
}
|
151 |
|
152 |
.generate-button:hover {
|
153 |
+
background-color: #405BBF !important;
|
154 |
}
|
155 |
|
156 |
/* Выделяем текст для Prompt */
|
|
|
159 |
color: #FFFFFF;
|
160 |
}
|
161 |
|
162 |
+
/* Контейнеры для правильного позиционирования лоадера */
|
163 |
+
.upload-container,
|
164 |
+
.processed-container,
|
165 |
+
.gr-model3d-container {
|
166 |
+
position: relative !important;
|
167 |
+
}
|
168 |
+
|
169 |
+
/* Обновленный стиль лоадера */
|
170 |
#loading-bar {
|
171 |
+
display: none;
|
172 |
position: absolute;
|
173 |
top: 50%;
|
174 |
left: 50%;
|
|
|
176 |
width: 60px;
|
177 |
height: 60px;
|
178 |
border: 8px solid #f3f3f3;
|
179 |
+
border-top: 8px solid #5271FF;
|
180 |
border-radius: 50%;
|
181 |
animation: spin 1s linear infinite;
|
182 |
+
z-index: 1000;
|
183 |
}
|
184 |
|
185 |
/* Анимация вращения */
|
|
|
192 |
.gr-checkbox label {
|
193 |
color: #FFFFFF !important;
|
194 |
}
|
195 |
+
|
196 |
+
/* Убедимся, что контейнеры изображений правильно позиционированы */
|
197 |
+
.image-container {
|
198 |
+
position: relative !important;
|
199 |
+
width: 100%;
|
200 |
+
height: 100%;
|
201 |
+
}
|
202 |
+
|
203 |
+
/* Стили для контейнера с 3D моделью */
|
204 |
+
.gr-model3d-container {
|
205 |
+
position: relative !important;
|
206 |
+
min-height: 400px;
|
207 |
+
}
|
208 |
"""
|
209 |
|
210 |
# Интерфейс
|
|
|
212 |
with gr.Column():
|
213 |
gr.Markdown("<span style='color: white; font-weight: bold;'>Upload and Process Your Image</span>")
|
214 |
with gr.Row():
|
215 |
+
with gr.Column(elem_classes="upload-container"):
|
216 |
+
input_image = gr.Image(
|
217 |
+
label="Upload Image",
|
218 |
+
image_mode="RGBA",
|
219 |
+
sources="upload",
|
220 |
+
type="pil",
|
221 |
+
width=400,
|
222 |
+
height=300,
|
223 |
+
)
|
224 |
+
upload_loader = gr.HTML(visible=False)
|
225 |
+
|
226 |
+
with gr.Column(elem_classes="processed-container"):
|
227 |
+
processed_image = gr.Image(
|
228 |
+
label="Processed Image",
|
229 |
+
interactive=False,
|
230 |
+
width=400,
|
231 |
+
height=300,
|
232 |
+
)
|
233 |
+
process_loader = gr.HTML(visible=False)
|
234 |
+
|
235 |
foreground_ratio = gr.Slider(
|
236 |
label="Foreground Ratio",
|
237 |
minimum=0.5,
|
|
|
240 |
step=0.05,
|
241 |
)
|
242 |
do_remove_background = gr.Checkbox(
|
243 |
+
label="Remove Background",
|
244 |
value=True,
|
245 |
)
|
246 |
submit = gr.Button("Generate", elem_classes="generate-button")
|
247 |
+
|
248 |
+
with gr.Column(elem_classes="model3d-container"):
|
249 |
+
output_model = gr.Model3D(
|
250 |
+
label="Generated GLB Model",
|
251 |
+
interactive=False,
|
252 |
+
)
|
253 |
+
model_loader = gr.HTML(visible=False)
|
254 |
|
255 |
+
# Обновляем цепочку событий
|
256 |
submit.click(
|
257 |
+
fn=lambda: """<div id='loading-bar' style='display: block;'></div>""",
|
258 |
+
outputs=[upload_loader],
|
259 |
+
show_progress=False,
|
260 |
).then(
|
261 |
fn=check_input_image,
|
262 |
inputs=[input_image],
|
263 |
+
outputs=[],
|
264 |
+
).then(
|
265 |
+
fn=lambda: """<div id='loading-bar' style='display: block;'></div>""",
|
266 |
+
outputs=[process_loader],
|
267 |
+
show_progress=False,
|
268 |
).then(
|
269 |
fn=preprocess,
|
270 |
inputs=[input_image, do_remove_background, foreground_ratio],
|
271 |
+
outputs=[processed_image],
|
272 |
+
).then(
|
273 |
+
fn=lambda: """<div id='loading-bar' style='display: none;'></div>""",
|
274 |
+
outputs=[upload_loader],
|
275 |
+
show_progress=False,
|
276 |
+
).then(
|
277 |
+
fn=lambda: """<div id='loading-bar' style='display: block;'></div>""",
|
278 |
+
outputs=[model_loader],
|
279 |
+
show_progress=False,
|
280 |
).then(
|
281 |
fn=generate,
|
282 |
inputs=[processed_image],
|
283 |
+
outputs=[output_model],
|
284 |
+
).then(
|
285 |
+
fn=lambda: """<div id='loading-bar' style='display: none;'></div>""",
|
286 |
+
outputs=[process_loader],
|
287 |
+
show_progress=False,
|
288 |
).then(
|
289 |
+
fn=lambda: """<div id='loading-bar' style='display: none;'></div>""",
|
290 |
+
outputs=[model_loader],
|
291 |
+
show_progress=False,
|
292 |
)
|
|
|
293 |
# Запуск приложения
|
294 |
demo.launch(
|
295 |
server_name="0.0.0.0",
|
296 |
server_port=7860,
|
297 |
share=True,
|
298 |
+
)
|