Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from diffusers import DiffusionPipeline | |
| import torch | |
| # 1. USE A SMALLER MODEL (CPU-FRIENDLY) | |
| model_id = "OFA-Sys/small-stable-diffusion-v0" # Lightweight model | |
| # 2. SIMPLIFIED PIPELINE FOR CPU | |
| pipe = DiffusionPipeline.from_pretrained(model_id) | |
| pipe = pipe.to("cpu") # Force CPU usage | |
| # 3. FASTER GENERATION SETTINGS | |
| def generate_image(prompt, negative_prompt="", steps=13): | |
| return pipe( | |
| prompt=prompt, | |
| negative_prompt=negative_prompt, | |
| num_inference_steps=steps, | |
| guidance_scale=7.5 | |
| ).images[0] | |
| # 4. STREAMLINED UI | |
| with gr.Blocks(css="footer {visibility: hidden !important;}") as demo: | |
| gr.Markdown("<h1>📋 Generative Image Creator</h1>") | |
| with gr.Row(): | |
| with gr.Column(): | |
| prompt = gr.Textbox(label="Your Guidance", value="a beautiful flower") | |
| negative = gr.Textbox(label="Avoid (Optional)", value="low-resolution") | |
| steps = gr.Slider(1, 30, value=11, label="Quality Steps", visible=False) | |
| btn = gr.Button("Generate Image") | |
| output = gr.Image(label="Result", height=400), | |
| article="<br><br><br><br><br><br><br><br><br><br><br><br><br><br>Hello" | |
| btn.click(fn=generate_image, inputs=[prompt, negative, steps], outputs=output) | |
| gr.Examples( | |
| examples=[ | |
| ["cityscape at night, red lights", "people"], | |
| ["watercolor painting of a flower", "photorealistic"] | |
| ], | |
| inputs=[prompt, negative] | |
| ) | |
| demo.launch() |