ThomasSimonini HF staff commited on
Commit
6b702cc
β€’
1 Parent(s): c7ae546

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -62
app.py CHANGED
@@ -114,67 +114,6 @@ STEP4_HEADER = """
114
 
115
  """
116
 
117
- # Code for TripoSR
118
- """
119
- # These part of the code (check_input_image and preprocess were taken from https://huggingface.co/spaces/stabilityai/TripoSR/blob/main/app.py)
120
- if torch.cuda.is_available():
121
- device = "cuda:0"
122
- else:
123
- device = "cpu"
124
-
125
- model = TSR.from_pretrained(
126
- "stabilityai/TripoSR",
127
- config_name="config.yaml",
128
- weight_name="model.ckpt",
129
- )
130
- model.renderer.set_chunk_size(131072)
131
- model.to(device)
132
-
133
- rembg_session = rembg.new_session()
134
-
135
-
136
- def check_input_image(input_image):
137
- if input_image is None:
138
- raise gr.Error("No image uploaded!")
139
-
140
-
141
- def preprocess(input_image, do_remove_background, foreground_ratio):
142
- def fill_background(image):
143
- image = np.array(image).astype(np.float32) / 255.0
144
- image = image[:, :, :3] * image[:, :, 3:4] + (1 - image[:, :, 3:4]) * 0.5
145
- image = Image.fromarray((image * 255.0).astype(np.uint8))
146
- return image
147
-
148
- if do_remove_background:
149
- image = input_image.convert("RGB")
150
- image = remove_background(image, rembg_session)
151
- image = resize_foreground(image, foreground_ratio)
152
- image = fill_background(image)
153
- else:
154
- image = input_image
155
- if image.mode == "RGBA":
156
- image = fill_background(image)
157
- return image
158
-
159
-
160
- @spaces.GPU
161
- def generate(image, mc_resolution, formats=["obj", "glb"]):
162
- scene_codes = model(image, device=device)
163
- mesh = model.extract_mesh(scene_codes, resolution=mc_resolution)[0]
164
- mesh = to_gradio_3d_orientation(mesh)
165
-
166
- mesh_path_glb = tempfile.NamedTemporaryFile(suffix=f".glb", delete=False)
167
- mesh.export(mesh_path_glb.name)
168
-
169
- mesh_path_obj = tempfile.NamedTemporaryFile(suffix=f".obj", delete=False)
170
- mesh.apply_scale([-1, 1, 1]) # Otherwise the visualized .obj will be flipped
171
- mesh.export(mesh_path_obj.name)
172
-
173
- return mesh_path_obj.name, mesh_path_glb.name
174
- """
175
-
176
-
177
-
178
  ###############################################################################
179
  # Configuration for InstantMesh
180
  # All this code is from https://huggingface.co/spaces/TencentARC/InstantMesh/blob/main/app.py
@@ -186,7 +125,7 @@ if cuda_path:
186
  else:
187
  print("CUDA installation not found")
188
 
189
- config_path = 'configs/instant-mesh-large.yaml'
190
  config = OmegaConf.load(config_path)
191
  config_name = os.path.basename(config_path).replace('.yaml', '')
192
  model_config = config.model_config
 
114
 
115
  """
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  ###############################################################################
118
  # Configuration for InstantMesh
119
  # All this code is from https://huggingface.co/spaces/TencentARC/InstantMesh/blob/main/app.py
 
125
  else:
126
  print("CUDA installation not found")
127
 
128
+ config_path = 'instantmesh/configs/instant-mesh-large.yaml'
129
  config = OmegaConf.load(config_path)
130
  config_name = os.path.basename(config_path).replace('.yaml', '')
131
  model_config = config.model_config