Spaces:
Paused
Paused
Abdulrahman1989
commited on
Commit
·
9d98595
1
Parent(s):
2eeb736
Fix the code to show both video and mesh as well
Browse files- Image3DProcessor.py +10 -1
- app.py +19 -8
Image3DProcessor.py
CHANGED
@@ -101,4 +101,13 @@ class Image3DProcessor:
|
|
101 |
rendered_image = t_to_512(rendered_image)
|
102 |
loop_renders.append(torch.clamp(rendered_image * 255, 0.0, 255.0).detach().permute(1, 2, 0).cpu().numpy().astype(np.uint8))
|
103 |
|
104 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
rendered_image = t_to_512(rendered_image)
|
102 |
loop_renders.append(torch.clamp(rendered_image * 255, 0.0, 255.0).detach().permute(1, 2, 0).cpu().numpy().astype(np.uint8))
|
103 |
|
104 |
+
# Save the mesh and video in memory and return them as byte arrays
|
105 |
+
mesh_buffer = BytesIO()
|
106 |
+
export_to_obj(mesh_buffer, reconstruction_unactivated) # Function that saves mesh to an in-memory buffer
|
107 |
+
mesh_data = mesh_buffer.getvalue()
|
108 |
+
|
109 |
+
video_buffer = BytesIO()
|
110 |
+
imageio.mimwrite(video_buffer, loop_renders, format='mp4', fps=30)
|
111 |
+
video_data = video_buffer.getvalue()
|
112 |
+
|
113 |
+
return mesh_data, video_data
|
app.py
CHANGED
@@ -18,11 +18,11 @@ class VideoGenerator:
|
|
18 |
self.processor = Image3DProcessor(model_cfg_path, model_repo_id, model_filename)
|
19 |
|
20 |
def generate_3d_video(self, image):
|
21 |
-
# Process the image and create a 3D video
|
22 |
processed_image = self.processor.preprocess(image, preprocess_background=False)
|
23 |
-
|
24 |
|
25 |
-
return
|
26 |
|
27 |
class GradioApp:
|
28 |
def __init__(self):
|
@@ -37,9 +37,20 @@ class GradioApp:
|
|
37 |
|
38 |
def full_pipeline(self, prompt):
|
39 |
initial_image = self.sdxl_generator.generate_images([prompt])[0]
|
40 |
-
#controlled_image = self.controlnet_processor.controlnet_image(initial_image)
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
def launch(self):
|
45 |
interface = gr.Interface(
|
@@ -47,7 +58,7 @@ class GradioApp:
|
|
47 |
inputs=gr.Textbox(label="Input Prompt"),
|
48 |
outputs=[
|
49 |
gr.Image(label="Generated Image"),
|
50 |
-
|
51 |
gr.Video(label="3D Model Video")
|
52 |
],
|
53 |
title="SDXL to ControlNet to 3D Pipeline",
|
@@ -57,4 +68,4 @@ class GradioApp:
|
|
57 |
|
58 |
if __name__ == "__main__":
|
59 |
app = GradioApp()
|
60 |
-
app.launch()
|
|
|
18 |
self.processor = Image3DProcessor(model_cfg_path, model_repo_id, model_filename)
|
19 |
|
20 |
def generate_3d_video(self, image):
|
21 |
+
# Process the image and create a 3D video and mesh
|
22 |
processed_image = self.processor.preprocess(image, preprocess_background=False)
|
23 |
+
mesh_data, video_data = self.processor.reconstruct_and_export(processed_image)
|
24 |
|
25 |
+
return mesh_data, video_data
|
26 |
|
27 |
class GradioApp:
|
28 |
def __init__(self):
|
|
|
37 |
|
38 |
def full_pipeline(self, prompt):
|
39 |
initial_image = self.sdxl_generator.generate_images([prompt])[0]
|
40 |
+
# controlled_image = self.controlnet_processor.controlnet_image(initial_image)
|
41 |
+
mesh_data, video_data = self.video_generator.generate_3d_video(initial_image)
|
42 |
+
|
43 |
+
# Create a temporary file to display the mesh content
|
44 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".obj") as mesh_file:
|
45 |
+
mesh_file.write(mesh_data)
|
46 |
+
mesh_path = mesh_file.name
|
47 |
+
|
48 |
+
# Create a temporary file to display the video content
|
49 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as video_file:
|
50 |
+
video_file.write(video_data)
|
51 |
+
video_path = video_file.name
|
52 |
+
|
53 |
+
return initial_image, mesh_path, video_path
|
54 |
|
55 |
def launch(self):
|
56 |
interface = gr.Interface(
|
|
|
58 |
inputs=gr.Textbox(label="Input Prompt"),
|
59 |
outputs=[
|
60 |
gr.Image(label="Generated Image"),
|
61 |
+
gr.File(label="3D Mesh (.obj)"),
|
62 |
gr.Video(label="3D Model Video")
|
63 |
],
|
64 |
title="SDXL to ControlNet to 3D Pipeline",
|
|
|
68 |
|
69 |
if __name__ == "__main__":
|
70 |
app = GradioApp()
|
71 |
+
app.launch()
|