Spaces:
Runtime error
Runtime error
MarcusLoren
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from meshgpt_pytorch import (
|
3 |
+
MeshTransformer,
|
4 |
+
mesh_render
|
5 |
+
)
|
6 |
+
import igl
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
import numpy as np
|
10 |
+
|
11 |
+
transformer = MeshTransformer.from_pretrained("MarcusLoren/MeshGPT-preview")
|
12 |
+
|
13 |
+
def save_as_obj(file_path):
|
14 |
+
v, f = igl.read_triangle_mesh(file_path)
|
15 |
+
v, f, _, _ = igl.remove_unreferenced(v, f)
|
16 |
+
c, _ = igl.orientable_patches(f)
|
17 |
+
f, _ = igl.orient_outward(v, f, c)
|
18 |
+
igl.write_triangle_mesh(file_path, v, f)
|
19 |
+
return file_path
|
20 |
+
|
21 |
+
def predict(text, num_input, num_temp):
|
22 |
+
transformer.eval()
|
23 |
+
labels = [label.strip() for label in text.split(',')]
|
24 |
+
output = []
|
25 |
+
if num_input > 1:
|
26 |
+
for label in labels:
|
27 |
+
output.append((transformer.generate(texts = [label ] * num_input, temperature = num_temp)))
|
28 |
+
else:
|
29 |
+
output.append((transformer.generate(texts = [label ] * num_input, temperature = num_temp)))
|
30 |
+
|
31 |
+
mesh_render.save_rendering('./render.obj', output)
|
32 |
+
return save_as_obj('./render.obj')
|
33 |
+
|
34 |
+
gradio_app = gr.Interface(
|
35 |
+
predict,
|
36 |
+
inputs=[
|
37 |
+
gr.Textbox(label="Enter labels, separated by commas"),
|
38 |
+
gr.Number(value=1, label="Number of examples per input"),
|
39 |
+
gr.Slider(minimum=0, maximum=1, value=0, label="Temperature (0 to 1)")
|
40 |
+
],
|
41 |
+
outputs=gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model"),
|
42 |
+
title="MeshGPT Inference - (Rending doesn't work, please download for best result)",
|
43 |
+
)
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
+
gradio_app.launch(share=False)
|