wushuang98 commited on
Commit
ff71942
·
verified ·
1 Parent(s): 4c4b4bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -26
app.py CHANGED
@@ -1,5 +1,3 @@
1
- import os
2
- os.system("pip install /home/user/app/third_party/voxelize/udf_ext-0.0.0-cp310-cp310-linux_x86_64.whl")
3
  import torch
4
  import trimesh
5
  import datetime
@@ -16,7 +14,6 @@ from typing import Any
16
 
17
  import gradio as gr
18
  from gradio.themes.utils import colors, fonts, sizes
19
- import spaces
20
 
21
  # -----------------------------------------------------------------------------
22
  # THEME ▸ a soft glass-like dark theme with a vibrant primary accent
@@ -51,7 +48,18 @@ def check_input_image(input_image):
51
  # -----------------------------------------------------------------------------
52
  # PLACEHOLDER BACK-END HOOKS ▸ replace with your real logic
53
  # -----------------------------------------------------------------------------
54
- @spaces.GPU(duration=600)
 
 
 
 
 
 
 
 
 
 
 
55
  def image2mesh(
56
  image: Any,
57
  resolution: str = '1024',
@@ -68,10 +76,6 @@ def image2mesh(
68
  uid = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
69
  image.save(os.path.join(output_path, uid + '.png'))
70
 
71
- pipe = Direct3DS2Pipeline.from_pretrained('wushuang98/Direct3D-S2', subfolder="direct3d-s2-v-1-1")
72
- # pipe.to("cuda:0")
73
- pipe.to("cuda")
74
-
75
  mesh = pipe(
76
  image,
77
  sdf_resolution=int(resolution),
@@ -159,13 +163,6 @@ body { background:linear-gradient(215deg,#101113 0%,#0b0c0d 60%,#0d1014 100%) }
159
  # ---------- Gallery / Examples ----------
160
  with gr.Column(scale=3):
161
  gr.Markdown("### Examples", elem_classes="subtitle")
162
- # gr.Examples(
163
- # examples=[os.path.join("assets/test", i) for i in os.listdir("assets/test")],
164
- # inputs=[image_input],
165
- # examples_per_page=8,
166
- # label="Gallery",
167
- # elem_id="examples_gallery",
168
- # )
169
  with gr.Tabs(selected='tab_img_gallery') as gallery:
170
  with gr.Tab('Image to 3D Gallery', id='tab_img_gallery') as tab_gi:
171
  with gr.Row():
@@ -175,25 +172,16 @@ body { background:linear-gradient(215deg,#101113 0%,#0b0c0d 60%,#0d1014 100%) }
175
  label=None,
176
  examples_per_page=24
177
  )
178
- # gallery = gr.Gallery(
179
- # [os.path.join("assets/test", i) for i in os.listdir("assets/test")],
180
- # columns=2,
181
- # object_fit="contain",
182
- # elem_id="examples_gallery",
183
- # allow_preview=False,
184
- # )
185
 
186
 
187
  # ▸ callbacks
188
  outputs = [output_model_obj]
189
- # rmbg = BiRefNet(device="cuda:0")
190
- rmbg = BiRefNet(device="cuda")
191
 
192
  gen_btn.click(
193
  fn=check_input_image,
194
  inputs=[image_input]
195
  ).success(
196
- fn=rmbg.run,
197
  inputs=[image_input],
198
  outputs=[processed_image]
199
  ).success(
@@ -209,4 +197,4 @@ if __name__ == "__main__":
209
  parser.add_argument("--cached_dir", type=str, default="outputs/web")
210
  args = parser.parse_args()
211
 
212
- demo.queue().launch(share=True, allowed_paths=[args.cached_dir], server_port=7860)
 
 
 
1
  import torch
2
  import trimesh
3
  import datetime
 
14
 
15
  import gradio as gr
16
  from gradio.themes.utils import colors, fonts, sizes
 
17
 
18
  # -----------------------------------------------------------------------------
19
  # THEME ▸ a soft glass-like dark theme with a vibrant primary accent
 
48
  # -----------------------------------------------------------------------------
49
  # PLACEHOLDER BACK-END HOOKS ▸ replace with your real logic
50
  # -----------------------------------------------------------------------------
51
+
52
+
53
+ pipe = Direct3DS2Pipeline.from_pretrained('wushuang98/Direct3D-S2', subfolder="direct3d-s2-v-1-1")
54
+ pipe.to("cuda")
55
+
56
+ rmbg = BiRefNet(device="cuda")
57
+
58
+ @spaces.GPU
59
+ def run_rembg(image: Image.Image):
60
+ return rmbg.run(image)
61
+
62
+ @spaces.GPU
63
  def image2mesh(
64
  image: Any,
65
  resolution: str = '1024',
 
76
  uid = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
77
  image.save(os.path.join(output_path, uid + '.png'))
78
 
 
 
 
 
79
  mesh = pipe(
80
  image,
81
  sdf_resolution=int(resolution),
 
163
  # ---------- Gallery / Examples ----------
164
  with gr.Column(scale=3):
165
  gr.Markdown("### Examples", elem_classes="subtitle")
 
 
 
 
 
 
 
166
  with gr.Tabs(selected='tab_img_gallery') as gallery:
167
  with gr.Tab('Image to 3D Gallery', id='tab_img_gallery') as tab_gi:
168
  with gr.Row():
 
172
  label=None,
173
  examples_per_page=24
174
  )
 
 
 
 
 
 
 
175
 
176
 
177
  # ▸ callbacks
178
  outputs = [output_model_obj]
 
 
179
 
180
  gen_btn.click(
181
  fn=check_input_image,
182
  inputs=[image_input]
183
  ).success(
184
+ fn=run_rembg,
185
  inputs=[image_input],
186
  outputs=[processed_image]
187
  ).success(
 
197
  parser.add_argument("--cached_dir", type=str, default="outputs/web")
198
  args = parser.parse_args()
199
 
200
+ demo.queue().launch(share=True, allowed_paths=[args.cached_dir], server_port=7860)