Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import StableDiffusionPipeline
|
4 |
+
|
5 |
+
# Load model (you can replace this with your own if needed)
|
6 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
7 |
+
"runwayml/stable-diffusion-v1-5",
|
8 |
+
torch_dtype=torch.float16
|
9 |
+
).to("cuda")
|
10 |
+
|
11 |
+
def generate_image(prompt, width, height, guidance_scale):
|
12 |
+
image = pipe(prompt, width=width, height=height, guidance_scale=guidance_scale).images[0]
|
13 |
+
return image
|
14 |
+
|
15 |
+
with gr.Blocks() as demo:
|
16 |
+
gr.Markdown("## 🎨 AI Image Generator - Powered by Stable Diffusion")
|
17 |
+
|
18 |
+
with gr.Row():
|
19 |
+
prompt = gr.Textbox(label="Enter your prompt", placeholder="e.g. A futuristic city at sunset")
|
20 |
+
|
21 |
+
with gr.Row():
|
22 |
+
width = gr.Slider(256, 1024, value=512, step=64, label="Width")
|
23 |
+
height = gr.Slider(256, 1024, value=512, step=64, label="Height")
|
24 |
+
guidance_scale = gr.Slider(1, 20, value=7.5, step=0.5, label="Guidance Scale")
|
25 |
+
|
26 |
+
generate_btn = gr.Button("Generate Image")
|
27 |
+
output = gr.Image(label="Generated Image")
|
28 |
+
|
29 |
+
generate_btn.click(fn=generate_image, inputs=[prompt, width, height, guidance_scale], outputs=output)
|
30 |
+
|
31 |
+
demo.launch()
|