ZubairAhmed777 commited on
Commit
10d7fd4
·
verified ·
1 Parent(s): cc74790

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import StableDiffusionPipeline
3
+ import gradio as gr
4
+
5
+ # Load the Stable Diffusion model (text-to-image generator)
6
+ model_id = "runwayml/stable-diffusion-v1-5"
7
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
8
+ pipe.to("cuda") # If you have a GPU, use it to speed up generation
9
+
10
+ # Function to generate images from text prompts
11
+ def generate_image(prompt):
12
+ # Generate image based on the prompt
13
+ image = pipe(prompt).images[0]
14
+ return image
15
+
16
+ # Create Gradio interface
17
+ iface = gr.Interface(
18
+ fn=generate_image, # Function to run
19
+ inputs=gr.Textbox(lines=2, placeholder="Enter your prompt..."), # Text input for prompts
20
+ outputs=gr.Image(), # Display the generated image
21
+ title="Text-to-Image Generator",
22
+ description="Enter a text prompt to generate an image using Stable Diffusion."
23
+ )
24
+
25
+ # Launch the Gradio interface
26
+ iface.launch()