Fouzanjaved commited on
Commit
4179b9f
Β·
verified Β·
1 Parent(s): ea32efe

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import StableDiffusionPipeline
3
+ import gradio as gr
4
+
5
+ # Load Stable Diffusion model from Hugging Face
6
+ model_id = "runwayml/stable-diffusion-v1-5" # Change to "stabilityai/stable-diffusion-xl-base-1.0" for SDXL
7
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
8
+ pipe.to("cuda") # Use "cpu" if no GPU is available
9
+
10
+ def generate_image(prompt):
11
+ image = pipe(prompt).images[0]
12
+ return image
13
+
14
+ # Create Gradio UI
15
+ demo = gr.Interface(
16
+ fn=generate_image,
17
+ inputs=gr.Textbox(label="Enter your prompt"),
18
+ outputs=gr.Image(),
19
+ title="Stable Diffusion Image Generator"
20
+ )
21
+
22
+ demo.launch()