initial commit
Browse files- .gitattributes +1 -0
- .gitignore +3 -0
- Dockerfile +16 -0
- app.py +48 -0
- requirements.txt +2 -0
- space_shuttle.stl +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.stl filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
flagged/
|
2 |
+
__pycache__/
|
3 |
+
.vscode
|
Dockerfile
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10-slim
|
2 |
+
|
3 |
+
ENV DEBIAN_FRONTEND noninteractive
|
4 |
+
ENV LANG C.UTF-8
|
5 |
+
ENV GRADIO_SERVER_NAME 0.0.0.0
|
6 |
+
|
7 |
+
RUN useradd -m -u 1000 user
|
8 |
+
WORKDIR /home/user/app
|
9 |
+
|
10 |
+
RUN --mount=target=requirements.txt,source=requirements.txt :\
|
11 |
+
&& pip install --no-cache-dir -r requirements.txt
|
12 |
+
|
13 |
+
COPY . .
|
14 |
+
EXPOSE 7860
|
15 |
+
|
16 |
+
ENTRYPOINT ["python", "app.py"]
|
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import trimesh
|
2 |
+
import tempfile
|
3 |
+
import atexit
|
4 |
+
import shutil
|
5 |
+
import pathlib
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
|
9 |
+
def cleanup_temp_directories():
|
10 |
+
print("Deleting temporary files")
|
11 |
+
for temp_dir in temp_directories:
|
12 |
+
try:
|
13 |
+
shutil.rmtree(temp_dir)
|
14 |
+
except FileNotFoundError:
|
15 |
+
print(f"Could not delete directory {temp_dir}")
|
16 |
+
|
17 |
+
|
18 |
+
def stl2glb(glb_file):
|
19 |
+
if not glb_file.endswith(".stl"):
|
20 |
+
raise gr.Error("Please upload a .stl file")
|
21 |
+
|
22 |
+
temp_dir = pathlib.Path(tempfile.mkdtemp())
|
23 |
+
temp_directories.append(temp_dir)
|
24 |
+
|
25 |
+
mesh = trimesh.load(glb_file)
|
26 |
+
glb = trimesh.exchange.gltf.export_glb(mesh)
|
27 |
+
|
28 |
+
output_file = (temp_dir / glb_file).with_suffix(".glb")
|
29 |
+
with open(output_file, "wb") as f:
|
30 |
+
f.write(glb)
|
31 |
+
|
32 |
+
return str(output_file)
|
33 |
+
|
34 |
+
|
35 |
+
if __name__ == "__main__":
|
36 |
+
temp_directories = []
|
37 |
+
atexit.register(cleanup_temp_directories)
|
38 |
+
|
39 |
+
demo = gr.Interface(
|
40 |
+
fn=stl2glb,
|
41 |
+
inputs=gr.Model3D(label="STL File"),
|
42 |
+
outputs=gr.Model3D(label="GLB File"),
|
43 |
+
examples=["space_shuttle.stl"],
|
44 |
+
title="STL2GLB Converter",
|
45 |
+
description="Convert a .stl file to a .glb file",
|
46 |
+
analytics_enabled=False,
|
47 |
+
)
|
48 |
+
demo.launch(share=False)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
trimesh
|
2 |
+
gradio
|
space_shuttle.stl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f8b96742bda278c6069d96f5054a320e3a21db2ad9db15c493a79f1f7b6482c6
|
3 |
+
size 7500084
|