Spaces:
Running
on
Zero
Running
on
Zero
test app from TEXTure
Browse files
app.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
from __future__ import annotations
|
4 |
+
|
5 |
+
import os
|
6 |
+
|
7 |
+
import gradio as gr
|
8 |
+
|
9 |
+
from model import Model
|
10 |
+
|
11 |
+
DESCRIPTION = '''# [TEXTure](https://github.com/TEXTurePaper/TEXTurePaper)
|
12 |
+
|
13 |
+
- This demo only accepts as input `.obj` files with less than 100,000 faces.
|
14 |
+
- Inference takes about 10 minutes on a T4 GPU.
|
15 |
+
'''
|
16 |
+
if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
|
17 |
+
DESCRIPTION += f'\n<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. <a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
|
18 |
+
|
19 |
+
model = Model()
|
20 |
+
|
21 |
+
with gr.Blocks(css='style.css') as demo:
|
22 |
+
gr.Markdown(DESCRIPTION)
|
23 |
+
with gr.Row():
|
24 |
+
with gr.Column():
|
25 |
+
input_shape = gr.Model3D(label='Input 3D mesh')
|
26 |
+
text = gr.Text(label='Text')
|
27 |
+
seed = gr.Slider(label='Seed',
|
28 |
+
minimum=0,
|
29 |
+
maximum=100000,
|
30 |
+
value=3,
|
31 |
+
step=1)
|
32 |
+
guidance_scale = gr.Slider(label='Guidance scale',
|
33 |
+
minimum=0,
|
34 |
+
maximum=50,
|
35 |
+
value=7.5,
|
36 |
+
step=0.1)
|
37 |
+
run_button = gr.Button('Run')
|
38 |
+
with gr.Column():
|
39 |
+
progress_text = gr.Text(label='Progress')
|
40 |
+
with gr.Tabs():
|
41 |
+
with gr.TabItem(label='Images from each viewpoint'):
|
42 |
+
viewpoint_images = gr.Gallery(show_label=False).style(
|
43 |
+
columns=4, height='auto')
|
44 |
+
with gr.TabItem(label='Result 3D model'):
|
45 |
+
result_3d_model = gr.Model3D(show_label=False)
|
46 |
+
with gr.TabItem(label='Output mesh file'):
|
47 |
+
output_file = gr.File(show_label=False)
|
48 |
+
with gr.Row():
|
49 |
+
examples = [
|
50 |
+
['shapes/dragon1.obj', 'a photo of a dragon', 0, 7.5],
|
51 |
+
['shapes/dragon2.obj', 'a photo of a dragon', 0, 7.5],
|
52 |
+
['shapes/eagle.obj', 'a photo of an eagle', 0, 7.5],
|
53 |
+
['shapes/napoleon.obj', 'a photo of Napoleon Bonaparte', 3, 7.5],
|
54 |
+
['shapes/nascar.obj', 'A next gen nascar', 2, 10],
|
55 |
+
]
|
56 |
+
gr.Examples(examples=examples,
|
57 |
+
inputs=[
|
58 |
+
input_shape,
|
59 |
+
text,
|
60 |
+
seed,
|
61 |
+
guidance_scale,
|
62 |
+
],
|
63 |
+
outputs=[
|
64 |
+
result_3d_model,
|
65 |
+
output_file,
|
66 |
+
],
|
67 |
+
cache_examples=False)
|
68 |
+
|
69 |
+
run_button.click(fn=model.run,
|
70 |
+
inputs=[
|
71 |
+
input_shape,
|
72 |
+
text,
|
73 |
+
seed,
|
74 |
+
guidance_scale,
|
75 |
+
],
|
76 |
+
outputs=[
|
77 |
+
viewpoint_images,
|
78 |
+
result_3d_model,
|
79 |
+
output_file,
|
80 |
+
progress_text,
|
81 |
+
])
|
82 |
+
|
83 |
+
demo.queue(max_size=5).launch(debug=True)
|