Spaces:
Runtime error
Runtime error
kilma98
commited on
Commit
·
d2d2257
1
Parent(s):
4677526
added gif file generation example
Browse files
app.py
CHANGED
@@ -1,2 +1,33 @@
|
|
1 |
-
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from diffusers import ShapEPipeline
|
3 |
+
import gradio as gr
|
4 |
+
from diffusers.utils import export_to_gif
|
5 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
6 |
+
|
7 |
+
def display_gif(gif_path):
|
8 |
+
return gif_path
|
9 |
+
|
10 |
+
pipe = ShapEPipeline.from_pretrained("openai/shap-e", torch_dtype=torch.float16, variant="fp16")
|
11 |
+
pipe = pipe.to(device)
|
12 |
+
|
13 |
+
guidance_scale = 15.0
|
14 |
+
prompt = ["A firecracker", "A birthday cupcake"]
|
15 |
+
|
16 |
+
images = pipe(
|
17 |
+
prompt,
|
18 |
+
guidance_scale=guidance_scale,
|
19 |
+
num_inference_steps=64,
|
20 |
+
frame_size=256,
|
21 |
+
).images
|
22 |
+
|
23 |
+
|
24 |
+
gif_file = export_to_gif(images[0], "firecracker_3d.gif")
|
25 |
+
export_to_gif(images[1], "cake_3d.gif")
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
interface = gr.Interface(fn=display_gif, inputs=[], outputs="image")
|
31 |
+
|
32 |
+
interface.launch(share=True, examples=[gif_file])
|
33 |
+
|