Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,44 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from diffusers import
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
"OFA-Sys/small-stable-diffusion-v0", # Lightweight model
|
| 8 |
-
torch_dtype=torch.float32
|
| 9 |
-
)
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from diffusers import DiffusionPipeline
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# 1. USE A SMALLER MODEL (CPU-FRIENDLY)
|
| 6 |
+
model_id = "OFA-Sys/small-stable-diffusion-v0" # Lightweight model
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# 2. SIMPLIFIED PIPELINE FOR CPU
|
| 9 |
+
pipe = DiffusionPipeline.from_pretrained(model_id)
|
| 10 |
+
pipe = pipe.to("cpu") # Force CPU usage
|
| 11 |
|
| 12 |
+
# 3. FASTER GENERATION SETTINGS
|
| 13 |
+
def generate_image(prompt, negative_prompt="", steps=15):
|
| 14 |
+
return pipe(
|
| 15 |
+
prompt=prompt,
|
| 16 |
+
negative_prompt=negative_prompt,
|
| 17 |
+
num_inference_steps=steps,
|
| 18 |
+
guidance_scale=7.5
|
| 19 |
+
).images[0]
|
| 20 |
+
|
| 21 |
+
# 4. STREAMLINED UI
|
| 22 |
+
with gr.Blocks() as demo:
|
| 23 |
+
gr.Markdown("# ⚡ Lightning-Fast AI Image Generator")
|
| 24 |
+
|
| 25 |
+
with gr.Row():
|
| 26 |
+
with gr.Column():
|
| 27 |
+
prompt = gr.Textbox(label="Your Prompt", value="a cat astronaut")
|
| 28 |
+
negative = gr.Textbox(label="Avoid (Optional)", value="blurry, deformed")
|
| 29 |
+
steps = gr.Slider(1, 30, value=10, label="Quality Steps")
|
| 30 |
+
btn = gr.Button("Generate →")
|
| 31 |
+
|
| 32 |
+
output = gr.Image(label="Result", height=400)
|
| 33 |
+
|
| 34 |
+
btn.click(fn=generate_image, inputs=[prompt, negative, steps], outputs=output)
|
| 35 |
+
|
| 36 |
+
gr.Examples(
|
| 37 |
+
examples=[
|
| 38 |
+
["cyberpunk cityscape at night, neon lights", "people, text", 12],
|
| 39 |
+
["watercolor painting of a forest", "photorealistic, humans", 8]
|
| 40 |
+
],
|
| 41 |
+
inputs=[prompt, negative, steps]
|
| 42 |
+
)
|
| 43 |
|
| 44 |
demo.launch()
|