|
import gradio as gr |
|
import numpy as np |
|
import random |
|
import torch |
|
from diffusers import DiffusionPipeline |
|
from datasets import load_dataset |
|
|
|
|
|
|
|
device = "cpu" |
|
model_repo_id = "stabilityai/sdxl-turbo" |
|
|
|
|
|
pipe = DiffusionPipeline.from_pretrained(model_repo_id) |
|
pipe = pipe.to(device) |
|
|
|
|
|
dataset = load_dataset("LEIDIA/Data_Womleimg") |
|
|
|
|
|
|
|
dataset_descriptions = [ |
|
"A woman wearing a full blue leather catsuit", |
|
"A woman in black leather pants", |
|
"A legs woman in tight high blue leather boots", |
|
"A woman in a long red leather jacket, red leather shorts, and tight high red leather boots", |
|
"A legs woman in cream color leather pants", |
|
"A woman in purple leather leggings with tight high black leather boots", |
|
"A woman in black leather top and a long black leather skirt", |
|
"A blonde woman with long curly hair wearing a yellow mini tight leather skirt", |
|
"A thin Asian woman wearing a thigh-long black leather dress", |
|
"Simple high brown leather boots", |
|
"A beautiful brunette woman wearing leather clothes", |
|
"A beautiful brunette woman in a sleeveless black dress seated at a bar holding a glass of champagne, with a cozy and elegant atmosphere in the background.", |
|
"A curly blonde woman wearing a bold red leather jacket paired with black leather tight pants and red high-heeled leather boots, creating a modern and edgy vibe.", |
|
"An ebony woman standing outdoors against a backdrop of rolling hills and a cloudy sky, wearing a striking outfit of a red leather shirt, black leather mini corset, red plaid skirt, and knee-high red lace-up leather boots.", |
|
"A blonde curly woman wearing a fitted, shiny blue leather outfit including a jacket and pants with metallic buttons, paired with knee-high boots, in a neutral-colored room.", |
|
"A girl in a black leather outfit with a heart-shaped cutout top, high-waisted leggings, and a purple cape, giving a superhero vibe.", |
|
"A girl in a sleek black leather cropped top with a zip closure and high-waisted bottom, paired with long black gloves and pink hair styled in a ponytail, creating a bold and fashion-forward look.", |
|
"A girl wearing a form-fitting black leather top, with long pink hair cascading down, creating a striking contrast in a neutral background." |
|
] |
|
|
|
|
|
DEFAULT_PROMPT = "A beautiful brunette woman wearing a leather outfit" |
|
DEFAULT_INFERENCE_STEPS = 6 |
|
IMAGE_WIDTH = 512 |
|
IMAGE_HEIGHT = 812 |
|
GUIDANCE_SCALE = 5.5 |
|
|
|
def resize_to_divisible_by_8(image): |
|
width, height = image.size |
|
new_width = width + (8 - width % 8) if width % 8 != 0 else width |
|
new_height = height + (8 - height % 8) if height % 8 != 0 else height |
|
return image.resize((new_width, new_height)) |
|
|
|
image = pipe(prompt, width=width, height=height) |
|
image = resize_to_divisible_by_8(image) |
|
|
|
|
|
def infer_simple(prompt): |
|
image = pipe( |
|
prompt=prompt, |
|
num_inference_steps=DEFAULT_INFERENCE_STEPS, |
|
guidance_scale=GUIDANCE_SCALE, |
|
height=IMAGE_HEIGHT, |
|
width=IMAGE_WIDTH, |
|
).images[0] |
|
return image |
|
|
|
|
|
with gr.Blocks() as demo: |
|
with gr.Row(): |
|
gr.Markdown("## Text-to-Image Wom Test - Quick CPU Version") |
|
|
|
prompt = gr.Textbox( |
|
label="Prompt", |
|
value=DEFAULT_PROMPT, |
|
placeholder="Describe the image you want to generate", |
|
) |
|
|
|
generate_button = gr.Button("Generate") |
|
result = gr.Image(label="Generated Image") |
|
|
|
generate_button.click( |
|
fn=infer_simple, |
|
inputs=prompt, |
|
outputs=result, |
|
) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|