Convert to cog.
Browse files- .gitignore +2 -0
- README.md +13 -1
- app.py +0 -49
- cog.yaml +12 -0
- predict.py +72 -0
- requirements.txt +0 -2
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
|
2 |
+
render.obj
|
README.md
CHANGED
@@ -10,4 +10,16 @@ pinned: false
|
|
10 |
license: mit
|
11 |
---
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
license: mit
|
11 |
---
|
12 |
|
13 |
+
```bash
|
14 |
+
cog predict -i text="cat"
|
15 |
+
```
|
16 |
+
|
17 |
+
Currently, this project is in the **Sandbox** phase, which is the initial stage of a project according to the V-Sekai maturity model.
|
18 |
+
|
19 |
+
The V-Sekai maturity model consists of three stages:
|
20 |
+
|
21 |
+
1. **Sandbox**: This stage serves as the starting point for projects, aiming to nurture innovation and project development.
|
22 |
+
2. **Incubating**: At this stage, projects are on their journey towards graduation, with an expectation of having a stable codebase and well-structured formation.
|
23 |
+
3. **Graduated**: These projects have reached maturity, adopting best practices and catering to a broad user base.
|
24 |
+
|
25 |
+
As the project fulfills the criteria laid out by V-Sekai, it will progress through these stages.
|
app.py
DELETED
@@ -1,49 +0,0 @@
|
|
1 |
-
import torch
|
2 |
-
import time
|
3 |
-
from meshgpt_pytorch import (
|
4 |
-
MeshTransformer,
|
5 |
-
mesh_render
|
6 |
-
)
|
7 |
-
import igl
|
8 |
-
|
9 |
-
import gradio as gr
|
10 |
-
import numpy as np
|
11 |
-
|
12 |
-
transformer = MeshTransformer.from_pretrained("MarcusLoren/MeshGPT-preview")
|
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 |
-
current_time = time.time()
|
26 |
-
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(current_time))
|
27 |
-
print(formatted_time, " Input:", text, "num_input", num_input, "num_temp",num_temp)
|
28 |
-
if num_input > 1:
|
29 |
-
for label in labels:
|
30 |
-
output.append((transformer.generate(texts = [label ] * num_input, temperature = num_temp)))
|
31 |
-
else:
|
32 |
-
output.append((transformer.generate(texts = labels , temperature = num_temp)))
|
33 |
-
|
34 |
-
mesh_render.save_rendering('./render.obj', output)
|
35 |
-
return save_as_obj('./render.obj')
|
36 |
-
|
37 |
-
gradio_app = gr.Interface(
|
38 |
-
predict,
|
39 |
-
inputs=[
|
40 |
-
gr.Textbox(label="Enter labels, separated by commas"),
|
41 |
-
gr.Number(value=1, label="Number of examples per input"),
|
42 |
-
gr.Slider(minimum=0, maximum=1, value=0, label="Temperature (0 to 1)")
|
43 |
-
],
|
44 |
-
outputs=gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model"),
|
45 |
-
title="MeshGPT Inference - (Rendering doesn't work, please download for best result)",
|
46 |
-
)
|
47 |
-
|
48 |
-
if __name__ == "__main__":
|
49 |
-
gradio_app.launch(share=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cog.yaml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
build:
|
2 |
+
gpu: true
|
3 |
+
system_packages:
|
4 |
+
- "libgl1-mesa-glx"
|
5 |
+
- "libglib2.0-0"
|
6 |
+
python_version: "3.11"
|
7 |
+
cuda: "11.5" # Query nvcc --version
|
8 |
+
python_packages:
|
9 |
+
- "torch==2.3.1"
|
10 |
+
- "libigl==2.5.1"
|
11 |
+
- "git+https://github.com/MarcusLoppe/meshgpt-pytorch.git@14126a20626356e9bd2e12dcf1a06872b9fe968d"
|
12 |
+
predict: "predict.py:Predictor"
|
predict.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from cog import BasePredictor, Input, File
|
2 |
+
import torch
|
3 |
+
import time
|
4 |
+
from meshgpt_pytorch import MeshTransformer, mesh_render
|
5 |
+
import igl
|
6 |
+
import numpy as np
|
7 |
+
|
8 |
+
class Predictor(BasePredictor):
|
9 |
+
def setup(self):
|
10 |
+
"""Load the model into memory to make running multiple predictions efficient"""
|
11 |
+
self.transformer = MeshTransformer.from_pretrained(
|
12 |
+
"MarcusLoren/MeshGPT-preview"
|
13 |
+
)
|
14 |
+
|
15 |
+
def save_as_obj(self, file_path):
|
16 |
+
v, f = igl.read_triangle_mesh(file_path)
|
17 |
+
v, f, _, _ = igl.remove_unreferenced(v, f)
|
18 |
+
c, _ = igl.orientable_patches(f)
|
19 |
+
f, _ = igl.orient_outward(v, f, c)
|
20 |
+
igl.write_triangle_mesh(file_path, v, f)
|
21 |
+
return file_path
|
22 |
+
|
23 |
+
def predict(
|
24 |
+
self,
|
25 |
+
text: str = Input(description="Enter labels, separated by commas"),
|
26 |
+
num_input: int = Input(description="Number of examples per input", default=1),
|
27 |
+
num_temp: float = Input(description="Temperature (0 to 1)", default=0),
|
28 |
+
) -> File:
|
29 |
+
"""Run a single prediction on the model"""
|
30 |
+
self.transformer.eval()
|
31 |
+
labels = [label.strip() for label in text.split(",")]
|
32 |
+
|
33 |
+
output = []
|
34 |
+
current_time = time.time()
|
35 |
+
|
36 |
+
formatted_time = time.strftime(
|
37 |
+
"%Y-%m-%d %H:%M:%S", time.localtime(current_time)
|
38 |
+
)
|
39 |
+
print(
|
40 |
+
formatted_time,
|
41 |
+
" Input:",
|
42 |
+
text,
|
43 |
+
"num_input",
|
44 |
+
num_input,
|
45 |
+
"num_temp",
|
46 |
+
num_temp,
|
47 |
+
)
|
48 |
+
|
49 |
+
if num_input > 1:
|
50 |
+
for label in labels:
|
51 |
+
output.append(
|
52 |
+
(
|
53 |
+
self.transformer.generate(
|
54 |
+
texts=[label] * num_input, temperature=num_temp
|
55 |
+
)
|
56 |
+
)
|
57 |
+
)
|
58 |
+
else:
|
59 |
+
output.append(
|
60 |
+
(self.transformer.generate(texts=labels, temperature=num_temp))
|
61 |
+
)
|
62 |
+
|
63 |
+
mesh_render.save_rendering("./render.obj", output)
|
64 |
+
|
65 |
+
return self.save_as_obj("./render.obj")
|
66 |
+
|
67 |
+
|
68 |
+
if __name__ == "__main__":
|
69 |
+
predictor = Predictor()
|
70 |
+
predictor.setup()
|
71 |
+
|
72 |
+
print(predictor.predict("cat", 1, 0.0))
|
requirements.txt
DELETED
@@ -1,2 +0,0 @@
|
|
1 |
-
git+https://github.com/MarcusLoppe/meshgpt-pytorch.git
|
2 |
-
libigl
|
|
|
|
|
|