Spaces:
Running
on
Zero
Running
on
Zero
File size: 2,410 Bytes
79e7646 |
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 45 46 47 48 49 50 51 52 53 |
import gradio as gr
import torch
from diffusers import AutoPipelineForImage2Image
from diffusers.utils import load_image
# === Load SDXL and LoRA from Hugging Face ===
pipe = AutoPipelineForImage2Image.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
torch_dtype=torch.float16,
variant="fp16",
use_safetensors=True
).to("cuda")
pipe.load_lora_weights("theoracle/sdxl-lora-headshot")
# === Inference function ===
def generate_image(image, prompt, negative_prompt, strength, guidance_scale):
image = image.resize((1024, 1024))
result = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
image=image,
strength=strength,
guidance_scale=guidance_scale,
num_inference_steps=50
).images[0]
return result
# === Gradio UI ===
demo = gr.Interface(
fn=generate_image,
inputs=[
gr.Image(type="pil", label="Upload Headshot"),
gr.Textbox(
label="Prompt",
lines=4,
value="a photo of a professional corporate TOK headshot with nice hair and heavy make up, featuring a confident female with blonde hair in formal business attire, clean background, soft natural lighting, clear facial features, natural makeup or well-groomed face, direct or angled eye contact, neutral or friendly expression, wearing a blazer or business suit, realistic skin texture, high-resolution detail, styled hair e.g., parted, neat, or voluminous"
),
gr.Textbox(
label="Negative Prompt",
lines=4,
value="brown hair, cartoon, anime, painting, drawing, low resolution, blurry, deformed face, extra limbs, unrealistic skin, overly saturated colors, harsh lighting, exaggerated makeup, fantasy, hat, helmet, sunglasses, messy background, extreme poses, profile-only shots, old-fashioned clothing, distorted proportions, unnatural expressions, glitch, watermark, text, duplicate face"
),
gr.Slider(minimum=0.1, maximum=1.0, step=0.05, value=0.20, label="Strength"),
gr.Slider(minimum=1.0, maximum=20.0, step=0.5, value=17.0, label="Guidance Scale")
],
outputs=gr.Image(type="pil", label="Generated Image"),
title="SDXL LoRA - Corporate Headshot Generator",
description="Upload a headshot and customize prompts to generate a refined corporate-style portrait using SDXL and a LoRA adapter."
)
demo.launch()
|