radames commited on
Commit
27dbef9
·
1 Parent(s): ee9ff91
Files changed (2) hide show
  1. app.py +12 -13
  2. model.html +33 -0
app.py CHANGED
@@ -6,7 +6,6 @@ import tempfile
6
  import time
7
  import pathlib
8
 
9
-
10
  def create_from_text(prompt):
11
  temp_dir = tempfile.mkdtemp()
12
  sanitized_prompt = re.sub("[^0-9a-zA-Z]+", "_", prompt)
@@ -30,9 +29,9 @@ def create_from_text(prompt):
30
  ]
31
  subprocess.run(cmd1)
32
  subprocess.run(cmd2)
33
- return convert_obj_to_glb(f"{temp_dir}/{sanitized_prompt}.obj", temp_dir)
34
-
35
-
36
  def create_from_image(image):
37
  temp_dir = tempfile.mkdtemp()
38
  sanitized_prompt = "image"
@@ -65,7 +64,8 @@ def create_from_image(image):
65
  subprocess.run(cmd1)
66
  subprocess.run(cmd2)
67
  subprocess.run(cmd3)
68
- return convert_obj_to_glb(f"{temp_dir}/{sanitized_prompt}.obj", temp_dir)
 
69
 
70
 
71
  def convert_obj_to_glb(obj_path, out_path):
@@ -75,6 +75,10 @@ def convert_obj_to_glb(obj_path, out_path):
75
  return f_path
76
 
77
 
 
 
 
 
78
  def generate(prompt, image):
79
  if prompt:
80
  gr.Info("Generating from prompt")
@@ -100,14 +104,9 @@ source: https://github.com/dreamgaussian/dreamgaussian
100
  clear = gr.Button("Clear")
101
  btn = gr.Button("Generate")
102
  with gr.Column():
103
- model_3d = gr.Model3D(clear_color=[1, 1, 1, 1])
104
  btn.click(generate, inputs=[prompt, image], outputs=[model_3d])
105
- clear.click(
106
- lambda x: (gr.update(value=None), gr.update(value=None)),
107
- None,
108
- [prompt, image],
109
- queue=False,
110
- )
111
 
112
  demo.queue(api_open=False, concurrency_count=1)
113
- demo.launch(debug=True, show_api=False, inline=False, share=True)
 
6
  import time
7
  import pathlib
8
 
 
9
  def create_from_text(prompt):
10
  temp_dir = tempfile.mkdtemp()
11
  sanitized_prompt = re.sub("[^0-9a-zA-Z]+", "_", prompt)
 
29
  ]
30
  subprocess.run(cmd1)
31
  subprocess.run(cmd2)
32
+ glb_path = convert_obj_to_glb(f"{temp_dir}/{sanitized_prompt}.obj", temp_dir)
33
+ return get_html_model(glb_path)
34
+
35
  def create_from_image(image):
36
  temp_dir = tempfile.mkdtemp()
37
  sanitized_prompt = "image"
 
64
  subprocess.run(cmd1)
65
  subprocess.run(cmd2)
66
  subprocess.run(cmd3)
67
+ glb_path = convert_obj_to_glb(f"{temp_dir}/{sanitized_prompt}.obj", temp_dir)
68
+ return get_html_model(glb_path)
69
 
70
 
71
  def convert_obj_to_glb(obj_path, out_path):
 
75
  return f_path
76
 
77
 
78
+ def get_html_model(f_path):
79
+ iframe = f"""<iframe src="file=model.html" model-url="file={f_path}" width="100%" height="500px"></iframe>"""
80
+
81
+ return iframe
82
  def generate(prompt, image):
83
  if prompt:
84
  gr.Info("Generating from prompt")
 
104
  clear = gr.Button("Clear")
105
  btn = gr.Button("Generate")
106
  with gr.Column():
107
+ model_3d = gr.HTML(label="Model 3D", show_label=True)
108
  btn.click(generate, inputs=[prompt, image], outputs=[model_3d])
109
+ clear.click(lambda x: (gr.update(value=None),gr.update(value=None)), None, [prompt, image], queue=False)
 
 
 
 
 
110
 
111
  demo.queue(api_open=False, concurrency_count=1)
112
+ demo.launch(debug=True, show_api=False, inline=False, share=True)
model.html ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html>
2
+
3
+ <head>
4
+ <script src="https://preview.babylonjs.com/viewer/babylon.viewer.js"></script>
5
+ </head>
6
+ <script>
7
+ const viewerEl = document.querySelector("#viewer");
8
+ const iframe = window.frameElement;
9
+ const modeUrl = iframe.getAttribute("data-model-url");
10
+ const viewer = new BabylonViewer.DefaultViewer(viewerEl, {
11
+ scene: {
12
+ debug: false
13
+ },
14
+ camera: {
15
+ behaviors: {
16
+ autoRotate: {
17
+ idleRotationSpeed: 0.3,
18
+ idleRotationWaitTime: 3000
19
+ }
20
+ }
21
+ },
22
+ model: {
23
+ url: modeUrl
24
+ }
25
+ });
26
+
27
+ </script>
28
+
29
+ <body>
30
+ <div id="viewer"></div>
31
+ </body>
32
+
33
+ </html>