Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,50 @@
|
|
1 |
-
# app.py
|
2 |
import streamlit as st
|
3 |
-
from model import load_pipeline, generate_3d_gif
|
4 |
from PIL import Image
|
|
|
|
|
5 |
|
6 |
-
# Load pipeline
|
7 |
pipe = load_pipeline()
|
8 |
|
9 |
-
st.title("3D Model
|
10 |
prompt = st.text_input("Enter a prompt for the 3D model:", "a shark")
|
|
|
|
|
11 |
|
12 |
-
if st.button("Generate 3D GIF"):
|
13 |
with st.spinner("Generating 3D model..."):
|
14 |
-
|
15 |
|
16 |
-
#
|
17 |
-
|
|
|
18 |
|
19 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
with open(gif_path, "rb") as file:
|
21 |
st.download_button(
|
22 |
label="Download GIF",
|
23 |
data=file,
|
24 |
-
file_name="
|
25 |
mime="image/gif"
|
26 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from PIL import Image
|
3 |
+
from model import load_pipeline, generate_3d_model, convert_to_gif
|
4 |
+
import os
|
5 |
|
6 |
+
# Load pipeline
|
7 |
pipe = load_pipeline()
|
8 |
|
9 |
+
st.title("3D Model Generator with GIF Export")
|
10 |
prompt = st.text_input("Enter a prompt for the 3D model:", "a shark")
|
11 |
+
output_obj_path = "generated_3d_model.obj"
|
12 |
+
output_gif_path = "generated_3d_model.gif"
|
13 |
|
14 |
+
if st.button("Generate 3D Model and Convert to GIF"):
|
15 |
with st.spinner("Generating 3D model..."):
|
16 |
+
obj_path = generate_3d_model(pipe, prompt, output_path=output_obj_path)
|
17 |
|
18 |
+
# Load the 3D model in trimesh for rendering as images
|
19 |
+
mesh = trimesh.load(obj_path)
|
20 |
+
images = []
|
21 |
|
22 |
+
# Rotate and render views for GIF
|
23 |
+
for angle in range(0, 360, 30): # Capture images every 30 degrees
|
24 |
+
scene = mesh.scene()
|
25 |
+
scene.set_camera(angles=(angle, angle))
|
26 |
+
data = scene.save_image(resolution=(256, 256))
|
27 |
+
images.append(Image.open(BytesIO(data)))
|
28 |
+
|
29 |
+
# Convert to GIF
|
30 |
+
gif_path = convert_to_gif(images, gif_path=output_gif_path)
|
31 |
+
|
32 |
+
# Display GIF
|
33 |
+
st.image(gif_path, caption="Generated 3D Model GIF")
|
34 |
+
|
35 |
+
# Provide download options
|
36 |
with open(gif_path, "rb") as file:
|
37 |
st.download_button(
|
38 |
label="Download GIF",
|
39 |
data=file,
|
40 |
+
file_name="generated_3d_model.gif",
|
41 |
mime="image/gif"
|
42 |
)
|
43 |
+
|
44 |
+
with open(obj_path, "rb") as file:
|
45 |
+
st.download_button(
|
46 |
+
label="Download 3D Model (.obj)",
|
47 |
+
data=file,
|
48 |
+
file_name="generated_3d_model.obj",
|
49 |
+
mime="application/octet-stream"
|
50 |
+
)
|