rohitr01 commited on
Commit
eca5a0d
·
verified ·
1 Parent(s): bc2e881

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -1,10 +1,17 @@
1
  import torch
2
  from diffusers import StableDiffusionPipeline
 
3
 
4
- pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16
5
- )
6
- pipe = pipe.to("cpu")
7
 
8
- prompt = "a photo of an astronaut riding a horse on mars"
9
- image = pipe(prompt).images[0]
10
- image
 
 
 
 
 
 
 
 
1
  import torch
2
  from diffusers import StableDiffusionPipeline
3
+ import gradio as gr
4
 
5
+ # Load model on CPU (use torch_dtype=torch.float32 for CPU compatibility)
6
+ pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float32).to("cpu")
 
7
 
8
+ # Function to generate image
9
+ def generate_image(prompt):
10
+ image = pipe(prompt).images[0]
11
+ return image
12
+
13
+ # Gradio interface
14
+ iface = gr.Interface(fn=generate_image, inputs="text", outputs="image", title="Stable Diffusion Image Generator")
15
+
16
+ # Launch app
17
+ iface.launch()