Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load model (smaller for faster loading)
|
| 6 |
+
model = StableDiffusionPipeline.from_pretrained(
|
| 7 |
+
"OFA-Sys/small-stable-diffusion-v0", # Lightweight model
|
| 8 |
+
torch_dtype=torch.float32
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
def generate_image(prompt):
|
| 12 |
+
return model(prompt).images[0]
|
| 13 |
+
|
| 14 |
+
# Create Gradio interface
|
| 15 |
+
demo = gr.Interface(
|
| 16 |
+
fn=generate_image,
|
| 17 |
+
inputs=gr.Textbox(label="Describe your image"),
|
| 18 |
+
outputs=gr.Image(label="Generated Image"),
|
| 19 |
+
title="🎨 AI Image Generator",
|
| 20 |
+
examples=[["a cat astronaut"], ["colorful jellyfish in space"]]
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
demo.launch()
|