dmitriitochilkin commited on
Commit
a9e44d5
1 Parent(s): 38bbc60

add examples and change markdown

Browse files
app.py CHANGED
@@ -8,12 +8,55 @@ import numpy as np
8
  import rembg
9
  import torch
10
  from PIL import Image
 
11
 
12
  from tsr.system import TSR
13
  from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation
14
 
15
  HF_TOKEN = os.getenv("HF_TOKEN")
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  if torch.cuda.is_available():
18
  device = "cuda:0"
19
  else:
@@ -63,14 +106,13 @@ def generate(image):
63
  mesh.export(mesh_path.name)
64
  return mesh_path.name
65
 
 
 
 
 
66
 
67
  with gr.Blocks() as demo:
68
- gr.Markdown(
69
- """
70
- ## TripoSR Demo
71
- [TripoSR](https://github.com/VAST-AI-Research/TripoSR) is a state-of-the-art open-source model for **fast** feedforward 3D reconstruction from a single image, collaboratively developed by [Tripo AI](https://www.tripo3d.ai/) and [Stability AI](https://stability.ai/).
72
- """
73
- )
74
  with gr.Row(variant="panel"):
75
  with gr.Column():
76
  with gr.Row():
@@ -107,6 +149,18 @@ with gr.Blocks() as demo:
107
  Note: The model shown here will be flipped due to some visualization issues. Please download to get the correct result.
108
  """
109
  )
 
 
 
 
 
 
 
 
 
 
 
 
110
  submit.click(fn=check_input_image, inputs=[input_image]).success(
111
  fn=preprocess,
112
  inputs=[input_image, do_remove_background, foreground_ratio],
 
8
  import rembg
9
  import torch
10
  from PIL import Image
11
+ from functools import partial
12
 
13
  from tsr.system import TSR
14
  from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation
15
 
16
  HF_TOKEN = os.getenv("HF_TOKEN")
17
 
18
+ HEADER = """
19
+ # TripoSR Demo
20
+ <table>
21
+ <tr>
22
+ <td style="text-align: center;">
23
+ <a href="https://stability.ai">
24
+ <img src="https://images.squarespace-cdn.com/content/v1/6213c340453c3f502425776e/6c9c4c25-5410-4547-bc26-dc621cdacb25/Stability+AI+logo.png" width="200" height="40" />
25
+ </a>
26
+ </td>
27
+ <td style="border-left: 1px solid #000; width: 1px;"></td>
28
+ <td style="text-align: center;">
29
+ <a href="https://www.tripo3d.ai">
30
+ <img src="https://www.tripo3d.ai/logo.png" width="170" height="40" />
31
+ </a>
32
+ </td>
33
+ </tr>
34
+ </table>
35
+
36
+ <table>
37
+ <tr>
38
+ <td style="text-align: center;">
39
+ <a href="https://huggingface.co/stabilityai/TripoSR"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Model_Card-Huggingface-orange"></a>
40
+ </td>
41
+ <td style="border-left: 1px solid #000; width: 1px;"></td>
42
+ <td style="text-align: center;">
43
+ <a href="https://github.com/VAST-AI-Research/TripoSR"><img src="logos/github-mark-white.png" height="20"></a>
44
+ </td>
45
+ <td style="border-left: 1px solid #000; width: 1px;"></td>
46
+ <td style="text-align: left;">
47
+ <a href="https://github.com/VAST-AI-Research/TripoSR"><img src="https://img.shields.io/badge/arXiv-1234.56789-b31b1b.svg" height="20"></a>
48
+ </td>
49
+ </tr>
50
+ </table>
51
+
52
+ **TripoSR** is a state-of-the-art open-source model for **fast** feedforward 3D reconstruction from a single image, developed in collaboration between [Tripo AI](https://www.tripo3d.ai/) and [Stability AI](https://stability.ai/).
53
+
54
+ **Tips:**
55
+ 1. If you find the result is unsatisfied, please try to change the foreground ratio. It might improve the results.
56
+ 2. Please disable "Remove Background" option only if your input image is RGBA with transparent background, image contents are centered and occupy more than 70% of image width or height.
57
+ """
58
+
59
+
60
  if torch.cuda.is_available():
61
  device = "cuda:0"
62
  else:
 
106
  mesh.export(mesh_path.name)
107
  return mesh_path.name
108
 
109
+ def run_example(image_pil):
110
+ preprocessed = preprocess(image_pil, False, 0.9)
111
+ mesh_name = generate(preprocessed)
112
+ return preprocessed, mesh_name
113
 
114
  with gr.Blocks() as demo:
115
+ gr.Markdown(HEADER)
 
 
 
 
 
116
  with gr.Row(variant="panel"):
117
  with gr.Column():
118
  with gr.Row():
 
149
  Note: The model shown here will be flipped due to some visualization issues. Please download to get the correct result.
150
  """
151
  )
152
+ with gr.Row(variant="panel"):
153
+ gr.Examples(
154
+ examples=[
155
+ os.path.join("examples", img_name) for img_name in sorted(os.listdir("examples"))
156
+ ],
157
+ inputs=[input_image],
158
+ outputs=[processed_image, output_model],
159
+ cache_examples=True,
160
+ fn=partial(run_example),
161
+ label="Examples",
162
+ examples_per_page=20
163
+ )
164
  submit.click(fn=check_input_image, inputs=[input_image]).success(
165
  fn=preprocess,
166
  inputs=[input_image, do_remove_background, foreground_ratio],
examples/chair_p.webp ADDED
examples/flamingo_p.webp ADDED
examples/hamburger_p.webp ADDED
examples/horse_p.webp ADDED
examples/iso_house.webp ADDED
examples/marble_p.webp ADDED
examples/police_woman_p.webp ADDED
examples/poly_fox.webp ADDED
examples/robot_p.webp ADDED
examples/teapot.webp ADDED
examples/tiger_girl.webp ADDED
examples/unicorn_p.webp ADDED
logos/github-mark-white.png ADDED
markdown.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # TripoSR Demo
2
+ <table>
3
+ <tr>
4
+ <td style="text-align: center;">
5
+ <a href="https://stability.ai">
6
+ <img src="https://images.squarespace-cdn.com/content/v1/6213c340453c3f502425776e/6c9c4c25-5410-4547-bc26-dc621cdacb25/Stability+AI+logo.png" height="40" />
7
+ </a>
8
+ </td>
9
+ <td style="border-left: 1px solid #000; width: 1px;"></td>
10
+ <td style="text-align: center;">
11
+ <a href="https://www.tripo3d.ai">
12
+ <img src="https://www.tripo3d.ai/logo.png" height="40" />
13
+ </a>
14
+ </td>
15
+ </tr>
16
+ </table>
17
+
18
+ <table cellspacing="0" cellpadding="0">
19
+ <tr>
20
+ <td style="text-align: center;">
21
+ <a href="https://huggingface.co/stabilityai/TripoSR"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Model_Card-Huggingface-orange"></a>
22
+ </td>
23
+ <td style="border-left: 1px solid #000; width: 1px;"></td>
24
+ <td style="text-align: center;">
25
+ <a href="https://github.com/VAST-AI-Research/TripoSR"><img src="logos/github-mark-white.png" height="20"></a>
26
+ </td>
27
+ <td style="border-left: 1px solid #000; width: 1px;"></td>
28
+ <td style="text-align: left;">
29
+ <a href="https://github.com/VAST-AI-Research/TripoSR"><img src="https://img.shields.io/badge/arXiv-1234.56789-b31b1b.svg" height="20"></a>
30
+ </td>
31
+ </tr>
32
+ </table>
33
+
34
+
35
+
36
+ **TripoSR** is a state-of-the-art open-source model for **fast** feedforward 3D reconstruction from a single image, developed in collaboration between [Tripo AI](https://www.tripo3d.ai/) and [Stability AI](https://stability.ai/).
37
+
38
+ **Tips:**
39
+ 1. If you find the result is unsatisfied, please try to change the foreground ratio. It might improve the results.
40
+ 2. Please disable "Remove Background" option only if your input image is RGBA with transparent background, image contents are centered and occupy more than 70% of image width or height.