Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
!pip --quiet install imageio[ffmpeg] PyMCubes trimesh rembg[gpu,cli] kiui
|
2 |
+
|
3 |
+
import torch
|
4 |
+
from transformers import AutoModel, AutoProcessor
|
5 |
+
|
6 |
+
# load the model and processor
|
7 |
+
model = AutoModel.from_pretrained("jadechoghari/vfusion3d", trust_remote_code=True)
|
8 |
+
processor = AutoProcessor.from_pretrained("jadechoghari/vfusion3d")
|
9 |
+
|
10 |
+
# download and preprocess the image
|
11 |
+
import requests
|
12 |
+
from PIL import Image
|
13 |
+
from io import BytesIO
|
14 |
+
|
15 |
+
image_url = 'https://sm.ign.com/ign_nordic/cover/a/avatar-gen/avatar-generations_prsz.jpg'
|
16 |
+
response = requests.get(image_url)
|
17 |
+
image = Image.open(BytesIO(response.content))
|
18 |
+
|
19 |
+
# preprocess the image and get the source camera
|
20 |
+
image, source_camera = processor(image)
|
21 |
+
|
22 |
+
|
23 |
+
# generate planes (default output)
|
24 |
+
output_planes = model(image, source_camera)
|
25 |
+
print("Planes shape:", output_planes.shape)
|
26 |
+
|
27 |
+
# generate a 3D mesh
|
28 |
+
output_planes, mesh_path = model(image, source_camera, export_mesh=True)
|
29 |
+
print("Planes shape:", output_planes.shape)
|
30 |
+
print("Mesh saved at:", mesh_path)
|
31 |
+
|
32 |
+
# Generate a video
|
33 |
+
output_planes, video_path = model(image, source_camera, export_video=True)
|
34 |
+
print("Planes shape:", output_planes.shape)
|
35 |
+
print("Video saved at:", video_path)
|