Rivan1220 commited on
Commit
5de704c
·
verified ·
1 Parent(s): 1fa1e95

Upload 2 files

Browse files
Files changed (2) hide show
  1. requirements.txt +5 -6
  2. text_to_image.py +24 -0
requirements.txt CHANGED
@@ -1,6 +1,5 @@
1
- accelerate
2
- diffusers
3
- invisible_watermark
4
- torch
5
- transformers
6
- xformers
 
1
+ torch
2
+ transformers
3
+ accelerate
4
+ diffusers
5
+ gradio
 
text_to_image.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import StableDiffusionPipeline
3
+ import gradio as gr
4
+
5
+ # Load the model (first time, downloads ~4GB weights)
6
+ pipe = StableDiffusionPipeline.from_pretrained(
7
+ "CompVis/stable-diffusion-v1-4",
8
+ torch_dtype=torch.float16
9
+ )
10
+ pipe.to("cuda" if torch.cuda.is_available() else "cpu")
11
+
12
+ # define generation function
13
+ def generate_image(prompt):
14
+ image = pipe(prompt).images[0]
15
+ return image
16
+
17
+ # build gradio interface
18
+ gr.Interface(
19
+ fn=generate_image,
20
+ inputs=gr.Textbox(label="Enter a text prompt", placeholder="e.g., a cat reading a newspaper"),
21
+ outputs="image",
22
+ title="🎨 Text to Image Generator",
23
+ description="Uses Stable Diffusion to turn text prompts into images"
24
+ ).launch()