GhibliCards / app.py
XuehangCang's picture
update:app Markdown label
bc20e87
import gradio as gr
import spaces
import torch
from diffusers import FluxPipeline
from PIL import Image
from huggingface_hub import login
import os
login(token=os.getenv('HF_TOKEN'))
@spaces.GPU
def generate_image_with_flux(prompt: str, height: int = 1024, width: int = 1024, guidance_scale: float = 3.5, num_inference_steps: int = 50) -> Image.Image:
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
pipe.to("cuda")
ghibli_keywords = "Studio Ghibli style, illustration, whimsical, painterly"
optimized_prompt = f"{prompt}, {ghibli_keywords}"
generator = torch.Generator("cuda").manual_seed(0)
image = pipe(
optimized_prompt,
height=height,
width=width,
guidance_scale=guidance_scale,
num_inference_steps=num_inference_steps,
generator=generator
).images[0]
return image
with gr.Blocks() as demo:
gr.Markdown("# Create Your GhibliCard")
with gr.Row():
with gr.Column():
prompt_input = gr.Textbox(label="prompt", placeholder="Enter a description of the GhibliCard you want to generate...")
height_input = gr.Slider(minimum=256, maximum=1024, step=128, value=1024, label="Height")
width_input = gr.Slider(minimum=256, maximum=1024, step=128, value=1024, label="Width")
guidance_scale_input = gr.Slider(minimum=1.0, maximum=10.0, step=0.5, value=3.5, label="guidance scale")
steps_input = gr.Slider(minimum=10, maximum=100, step=10, value=50, label="inference steps")
generate_button = gr.Button("Generate GhibliCard")
with gr.Column():
output_image = gr.Image(label="Generated GhibliCard")
generate_button.click(
generate_image_with_flux,
inputs=[prompt_input, height_input, width_input, guidance_scale_input, steps_input],
outputs=output_image
)
if __name__ == "__main__":
demo.launch()