|
import gradio as gr |
|
import torch |
|
from diffusers import StableDiffusionPipeline |
|
|
|
device = "cuda" if torch.cuda.is_available() else "cpu" |
|
model_id = "nitrosocke/Ghibli-Diffusion" |
|
|
|
|
|
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16 if device == "cuda" else torch.float32) |
|
pipe.to(device) |
|
pipe.enable_attention_slicing() |
|
|
|
def generate_ghibli_style(image): |
|
prompt = "ghibli style portrait" |
|
with torch.inference_mode(): |
|
result = pipe(prompt, image=image, strength=0.6, guidance_scale=6.5, num_inference_steps=25).images[0] |
|
return result |
|
|
|
iface = gr.Interface( |
|
fn=generate_ghibli_style, |
|
inputs=gr.Image(type="pil"), |
|
outputs=gr.Image(), |
|
title="Studio Ghibli Portrait Generator", |
|
description="Upload a photo to generate a Ghibli-style portrait!" |
|
) |
|
|
|
iface.launch() |
|
|