File size: 2,318 Bytes
e166dfe
5dafacd
b27eba8
89cb5db
e166dfe
 
78451dd
964a38f
a84d7e6
e166dfe
 
3a6f3d0
5dafacd
e166dfe
acf2c5a
e166dfe
5dafacd
6b72774
3a6f3d0
acf2c5a
b2c3167
b27eba8
d256ee6
b2c3167
b27eba8
 
acf2c5a
b2c3167
212a667
308e61b
9309e46
b9d5063
308e61b
5dafacd
41bff10
 
 
 
 
 
9309e46
 
78451dd
5dafacd
 
9309e46
 
e166dfe
 
5dafacd
e166dfe
 
9309e46
5dafacd
a7b3e91
f80a1cb
cfc9560
9309e46
5dc3a63
9309e46
 
 
 
6b72774
5dafacd
6b72774
 
5dafacd
6b72774
9309e46
 
6b72774
 
5dafacd
 
e166dfe
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import gradio as gr
import torch
import json
import os
from diffusers import DiffusionPipeline
from datasets import load_dataset
from PIL import Image


# Configurações do dispositivo para uso apenas da CPU
device = "cpu"
model_repo_id = "stabilityai/stable-diffusion-xl-base-1.0"  # 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", split="train")# Carrega o dataset de imagens

# Acessando as descrições diretamente do dataset
for example in dataset:
    image_id = example["Wom01.jpg"].filename  # Nome do arquivo de imagem
    description = example.get("description", "Descrição não encontrada")  # Acessando a descrição
    print(f"ID da imagem: {image_id}, Descrição: {description}")


    # Definir parâmetros padrão para geração rápida
DEFAULT_PROMPT = "A beautiful brunette woman wearing a blue leather pants "
DEFAULT_INFERENCE_STEPS = 6
IMAGE_WIDTH = 512
IMAGE_HEIGHT = 816
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))

# Função simples para gerar imagem
def infer_simple(prompt):
    # Geração da imagem
    image = pipe(
        prompt=prompt,
        num_inference_steps=DEFAULT_INFERENCE_STEPS,
        guidance_scale=GUIDANCE_SCALE,
        height=IMAGE_HEIGHT,
        width=IMAGE_WIDTH,
    ).images[0]
    # Redimensionar a imagem para ser divisível por 8
    image = resize_to_divisible_by_8(image)
    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()