Spaces:
Runtime error
Runtime error
| import os | |
| import gradio as gr | |
| import torch | |
| from diffusers import DDPMPipeline | |
| import warnings | |
| warnings.filterwarnings('ignore') | |
| # Constants | |
| MODEL_ID = "google/ddpm-celebahq-256" | |
| DEVICE = "cpu" # Force CPU for better compatibility | |
| DTYPE = torch.float32 | |
| def generate_image(steps=30): | |
| try: | |
| # Initialize pipeline with basic settings | |
| pipe = DDPMPipeline.from_pretrained(MODEL_ID) | |
| pipe = pipe.to(DEVICE) | |
| # Generate image | |
| with torch.inference_mode(): | |
| image = pipe( | |
| batch_size=1, | |
| num_inference_steps=steps, | |
| ).images[0] | |
| return image | |
| except Exception as e: | |
| print(f"Error generating image: {str(e)}") | |
| return None | |
| # Create the Gradio interface | |
| with gr.Blocks(title="Simple Image Generator") as demo: | |
| gr.Markdown("# π¨ Simple Image Generator") | |
| gr.Markdown("Generate celebrity-like faces using DDPM") | |
| with gr.Row(): | |
| with gr.Column(): | |
| steps = gr.Slider( | |
| minimum=10, | |
| maximum=50, | |
| value=30, | |
| step=1, | |
| label="Steps" | |
| ) | |
| generate_btn = gr.Button("π¨ Generate", variant="primary") | |
| with gr.Column(): | |
| output_image = gr.Image(label="Generated Image", type="pil") | |
| generate_btn.click( | |
| fn=generate_image, | |
| inputs=[ | |
| steps, | |
| ], | |
| outputs=output_image | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |