Spaces:
Running
Running
File size: 1,183 Bytes
cedc5fc 559af25 705608a 559af25 cedc5fc 559af25 cedc5fc 705608a 559af25 705608a cedc5fc 559af25 cedc5fc 559af25 cedc5fc 559af25 cedc5fc 559af25 cedc5fc 705608a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import gradio as gr
import torch
from diffusers import StableDiffusionImg2ImgPipeline
from PIL import Image
# Use CPU and optimize precision
device = "cpu"
dtype = torch.float32 # float16 is only for GPUs
# Load model with reduced precision for CPU
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
"nitrosocke/Ghibli-Diffusion",
torch_dtype=dtype
).to(device)
# Disable xformers (only for GPU)
print("⚠️ Running on CPU: xformers disabled, inference will be slow.")
def process_image(input_img):
if input_img is None:
return None
input_img = input_img.convert("RGB").resize((512, 512))
result = pipe(
prompt="ghibli style, studio ghibli, anime art",
image=input_img,
strength=0.5, # Reduce strength to speed up processing
guidance_scale=7.5 # Lower guidance for faster inference
).images[0]
return result
# Gradio UI
demo = gr.Interface(
fn=process_image,
inputs=gr.Image(type="pil"),
outputs=gr.Image(type="pil"),
title="🎨 Ghibli Style Transfer (CPU Optimized)",
description="Upload an image to transform it into Studio Ghibli style artwork"
)
demo.launch()
|