Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import time # Для эмуляции времени загрузки
|
3 |
import tempfile
|
4 |
-
import os
|
5 |
import numpy as np
|
6 |
import torch
|
7 |
from PIL import Image
|
@@ -58,17 +57,14 @@ def generate(image):
|
|
58 |
return mesh_path2.name
|
59 |
|
60 |
|
61 |
-
|
62 |
-
|
|
|
63 |
|
64 |
-
def stop_loading_processed():
|
65 |
-
return "<div id='loading-bar-processed' style='display: none;'></div>"
|
66 |
|
67 |
-
def
|
68 |
-
return "<div id='loading-bar
|
69 |
|
70 |
-
def stop_loading_glb():
|
71 |
-
return "<div id='loading-bar-glb' style='display: none;'></div>"
|
72 |
|
73 |
# Настройка темы и CSS
|
74 |
class CustomTheme(gr.themes.Base):
|
@@ -86,7 +82,7 @@ class CustomTheme(gr.themes.Base):
|
|
86 |
|
87 |
|
88 |
css = """
|
89 |
-
/* Скрываем нижний колонтитул
|
90 |
footer {
|
91 |
visibility: hidden;
|
92 |
height: 0;
|
@@ -95,78 +91,99 @@ footer {
|
|
95 |
overflow: hidden;
|
96 |
}
|
97 |
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
|
|
100 |
}
|
101 |
|
102 |
-
/*
|
103 |
-
|
104 |
font-family: 'Poppins', sans-serif;
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
background-color: #191a1e !important;
|
106 |
color: #FFFFFF;
|
|
|
107 |
}
|
108 |
|
109 |
-
/*
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
top: 50%;
|
114 |
-
left: 50%;
|
115 |
-
transform: translate(-50%, -50%);
|
116 |
-
width: 60px;
|
117 |
-
height: 60px;
|
118 |
-
border: 8px solid #f3f3f3; /* Светло-серый фон */
|
119 |
-
border-top: 8px solid #5271FF; /* Активная часть голубого цвета */
|
120 |
-
border-radius: 50%;
|
121 |
-
animation: spin 1s linear infinite; /* Анимация вращения */
|
122 |
}
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
100% { transform: translate(-50%, -50%) rotate(360deg); }
|
127 |
}
|
128 |
|
129 |
-
|
130 |
-
|
131 |
-
width:
|
132 |
-
|
133 |
-
|
134 |
-
border: none !important; /* Убираем границы */
|
135 |
}
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
background-color: transparent !important; /* Прозрачный фон */
|
140 |
-
border: none !important; /* Убираем границы */
|
141 |
-
box-shadow: none !important; /* Убираем тени */
|
142 |
}
|
143 |
|
144 |
-
/*
|
145 |
.generate-button {
|
146 |
-
background-color: #5271FF !important;
|
147 |
-
color: #FFFFFF !important;
|
148 |
border: none;
|
149 |
-
border-radius: 5px;
|
150 |
font-weight: bold;
|
151 |
-
padding: 10px 20px;
|
152 |
-
cursor: pointer;
|
153 |
-
transition: background-color 0.3s ease;
|
154 |
}
|
155 |
|
156 |
.generate-button:hover {
|
157 |
-
background-color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
}
|
159 |
|
|
|
|
|
|
|
|
|
160 |
"""
|
|
|
161 |
# Интерфейс
|
162 |
-
with gr.Blocks(css=css) as demo:
|
163 |
with gr.Column():
|
164 |
-
# Заголовок
|
165 |
gr.Markdown("<span style='color: white; font-weight: bold;'>Upload and Process Your Image</span>")
|
166 |
-
|
167 |
-
# Контейнер для загрузки изображения и обработанного изображения
|
168 |
with gr.Row():
|
169 |
-
# Загрузка изображения
|
170 |
input_image = gr.Image(
|
171 |
label="Upload Image",
|
172 |
image_mode="RGBA",
|
@@ -175,18 +192,12 @@ with gr.Blocks(css=css) as demo:
|
|
175 |
width=400,
|
176 |
height=300,
|
177 |
)
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
width=400,
|
185 |
-
height=300,
|
186 |
-
)
|
187 |
-
processed_loader = gr.HTML("<div id='loading-bar-processed'></div>")
|
188 |
-
|
189 |
-
# Слайдер и чекбокс
|
190 |
foreground_ratio = gr.Slider(
|
191 |
label="Foreground Ratio",
|
192 |
minimum=0.5,
|
@@ -195,26 +206,21 @@ with gr.Blocks(css=css) as demo:
|
|
195 |
step=0.05,
|
196 |
)
|
197 |
do_remove_background = gr.Checkbox(
|
198 |
-
label="Remove Background",
|
199 |
value=True,
|
200 |
)
|
201 |
-
|
202 |
-
# Кнопка генерации
|
203 |
submit = gr.Button("Generate", elem_classes="generate-button")
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
|
205 |
-
# Контейнер для модели GLB и лоадера
|
206 |
-
with gr.Column(elem_id="glb-container"):
|
207 |
-
output_model = gr.Model3D(
|
208 |
-
label="Generated GLB Model",
|
209 |
-
interactive=False,
|
210 |
-
)
|
211 |
-
glb_loader = gr.HTML("<div id='loading-bar-glb'></div>")
|
212 |
-
|
213 |
-
# Логика кнопки и цепочки событий
|
214 |
submit.click(
|
215 |
-
fn=
|
216 |
inputs=[],
|
217 |
-
outputs=[
|
218 |
).then(
|
219 |
fn=check_input_image,
|
220 |
inputs=[input_image],
|
@@ -223,28 +229,19 @@ with gr.Blocks(css=css) as demo:
|
|
223 |
fn=preprocess,
|
224 |
inputs=[input_image, do_remove_background, foreground_ratio],
|
225 |
outputs=[processed_image]
|
226 |
-
).then(
|
227 |
-
fn=stop_loading_processed,
|
228 |
-
inputs=[],
|
229 |
-
outputs=[processed_loader],
|
230 |
-
).then(
|
231 |
-
fn=start_loading_glb,
|
232 |
-
inputs=[],
|
233 |
-
outputs=[glb_loader],
|
234 |
).then(
|
235 |
fn=generate,
|
236 |
inputs=[processed_image],
|
237 |
outputs=[output_model]
|
238 |
).then(
|
239 |
-
fn=
|
240 |
inputs=[],
|
241 |
-
outputs=[
|
242 |
)
|
243 |
|
244 |
-
|
245 |
# Запуск приложения
|
246 |
demo.launch(
|
247 |
server_name="0.0.0.0",
|
248 |
server_port=7860,
|
249 |
share=True,
|
250 |
-
)
|
|
|
1 |
import gradio as gr
|
2 |
import time # Для эмуляции времени загрузки
|
3 |
import tempfile
|
|
|
4 |
import numpy as np
|
5 |
import torch
|
6 |
from PIL import Image
|
|
|
57 |
return mesh_path2.name
|
58 |
|
59 |
|
60 |
+
# Функция для отображения загрузки
|
61 |
+
def start_loading():
|
62 |
+
return "<div id='loading-bar' style='display: block;'></div>"
|
63 |
|
|
|
|
|
64 |
|
65 |
+
def stop_loading():
|
66 |
+
return "<div id='loading-bar' style='display: none;'></div>"
|
67 |
|
|
|
|
|
68 |
|
69 |
# Настройка темы и CSS
|
70 |
class CustomTheme(gr.themes.Base):
|
|
|
82 |
|
83 |
|
84 |
css = """
|
85 |
+
/* Скрываем нижний колонтитул */
|
86 |
footer {
|
87 |
visibility: hidden;
|
88 |
height: 0;
|
|
|
91 |
overflow: hidden;
|
92 |
}
|
93 |
|
94 |
+
/* Применяем шрифты */
|
95 |
+
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&display=swap');
|
96 |
+
body, input, button, textarea, select, .gr-button {
|
97 |
+
font-family: 'Poppins', sans-serif;
|
98 |
+
background-color: #191a1e !important;
|
99 |
+
color: #FFFFFF;
|
100 |
}
|
101 |
|
102 |
+
/* Настройки заголовков */
|
103 |
+
h1, h2, h3, h4, h5, h6 {
|
104 |
font-family: 'Poppins', sans-serif;
|
105 |
+
font-weight: 700;
|
106 |
+
color: #FFFFFF;
|
107 |
+
}
|
108 |
+
|
109 |
+
/* Стиль для текстовых полей и кнопок */
|
110 |
+
input[type="text"], textarea {
|
111 |
background-color: #191a1e !important;
|
112 |
color: #FFFFFF;
|
113 |
+
border: 1px solid #FFFFFF;
|
114 |
}
|
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 */
|
138 |
.generate-button {
|
139 |
+
background-color: #5271FF !important;
|
140 |
+
color: #FFFFFF !important;
|
141 |
border: none;
|
|
|
142 |
font-weight: bold;
|
|
|
|
|
|
|
143 |
}
|
144 |
|
145 |
.generate-button:hover {
|
146 |
+
background-color: #405BBF !important; /* Цвет при наведении */
|
147 |
+
}
|
148 |
+
|
149 |
+
/* Выделяем текст для Prompt */
|
150 |
+
.prompt-text {
|
151 |
+
font-weight: bold;
|
152 |
+
color: #FFFFFF;
|
153 |
+
}
|
154 |
+
|
155 |
+
/* Лоадер (анимация) */
|
156 |
+
#loading-bar {
|
157 |
+
display: none; /* Скрыт по умолчан��ю */
|
158 |
+
position: absolute;
|
159 |
+
top: 50%;
|
160 |
+
left: 50%;
|
161 |
+
transform: translate(-50%, -50%);
|
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 |
+
/* Анимация вращения */
|
171 |
+
@keyframes spin {
|
172 |
+
0% { transform: translate(-50%, -50%) rotate(0deg); }
|
173 |
+
100% { transform: translate(-50%, -50%) rotate(360deg); }
|
174 |
}
|
175 |
|
176 |
+
/* Текст CheckBox в белый */
|
177 |
+
.gr-checkbox label {
|
178 |
+
color: #FFFFFF !important;
|
179 |
+
}
|
180 |
"""
|
181 |
+
|
182 |
# Интерфейс
|
183 |
+
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 |
input_image = gr.Image(
|
188 |
label="Upload Image",
|
189 |
image_mode="RGBA",
|
|
|
192 |
width=400,
|
193 |
height=300,
|
194 |
)
|
195 |
+
processed_image = gr.Image(
|
196 |
+
label="Processed Image",
|
197 |
+
interactive=False,
|
198 |
+
width=400,
|
199 |
+
height=300,
|
200 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
foreground_ratio = gr.Slider(
|
202 |
label="Foreground Ratio",
|
203 |
minimum=0.5,
|
|
|
206 |
step=0.05,
|
207 |
)
|
208 |
do_remove_background = gr.Checkbox(
|
209 |
+
label="Remove Background", # Текст перекрашен в белый через CSS
|
210 |
value=True,
|
211 |
)
|
|
|
|
|
212 |
submit = gr.Button("Generate", elem_classes="generate-button")
|
213 |
+
loading_bar = gr.HTML("<div id='loading-bar'></div>")
|
214 |
+
output_model = gr.Model3D(
|
215 |
+
label="Generated GLB Model",
|
216 |
+
interactive=False,
|
217 |
+
elem_classes="gr-model3d-container",
|
218 |
+
)
|
219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
submit.click(
|
221 |
+
fn=start_loading, # Включить прогресс-бар
|
222 |
inputs=[],
|
223 |
+
outputs=[loading_bar],
|
224 |
).then(
|
225 |
fn=check_input_image,
|
226 |
inputs=[input_image],
|
|
|
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=stop_loading, # Отключаем прогресс-бар после завершения генерации
|
238 |
inputs=[],
|
239 |
+
outputs=[loading_bar],
|
240 |
)
|
241 |
|
|
|
242 |
# Запуск приложения
|
243 |
demo.launch(
|
244 |
server_name="0.0.0.0",
|
245 |
server_port=7860,
|
246 |
share=True,
|
247 |
+
)
|