Spaces:
Running
on
T4
Running
on
T4
Upload gradio_app.py
Browse files- gradio_app.py +29 -16
gradio_app.py
CHANGED
@@ -137,25 +137,39 @@ def build_model_viewer_html(save_folder, height=660, width=790, textured=False):
|
|
137 |
template_html = template_html.replace('#src#', f'{related_path}/')
|
138 |
f.write(template_html)
|
139 |
|
140 |
-
iframe_tag = f'<iframe src="file={output_html_path}" height="{height}" width="100%" frameborder="0"></iframe>'
|
141 |
-
print(
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
-
return f"""
|
145 |
-
<div style='height: {height}; width: 100%;'>
|
146 |
-
{iframe_tag}
|
147 |
-
</div>
|
148 |
-
"""
|
149 |
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
|
|
154 |
|
|
|
|
|
|
|
|
|
155 |
# Encode the GLB file as base64 to embed directly in the HTML
|
156 |
-
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
#model_viewer_html = f"""
|
161 |
#<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
|
@@ -166,7 +180,6 @@ def build_model_viewer_html(save_folder, height=660, width=790, textured=False):
|
|
166 |
# style="height: {height}px; width: {width}px;">
|
167 |
#</model-viewer>
|
168 |
#"""
|
169 |
-
|
170 |
#return model_viewer_html
|
171 |
|
172 |
@spaces.GPU(duration=40)
|
|
|
137 |
template_html = template_html.replace('#src#', f'{related_path}/')
|
138 |
f.write(template_html)
|
139 |
|
140 |
+
#iframe_tag = f'<iframe src="file={output_html_path}" height="{height}" width="100%" frameborder="0"></iframe>'
|
141 |
+
#print(
|
142 |
+
# f'Find html file {output_html_path}, {os.path.exists(output_html_path)}')
|
143 |
+
|
144 |
+
#return f"""
|
145 |
+
# <div style='height: {height}; width: 100%;'>
|
146 |
+
# {iframe_tag}
|
147 |
+
# </div>
|
148 |
+
#"""
|
149 |
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
+
if textured:
|
152 |
+
mesh_file_path = os.path.join(save_folder, f'textured_mesh.glb')
|
153 |
+
else:
|
154 |
+
mesh_file_path = os.path.join(save_folder, f'white_mesh.glb')
|
155 |
+
|
156 |
|
157 |
+
print(
|
158 |
+
f'Find html file {mesh_file_path}, {os.path.exists(mesh_file_path)}')
|
159 |
+
|
160 |
+
|
161 |
# Encode the GLB file as base64 to embed directly in the HTML
|
162 |
+
with open(mesh_file_path, 'rb') as f:
|
163 |
+
encoded = base64.b64encode(f.read()).decode('utf-8')
|
164 |
+
|
165 |
+
html = f"""
|
166 |
+
<model-viewer src="data:model/gltf-binary;base64,{encoded}"
|
167 |
+
alt="3D Model" camera-controls auto-rotate
|
168 |
+
style="height: 690px; width: 500px;">
|
169 |
+
</model-viewer>
|
170 |
+
"""
|
171 |
+
|
172 |
+
return html
|
173 |
|
174 |
#model_viewer_html = f"""
|
175 |
#<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
|
|
|
180 |
# style="height: {height}px; width: {width}px;">
|
181 |
#</model-viewer>
|
182 |
#"""
|
|
|
183 |
#return model_viewer_html
|
184 |
|
185 |
@spaces.GPU(duration=40)
|