Init stable diffusion
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import torch
|
| 4 |
+
from diffusers import StableDiffusionImg2ImgPipeline
|
| 5 |
+
|
| 6 |
+
# Load model (use a lightweight Ghibli/anime model from Hugging Face or CivitAI)
|
| 7 |
+
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
| 8 |
+
"CompVis/stable-diffusion-v1-4", # swap with Ghibli-style model if needed
|
| 9 |
+
torch_dtype=torch.float32,
|
| 10 |
+
).to("cpu")
|
| 11 |
+
|
| 12 |
+
def generate_ghibli_style(image, prompt):
|
| 13 |
+
output = pipe(prompt=prompt, image=image, strength=0.6, guidance_scale=7.5)
|
| 14 |
+
return output.images[0]
|
| 15 |
+
|
| 16 |
+
gr.Interface(
|
| 17 |
+
fn=generate_ghibli_style,
|
| 18 |
+
inputs=[gr.Image(type="pil"), gr.Textbox(label="Prompt")],
|
| 19 |
+
outputs=gr.Image(),
|
| 20 |
+
title="Ghibli Image Stylizer",
|
| 21 |
+
description="Upload an image and get a Studio Ghibli-style transformation for free!",
|
| 22 |
+
).launch()
|