Dua Rajper commited on
Commit
03824ce
·
verified ·
1 Parent(s): 7f5a2f3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from diffusers import StableDiffusionPipeline
3
+ import torch
4
+
5
+ # Load the Stable Diffusion model
6
+ model_id = "runwayml/stable-diffusion-v1-5"
7
+ pipeline = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
8
+ pipeline.to("cuda" if torch.cuda.is_available() else "cpu")
9
+
10
+ def generate_image(prompt):
11
+ image = pipeline(prompt).images[0]
12
+ return image
13
+
14
+ # Define the Gradio interface
15
+ interface = gr.Interface(
16
+ fn=generate_image,
17
+ inputs=gr.Textbox(label="Enter your text prompt"),
18
+ outputs=gr.Image(type="pil"),
19
+ title="Text-to-Image Generator",
20
+ description="Enter a prompt, and the AI will generate an image based on it.",
21
+ )
22
+
23
+ # Launch the app
24
+ if __name__ == "__main__":
25
+ interface.launch()