Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import torch | |
| from diffusers import StableDiffusionPipeline | |
| from PIL import Image | |
| # Load the pre-trained Ghibli-Diffusion model | |
| model_id = "nitrosocke/Ghibli-Diffusion" | |
| pipeline = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) | |
| pipeline.to("cuda") # Ensure GPU acceleration | |
| def generate_ghibli_portrait(image): | |
| # Convert input image to PIL format | |
| input_image = Image.open(image).convert("RGB").resize((512, 512)) | |
| # Generate image using the model | |
| prompt = "Ghibli-style portrait of a person, highly detailed, soft lighting" | |
| result = pipeline(prompt=prompt, image=input_image).images[0] | |
| return result | |
| # Gradio UI | |
| demo = gr.Interface( | |
| fn=generate_ghibli_portrait, | |
| inputs=gr.Image(type="file", label="Upload your photo"), | |
| outputs=gr.Image(label="Ghibli-style Portrait"), | |
| title="Studio Ghibli Portrait Generator", | |
| description="Upload your photo to generate a Ghibli-style portrait using AI." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |