Alpha108 commited on
Commit
eeaed51
·
verified ·
1 Parent(s): d58b131

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from diffusers import StableDiffusionPipeline
3
+ import torch
4
+
5
+ # Load the Stable Diffusion model from Hugging Face Hub
6
+ model_id = "runwayml/stable-diffusion-v1-5"
7
+
8
+ pipe = StableDiffusionPipeline.from_pretrained(
9
+ model_id,
10
+ torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
11
+ )
12
+ pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
13
+
14
+ def generate_image(prompt):
15
+ image = pipe(prompt).images[0]
16
+ return image
17
+
18
+ # Gradio UI
19
+ demo = gr.Interface(
20
+ fn=generate_image,
21
+ inputs=gr.Textbox(label="Enter your prompt"),
22
+ outputs=gr.Image(label="Generated Image"),
23
+ title="Text-to-Image Generator",
24
+ description="Generate images from text using Stable Diffusion (v1-5)."
25
+ )
26
+
27
+ if __name__ == "__main__":
28
+ demo.launch()