Mariam-Elz commited on
Commit
5c9ed90
·
verified ·
1 Parent(s): 62d7392

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from PIL import Image
4
+ from model import CRM
5
+ from inference import generate3d
6
+ import numpy as np
7
+
8
+ # Load model
9
+ crm_path = "CRM.pth" # Make sure the model is uploaded to the Space
10
+ model = CRM(torch.load(crm_path, map_location="cpu"))
11
+ model = model.to("cuda:0" if torch.cuda.is_available() else "cpu")
12
+
13
+ def generate_3d(image_path, seed=1234, scale=5.5, step=30):
14
+ image = Image.open(image_path).convert("RGB")
15
+ np_img = np.array(image)
16
+ glb_path = generate3d(model, np_img, np_img, "cuda:0" if torch.cuda.is_available() else "cpu")
17
+ return glb_path
18
+
19
+ iface = gr.Interface(
20
+ fn=generate_3d,
21
+ inputs=gr.Image(type="filepath"),
22
+ outputs=gr.Model3D(),
23
+ title="Convolutional Reconstruction Model (CRM)",
24
+ description="Upload an image to generate a 3D model."
25
+ )
26
+
27
+ iface.launch()