Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from diffusers import DiffusionPipeline
|
3 |
+
import torch
|
4 |
+
import random
|
5 |
+
|
6 |
+
# Use lightweight model (faster & less resources)
|
7 |
+
model_id = "OFA-Sys/small-stable-diffusion-v0" # 35x smaller than SDXL
|
8 |
+
|
9 |
+
# Load model with optimizations
|
10 |
+
pipe = DiffusionPipeline.from_pretrained(
|
11 |
+
model_id,
|
12 |
+
torch_dtype=torch.float16
|
13 |
+
).to("cuda")
|
14 |
+
|
15 |
+
def generate(prompt):
|
16 |
+
# Random seed for unique generations
|
17 |
+
random_seed = random.randint(0, 2147483647)
|
18 |
+
generator = torch.Generator("cuda").manual_seed(random_seed)
|
19 |
+
|
20 |
+
# Generate image with variations
|
21 |
+
image = pipe(
|
22 |
+
prompt,
|
23 |
+
num_inference_steps=20, # Faster generation
|
24 |
+
generator=generator
|
25 |
+
).images[0]
|
26 |
+
|
27 |
+
return image
|
28 |
+
|
29 |
+
# Simple interface
|
30 |
+
gr.Interface(
|
31 |
+
fn=generate,
|
32 |
+
inputs=gr.Textbox(label="Enter text prompt"),
|
33 |
+
outputs=gr.Image(label="Generated Image"),
|
34 |
+
title="Simple AI Image Generator",
|
35 |
+
description="Type anything - get random images every time!",
|
36 |
+
allow_flagging="never" # Remove feedback buttons
|
37 |
+
).launch()
|