Zaiiida commited on
Commit
2623970
·
verified ·
1 Parent(s): e173da1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -29
app.py CHANGED
@@ -28,7 +28,6 @@ intrinsic, intrinsic_normed_cond = sf3d_utils.create_intrinsic_from_fov_deg(
28
  COND_FOVY_DEG, COND_HEIGHT, COND_WIDTH
29
  )
30
 
31
-
32
  model = SF3D.from_pretrained(
33
  "stabilityai/stable-fast-3d",
34
  config_name="config.yaml",
@@ -117,9 +116,9 @@ def resize_foreground(
117
  alpha[1].min(),
118
  alpha[1].max(),
119
  )
120
- # crop the foreground
121
  fg = image[y1:y2, x1:x2]
122
- # pad to square
123
  size = max(fg.shape[0], fg.shape[1])
124
  ph0, pw0 = (size - fg.shape[0]) // 2, (size - fg.shape[1]) // 2
125
  ph1, pw1 = size - fg.shape[0] - ph0, size - fg.shape[1] - pw0
@@ -130,9 +129,9 @@ def resize_foreground(
130
  constant_values=((0, 0), (0, 0), (0, 0)),
131
  )
132
 
133
- # compute padding according to the ratio
134
  new_size = int(new_image.shape[0] / ratio)
135
- # pad to size, double side
136
  ph0, pw0 = (new_size - size) // 2, (new_size - size) // 2
137
  ph1, pw1 = new_size - size - ph0, new_size - size - pw0
138
  new_image = np.pad(
@@ -236,54 +235,56 @@ def update_foreground_ratio(img_proc, fr):
236
  foreground_res,
237
  gr.update(value=show_mask_img(foreground_res)),
238
  )
 
 
239
  class CustomTheme(gr.themes.Base):
240
- def __init__(self):
241
- super().__init__()
242
- self.primary_hue = "#191a1e"
243
- self.background_fill_primary = "#191a1e"
244
- self.background_fill_secondary = "#191a1e"
245
- self.background_fill_tertiary = "#191a1e"
246
- self.text_color_primary = "#FFFFFF"
247
- self.text_color_secondary = "#FFFFFF"
248
- self.text_color_tertiary = "#FFFFFF"
249
- self.input_background_fill = "#191a1e"
250
- self.input_text_color = "#FFFFFF"
251
  css = """
252
- /* Задаем фоновый цвет всей страницы */
253
  body {
254
- background-color: #191a1e !important; /* Тёмный фон */
255
  margin: 0;
256
  padding: 0;
257
  }
258
 
259
- /* Применяем шрифты */
260
  @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&display=swap');
261
  body, input, button, textarea, select, .gr-button {
262
  font-family: 'Poppins', sans-serif;
263
  color: #FFFFFF;
264
  }
265
 
266
- /* Настройки заголовков */
267
  h1, h2, h3, h4, h5, h6 {
268
  font-family: 'Poppins', sans-serif;
269
  font-weight: 700;
270
  color: #FFFFFF;
271
  }
272
 
273
- /* Цвет кнопок */
274
- .generate-button {
275
- background-color: #5271FF !important; /* Голубой */
276
  color: #FFFFFF !important;
277
  border: none;
278
  font-weight: bold;
279
  }
280
 
281
- /* Цвет контейнеров */
282
  .gr-block {
283
- background-color: #1c1c24 !important; /* Голубоватый тёмный фон */
284
- border: 1px solid #5271FF !important; /* Голубая рамка */
285
  }
286
  """
 
287
  with gr.Blocks(theme=CustomTheme(), css=css) as demo:
288
  img_proc_state = gr.State()
289
  background_remove_state = gr.State()
@@ -292,7 +293,7 @@ with gr.Blocks(theme=CustomTheme(), css=css) as demo:
292
  with gr.Column():
293
  with gr.Row():
294
  input_img = gr.Image(
295
- type="pil", label="Input Image", sources="upload", image_mode="RGBA"
296
  )
297
  preview_removal = gr.Image(
298
  label="Preview Background Removal",
@@ -330,8 +331,8 @@ with gr.Blocks(theme=CustomTheme(), css=css) as demo:
330
  with gr.Column(visible=False, scale=1.0) as hdr_row:
331
  gr.Markdown("""## HDR Environment Map
332
 
333
- Select an HDR environment map to light the 3D model. You can also upload your own HDR environment maps.
334
- """)
335
 
336
  with gr.Row():
337
  hdr_illumination_file = gr.File(
 
28
  COND_FOVY_DEG, COND_HEIGHT, COND_WIDTH
29
  )
30
 
 
31
  model = SF3D.from_pretrained(
32
  "stabilityai/stable-fast-3d",
33
  config_name="config.yaml",
 
116
  alpha[1].min(),
117
  alpha[1].max(),
118
  )
119
+ # Crop the foreground
120
  fg = image[y1:y2, x1:x2]
121
+ # Pad to square
122
  size = max(fg.shape[0], fg.shape[1])
123
  ph0, pw0 = (size - fg.shape[0]) // 2, (size - fg.shape[1]) // 2
124
  ph1, pw1 = size - fg.shape[0] - ph0, size - fg.shape[1] - pw0
 
129
  constant_values=((0, 0), (0, 0), (0, 0)),
130
  )
131
 
132
+ # Compute padding according to the ratio
133
  new_size = int(new_image.shape[0] / ratio)
134
+ # Pad to size, double side
135
  ph0, pw0 = (new_size - size) // 2, (new_size - size) // 2
136
  ph1, pw1 = new_size - size - ph0, new_size - size - pw0
137
  new_image = np.pad(
 
235
  foreground_res,
236
  gr.update(value=show_mask_img(foreground_res)),
237
  )
238
+
239
+ # Corrected CustomTheme class
240
  class CustomTheme(gr.themes.Base):
241
+ primary_hue = gr.themes.Color("#191a1e")
242
+ background_fill_primary = gr.themes.Color("#191a1e")
243
+ background_fill_secondary = gr.themes.Color("#191a1e")
244
+ background_fill_tertiary = gr.themes.Color("#191a1e")
245
+ text_color_primary = gr.themes.Color("#FFFFFF")
246
+ text_color_secondary = gr.themes.Color("#FFFFFF")
247
+ text_color_tertiary = gr.themes.Color("#FFFFFF")
248
+ input_background_fill = gr.themes.Color("#191a1e")
249
+ input_text_color = gr.themes.Color("#FFFFFF")
250
+
 
251
  css = """
252
+ /* Apply background color to the entire page */
253
  body {
254
+ background-color: #191a1e !important;
255
  margin: 0;
256
  padding: 0;
257
  }
258
 
259
+ /* Apply fonts */
260
  @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&display=swap');
261
  body, input, button, textarea, select, .gr-button {
262
  font-family: 'Poppins', sans-serif;
263
  color: #FFFFFF;
264
  }
265
 
266
+ /* Header settings */
267
  h1, h2, h3, h4, h5, h6 {
268
  font-family: 'Poppins', sans-serif;
269
  font-weight: 700;
270
  color: #FFFFFF;
271
  }
272
 
273
+ /* Button colors */
274
+ .gr-button {
275
+ background-color: #5271FF !important;
276
  color: #FFFFFF !important;
277
  border: none;
278
  font-weight: bold;
279
  }
280
 
281
+ /* Container colors */
282
  .gr-block {
283
+ background-color: #1c1c24 !important;
284
+ border: 1px solid #5271FF !important;
285
  }
286
  """
287
+
288
  with gr.Blocks(theme=CustomTheme(), css=css) as demo:
289
  img_proc_state = gr.State()
290
  background_remove_state = gr.State()
 
293
  with gr.Column():
294
  with gr.Row():
295
  input_img = gr.Image(
296
+ type="pil", label="Input Image", source="upload", image_mode="RGBA"
297
  )
298
  preview_removal = gr.Image(
299
  label="Preview Background Removal",
 
331
  with gr.Column(visible=False, scale=1.0) as hdr_row:
332
  gr.Markdown("""## HDR Environment Map
333
 
334
+ Select an HDR environment map to light the 3D model. You can also upload your own HDR environment maps.
335
+ """)
336
 
337
  with gr.Row():
338
  hdr_illumination_file = gr.File(