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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -12,9 +12,9 @@ device = "cuda:0" if torch.cuda.is_available() else "cpu"
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)
@@ -25,35 +25,38 @@ def check_input_image(input_image):
25
  if input_image is None:
26
  raise gr.Error("No image uploaded!")
27
 
 
28
  # Функция обработки изображения
29
  def preprocess(input_image, do_remove_background, foreground_ratio):
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 модели
48
  def generate(image):
49
  time.sleep(3) # Эмуляция времени обработки
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
 
 
57
  # Функции для управления лоадерами
58
  def start_loading_processed():
59
  return "<div id='loading-bar-processed' style='display: block;'></div>"
@@ -67,6 +70,7 @@ def start_loading_glb():
67
  def stop_loading_glb():
68
  return "<div id='loading-bar-glb' style='display: none;'></div>"
69
 
 
70
  # Настройка темы и CSS
71
  class CustomTheme(gr.themes.Base):
72
  def __init__(self):
@@ -76,10 +80,11 @@ class CustomTheme(gr.themes.Base):
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 */
@@ -203,4 +208,4 @@ demo.launch(
203
  server_name="0.0.0.0",
204
  server_port=7860,
205
  share=True,
206
- )
 
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)
 
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
  image = Image.fromarray((image * 255.0).astype(np.uint8))
35
+ return image
36
 
37
  if do_remove_background:
38
  image = input_image.convert("RGB")
39
+ image = remove_background(image)
40
  image = resize_foreground(image, foreground_ratio)
41
+ image = fill_background(image)
42
  else:
43
  image = input_image
44
  if image.mode == "RGBA":
45
+ image = fill_background(image)
46
  return image
47
 
48
+
49
  # Функция генерации 3D модели
50
  def generate(image):
51
  time.sleep(3) # Эмуляция времени обработки
52
  scene_codes = model(image, device=device)
53
  mesh = model.extract_mesh(scene_codes)[0]
54
  mesh = to_gradio_3d_orientation(mesh)
55
+ mesh_path2 = tempfile.NamedTemporaryFile(suffix=".glb", delete=False)
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
  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):
 
80
  self.background_fill_secondary = "#191a1e"
81
  self.background_fill_tertiary = "#191a1e"
82
  self.text_color_primary = "#FFFFFF"
83
+ self.text_color_secondary = "#FFFFFF"
84
+ self.text_color_tertiary = "#FFFFFF"
85
  self.input_background_fill = "#191a1e"
86
+ self.input_text_color = "#FFFFFF"
87
+
88
 
89
  css = """
90
  /* Скрываем системный лоадер Gradio */
 
208
  server_name="0.0.0.0",
209
  server_port=7860,
210
  share=True,
211
+ )