pradeep4321 commited on
Commit
691b204
·
verified ·
1 Parent(s): 5f0402f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import StableDiffusionPipeline
4
+
5
+ # Load the Stable Diffusion v1.5 model (on CPU with float32)
6
+ model_id = "sd-legacy/stable-diffusion-v1-5"
7
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
8
+ pipe = pipe.to("cpu")
9
+
10
+ # Image generation function
11
+ def generate_image(prompt):
12
+ image = pipe(prompt).images[0]
13
+ return image
14
+
15
+ # Gradio UI setup
16
+ demo = gr.Interface(
17
+ fn=generate_image,
18
+ inputs=gr.Textbox(lines=2, placeholder="Describe your image...", label="Prompt"),
19
+ outputs=gr.Image(type="pil", label="Generated Image"),
20
+ title="🎨 Stable Diffusion v1.5 (CPU)",
21
+ description="Enter a prompt and generate an image using Stable Diffusion v1.5 on CPU.",
22
+ allow_flagging="never"
23
+ )
24
+
25
+ if __name__ == "__main__":
26
+ demo.launch()