Zaiiida commited on
Commit
0bb48ab
·
verified ·
1 Parent(s): 6856aac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -22
app.py CHANGED
@@ -12,13 +12,14 @@ device = "cuda:0" if torch.cuda.is_available() else "cpu"
12
 
13
  # Загружаем модель
14
  model = TSR.from_pretrained(
15
- "stabilityai/TripoSR",
16
- config_name="config.yaml",
17
- weight_name="model.ckpt",
18
  )
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:
@@ -29,17 +30,18 @@ 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")
36
- image = remove_background(image)
37
  image = resize_foreground(image, foreground_ratio)
38
- image = fill_background(image)
39
  else:
40
  image = input_image
41
  if image.mode == "RGBA":
42
- image = fill_background(image)
43
  return image
44
 
45
  # Функция генерации 3D модели
@@ -48,7 +50,7 @@ def generate(image):
48
  scene_codes = model(image, device=device)
49
  mesh = model.extract_mesh(scene_codes)[0]
50
  mesh = to_gradio_3d_orientation(mesh)
51
- mesh_path2 = tempfile.NamedTemporaryFile(suffix=".glb", delete=False)
52
  mesh.export(mesh_path2.name)
53
  return mesh_path2.name
54
 
@@ -74,10 +76,10 @@ class CustomTheme(gr.themes.Base):
74
  self.background_fill_secondary = "#191a1e"
75
  self.background_fill_tertiary = "#191a1e"
76
  self.text_color_primary = "#FFFFFF"
77
- self.text_color_secondary = "#FFFFFF"
78
- self.text_color_tertiary = "#FFFFFF"
79
  self.input_background_fill = "#191a1e"
80
- self.input_text_color = "#FFFFFF"
81
 
82
  css = """
83
  /* Скрываем системный лоадер Gradio */
@@ -90,9 +92,9 @@ 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,6 +102,9 @@ body, input, button, textarea, select,.gr-button {
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,13 +113,6 @@ body, input, button, textarea, select,.gr-button {
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,7 +120,7 @@ body, input, button, textarea, select,.gr-button {
122
 
123
  /* Текст CheckBox в белый */
124
  .gr-checkbox label {
125
- color: #FFFFFF!important;
126
  }
127
  """
128
 
@@ -156,7 +154,7 @@ with gr.Blocks(theme=CustomTheme(), css=css) as demo:
156
  step=0.05,
157
  )
158
  do_remove_background = gr.Checkbox(
159
- label="Remove Background",
160
  value=True,
161
  )
162
 
 
12
 
13
  # Загружаем модель
14
  model = TSR.from_pretrained(
15
+ "stabi/TripoSR",
16
+ config_name=" config.yaml",
17
+ weight_name=" model.ckpt",
18
  )
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:
 
30
  def fill_background(image):
31
  image = np.array(image).astype(np.float32) / 255.0
32
  image = image[:, :, :3] * image[:, :, 3:4] + (1 - image[:, :, 3:4]) * 0.5
33
+ image = Image.fromarray((image * 255.0).astype(np.uint8))
34
+ return image
35
 
36
  if do_remove_background:
37
  image = input_image.convert("RGB")
38
+ image = removebackground(image)
39
  image = resize_foreground(image, foreground_ratio)
40
+ image = fillbackground(image)
41
  else:
42
  image = input_image
43
  if image.mode == "RGBA":
44
+ image = fillbackground(image)
45
  return image
46
 
47
  # Функция генерации 3D модели
 
50
  scene_codes = model(image, device=device)
51
  mesh = model.extract_mesh(scene_codes)[0]
52
  mesh = to_gradio_3d_orientation(mesh)
53
+ mesh_path2 = tempfile.Namedtemporaryfile(delete=False)
54
  mesh.export(mesh_path2.name)
55
  return mesh_path2.name
56
 
 
76
  self.background_fill_secondary = "#191a1e"
77
  self.background_fill_tertiary = "#191a1e"
78
  self.text_color_primary = "#FFFFFF"
79
+ self.textcolor_secondary = "#FFFFFF"
80
+ self.textcolor_tertiary = "#FFFFFF"
81
  self.input_background_fill = "#191a1e"
82
+ self.inputtext_color = "#FFFFFF"
83
 
84
  css = """
85
  /* Скрываем системный лоадер Gradio */
 
92
  }
93
 
94
  /* Общий стиль */
95
+ body, input, button, textarea, select, .gr-button {
96
  font-family: 'Poppins', sans-serif;
97
+ background-color: #191a1e !important;
98
  color: #FFFFFF;
99
  }
100
 
 
102
  #loading-bar-processed, #loading-bar-glb {
103
  display: none;
104
  position: absolute;
105
+ top: 50%;
106
+ left: 50%;
107
+ transform: translate(-50%, -50%);
108
  width: 60px;
109
  height: 60px;
110
  border: 8px solid #f3f3f3;
 
113
  animation: spin 1s linear infinite;
114
  }
115
 
 
 
 
 
 
 
 
116
  @keyframes spin {
117
  0% { transform: translate(-50%, -50%) rotate(0deg); }
118
  100% { transform: translate(-50%, -50%) rotate(360deg); }
 
120
 
121
  /* Текст CheckBox в белый */
122
  .gr-checkbox label {
123
+ color: #FFFFFF !important;
124
  }
125
  """
126
 
 
154
  step=0.05,
155
  )
156
  do_remove_background = gr.Checkbox(
157
+ label="Remove Background", # Текст перекрашен в белый через CSS
158
  value=True,
159
  )
160