Wom_test / app.py
LEIDIA's picture
Update app.py
6c5943e verified
raw
history blame
3.87 kB
import gradio as gr
import numpy as np
import random
import torch
from diffusers import DiffusionPipeline
from datasets import load_dataset
# Configurações do dispositivo para uso apenas da CPU
device = "cpu"
model_repo_id = "stabilityai/sdxl-turbo" # Continuando com o modelo especificado
# Carregar o pipeline configurado para CPU
pipe = DiffusionPipeline.from_pretrained(model_repo_id)
pipe = pipe.to(device)
# Carregando o dataset do Hugging Face
dataset = load_dataset("LEIDIA/Data_Womleimg")
# Parâmetros para carregar o dataset personalizado
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."
]
# Definir parâmetros padrão para geração rápida
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)
# Função simples para gerar imagem
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
# Interface Gradio
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()