The-Best-Codes commited on
Commit
eda7a8f
1 Parent(s): 0b75b6a

Add loader in UI

Browse files
Files changed (2) hide show
  1. app.py +10 -7
  2. appOld.py +32 -0
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import gradio as gr
2
- import torch
3
  from diffusers import ShapEPipeline
4
  from diffusers.utils import export_to_gif
5
 
@@ -7,15 +6,19 @@ from diffusers.utils import export_to_gif
7
  ckpt_id = "openai/shap-e"
8
  pipe = ShapEPipeline.from_pretrained(ckpt_id)
9
 
10
- def generate_shap_e_gif(prompt):
11
  guidance_scale = 15.0
12
- images = pipe(
13
- prompt,
14
- guidance_scale=guidance_scale,
15
- num_inference_steps=64,
16
- ).images
 
 
 
17
 
18
  gif_path = export_to_gif(images, f"{prompt}_3d.gif")
 
19
  return gif_path
20
 
21
  # Create the Gradio interface
 
1
  import gradio as gr
 
2
  from diffusers import ShapEPipeline
3
  from diffusers.utils import export_to_gif
4
 
 
6
  ckpt_id = "openai/shap-e"
7
  pipe = ShapEPipeline.from_pretrained(ckpt_id)
8
 
9
+ def generate_shap_e_gif(prompt, progress=gr.Progress()):
10
  guidance_scale = 15.0
11
+ num_inference_steps = 64
12
+ progress(0, desc="Starting...")
13
+ images = []
14
+
15
+ for i in progress.tqdm(range(num_inference_steps), desc="Generating GIF"):
16
+ image = pipe(prompt, guidance_scale=guidance_scale, num_inference_steps=1).images[0]
17
+ images.append(image)
18
+ progress(i+1, total=num_inference_steps, desc="Processing")
19
 
20
  gif_path = export_to_gif(images, f"{prompt}_3d.gif")
21
+ progress(1, desc="Completed")
22
  return gif_path
23
 
24
  # Create the Gradio interface
appOld.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import ShapEPipeline
4
+ from diffusers.utils import export_to_gif
5
+
6
+ # Load the ShapE model
7
+ ckpt_id = "openai/shap-e"
8
+ pipe = ShapEPipeline.from_pretrained(ckpt_id)
9
+
10
+ def generate_shap_e_gif(prompt):
11
+ guidance_scale = 15.0
12
+ images = pipe(
13
+ prompt,
14
+ guidance_scale=guidance_scale,
15
+ num_inference_steps=64,
16
+ ).images
17
+
18
+ gif_path = export_to_gif(images, f"{prompt}_3d.gif")
19
+ return gif_path
20
+
21
+ # Create the Gradio interface
22
+ demo = gr.Interface(
23
+ fn=generate_shap_e_gif,
24
+ inputs=gr.Textbox(lines=2, placeholder="Enter a prompt"),
25
+ outputs=gr.File(),
26
+ title="ShapE 3D GIF Generator",
27
+ description="Enter a prompt to generate a 3D GIF using the ShapE model."
28
+ )
29
+
30
+ # Run the app
31
+ if __name__ == "__main__":
32
+ demo.launch()