Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -19,20 +19,17 @@ model = TSR.from_pretrained(
|
|
19 |
model.renderer.set_chunk_size(131072)
|
20 |
model.to(device)
|
21 |
|
22 |
-
|
23 |
# Функция для проверки изображения
|
24 |
def check_input_image(input_image):
|
25 |
if input_image is None:
|
26 |
raise gr.Error("No image uploaded!")
|
27 |
|
28 |
-
|
29 |
# Функция обработки изображения
|
30 |
def preprocess(input_image, do_remove_background, foreground_ratio):
|
31 |
def fill_background(image):
|
32 |
image = np.array(image).astype(np.float32) / 255.0
|
33 |
image = image[:, :, :3] * image[:, :, 3:4] + (1 - image[:, :, 3:4]) * 0.5
|
34 |
-
|
35 |
-
return image
|
36 |
|
37 |
if do_remove_background:
|
38 |
image = input_image.convert("RGB")
|
@@ -45,7 +42,6 @@ def preprocess(input_image, do_remove_background, foreground_ratio):
|
|
45 |
image = fill_background(image)
|
46 |
return image
|
47 |
|
48 |
-
|
49 |
# Функция генерации 3D модели
|
50 |
def generate(image):
|
51 |
time.sleep(3) # Эмуляция времени обработки
|
@@ -56,7 +52,6 @@ def generate(image):
|
|
56 |
mesh.export(mesh_path2.name)
|
57 |
return mesh_path2.name
|
58 |
|
59 |
-
|
60 |
# Функции для управления лоадерами
|
61 |
def start_loading_processed():
|
62 |
return "<div id='loading-bar-processed' style='display: block;'></div>"
|
@@ -70,7 +65,6 @@ def start_loading_glb():
|
|
70 |
def stop_loading_glb():
|
71 |
return "<div id='loading-bar-glb' style='display: none;'></div>"
|
72 |
|
73 |
-
|
74 |
# Настройка темы и CSS
|
75 |
class CustomTheme(gr.themes.Base):
|
76 |
def __init__(self):
|
@@ -85,7 +79,6 @@ class CustomTheme(gr.themes.Base):
|
|
85 |
self.input_background_fill = "#191a1e"
|
86 |
self.input_text_color = "#FFFFFF"
|
87 |
|
88 |
-
|
89 |
css = """
|
90 |
/* Скрываем системный лоадер Gradio */
|
91 |
footer {
|
@@ -97,9 +90,9 @@ footer {
|
|
97 |
}
|
98 |
|
99 |
/* Общий стиль */
|
100 |
-
body, input, button, textarea, select
|
101 |
font-family: 'Poppins', sans-serif;
|
102 |
-
background-color: #191a1e
|
103 |
color: #FFFFFF;
|
104 |
}
|
105 |
|
@@ -107,9 +100,6 @@ body, input, button, textarea, select, .gr-button {
|
|
107 |
#loading-bar-processed, #loading-bar-glb {
|
108 |
display: none;
|
109 |
position: absolute;
|
110 |
-
top: 50%;
|
111 |
-
left: 50%;
|
112 |
-
transform: translate(-50%, -50%);
|
113 |
width: 60px;
|
114 |
height: 60px;
|
115 |
border: 8px solid #f3f3f3;
|
@@ -118,6 +108,13 @@ body, input, button, textarea, select, .gr-button {
|
|
118 |
animation: spin 1s linear infinite;
|
119 |
}
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
@keyframes spin {
|
122 |
0% { transform: translate(-50%, -50%) rotate(0deg); }
|
123 |
100% { transform: translate(-50%, -50%) rotate(360deg); }
|
@@ -125,7 +122,7 @@ body, input, button, textarea, select, .gr-button {
|
|
125 |
|
126 |
/* Текст CheckBox в белый */
|
127 |
.gr-checkbox label {
|
128 |
-
color: #FFFFFF
|
129 |
}
|
130 |
"""
|
131 |
|
@@ -159,7 +156,7 @@ with gr.Blocks(theme=CustomTheme(), css=css) as demo:
|
|
159 |
step=0.05,
|
160 |
)
|
161 |
do_remove_background = gr.Checkbox(
|
162 |
-
label="Remove Background",
|
163 |
value=True,
|
164 |
)
|
165 |
|
@@ -208,4 +205,4 @@ demo.launch(
|
|
208 |
server_name="0.0.0.0",
|
209 |
server_port=7860,
|
210 |
share=True,
|
211 |
-
)
|
|
|
19 |
model.renderer.set_chunk_size(131072)
|
20 |
model.to(device)
|
21 |
|
|
|
22 |
# Функция для проверки изображения
|
23 |
def check_input_image(input_image):
|
24 |
if input_image is None:
|
25 |
raise gr.Error("No image uploaded!")
|
26 |
|
|
|
27 |
# Функция обработки изображения
|
28 |
def preprocess(input_image, do_remove_background, foreground_ratio):
|
29 |
def fill_background(image):
|
30 |
image = np.array(image).astype(np.float32) / 255.0
|
31 |
image = image[:, :, :3] * image[:, :, 3:4] + (1 - image[:, :, 3:4]) * 0.5
|
32 |
+
return Image.fromarray((image * 255.0).astype(np.uint8))
|
|
|
33 |
|
34 |
if do_remove_background:
|
35 |
image = input_image.convert("RGB")
|
|
|
42 |
image = fill_background(image)
|
43 |
return image
|
44 |
|
|
|
45 |
# Функция генерации 3D модели
|
46 |
def generate(image):
|
47 |
time.sleep(3) # Эмуляция времени обработки
|
|
|
52 |
mesh.export(mesh_path2.name)
|
53 |
return mesh_path2.name
|
54 |
|
|
|
55 |
# Функции для управления лоадерами
|
56 |
def start_loading_processed():
|
57 |
return "<div id='loading-bar-processed' style='display: block;'></div>"
|
|
|
65 |
def stop_loading_glb():
|
66 |
return "<div id='loading-bar-glb' style='display: none;'></div>"
|
67 |
|
|
|
68 |
# Настройка темы и CSS
|
69 |
class CustomTheme(gr.themes.Base):
|
70 |
def __init__(self):
|
|
|
79 |
self.input_background_fill = "#191a1e"
|
80 |
self.input_text_color = "#FFFFFF"
|
81 |
|
|
|
82 |
css = """
|
83 |
/* Скрываем системный лоадер Gradio */
|
84 |
footer {
|
|
|
90 |
}
|
91 |
|
92 |
/* Общий стиль */
|
93 |
+
body, input, button, textarea, select,.gr-button {
|
94 |
font-family: 'Poppins', sans-serif;
|
95 |
+
background-color: #191a1e!important;
|
96 |
color: #FFFFFF;
|
97 |
}
|
98 |
|
|
|
100 |
#loading-bar-processed, #loading-bar-glb {
|
101 |
display: none;
|
102 |
position: absolute;
|
|
|
|
|
|
|
103 |
width: 60px;
|
104 |
height: 60px;
|
105 |
border: 8px solid #f3f3f3;
|
|
|
108 |
animation: spin 1s linear infinite;
|
109 |
}
|
110 |
|
111 |
+
#processed-container #loading-bar-processed,
|
112 |
+
.gr-model3d-container #loading-bar-glb {
|
113 |
+
top: 50%;
|
114 |
+
left: 50%;
|
115 |
+
transform: translate(-50%, -50%);
|
116 |
+
}
|
117 |
+
|
118 |
@keyframes spin {
|
119 |
0% { transform: translate(-50%, -50%) rotate(0deg); }
|
120 |
100% { transform: translate(-50%, -50%) rotate(360deg); }
|
|
|
122 |
|
123 |
/* Текст CheckBox в белый */
|
124 |
.gr-checkbox label {
|
125 |
+
color: #FFFFFF!important;
|
126 |
}
|
127 |
"""
|
128 |
|
|
|
156 |
step=0.05,
|
157 |
)
|
158 |
do_remove_background = gr.Checkbox(
|
159 |
+
label="Remove Background",
|
160 |
value=True,
|
161 |
)
|
162 |
|
|
|
205 |
server_name="0.0.0.0",
|
206 |
server_port=7860,
|
207 |
share=True,
|
208 |
+
)
|