njavidfar commited on
Commit
e0ef166
·
verified ·
1 Parent(s): d64b5f3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import StableDiffusionPipeline
3
+ import gradio as gr
4
+
5
+ # Load Stable Diffusion model (we'll run it on CPU)
6
+ pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
7
+ pipe.to("cpu")
8
+
9
+ # Inference function to generate an image from text prompt
10
+ def generate_image(prompt):
11
+ image = pipe(prompt).images[0]
12
+ return image
13
+
14
+ # Gradio interface for text-to-image generation
15
+ iface = gr.Interface(
16
+ fn=generate_image,
17
+ inputs="text", # User will input a text prompt
18
+ outputs="image", # The output will be an image
19
+ title="Stable Diffusion Text-to-Image",
20
+ description="Generate images from text using Stable Diffusion 1.5",
21
+ )
22
+
23
+ # Launch the interface
24
+ iface.launch()