Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,10 @@ import torch
|
|
3 |
from diffusers import DiffusionPipeline
|
4 |
from datasets import load_dataset
|
5 |
from PIL import Image
|
6 |
-
|
|
|
|
|
|
|
7 |
|
8 |
# Configurações do dispositivo para uso apenas da CPU
|
9 |
device = "cpu"
|
@@ -14,7 +17,7 @@ pipe = DiffusionPipeline.from_pretrained(model_repo_id)
|
|
14 |
pipe = pipe.to(device)
|
15 |
|
16 |
# Carregando o dataset do Hugging Face
|
17 |
-
dataset = load_dataset("LEIDIA/Data_Womleimg")
|
18 |
|
19 |
|
20 |
# Parâmetros para carregar o dataset personalizado
|
@@ -39,6 +42,40 @@ dataset_descriptions = [
|
|
39 |
"A girl wearing a form-fitting black leather top, with long pink hair cascading down, creating a striking contrast in a neutral background."
|
40 |
]
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
# Definir parâmetros padrão para geração rápida
|
43 |
DEFAULT_PROMPT = "A beautiful brunette woman wearing a blue leather pants "
|
44 |
DEFAULT_INFERENCE_STEPS = 10
|
|
|
3 |
from diffusers import DiffusionPipeline
|
4 |
from datasets import load_dataset
|
5 |
from PIL import Image
|
6 |
+
import albumentations as A
|
7 |
+
from albumentations.pytorch import ToTensorV2
|
8 |
+
import numpy as np
|
9 |
+
import os
|
10 |
|
11 |
# Configurações do dispositivo para uso apenas da CPU
|
12 |
device = "cpu"
|
|
|
17 |
pipe = pipe.to(device)
|
18 |
|
19 |
# Carregando o dataset do Hugging Face
|
20 |
+
dataset = load_dataset("LEIDIA/Data_Womleimg", split="train")
|
21 |
|
22 |
|
23 |
# Parâmetros para carregar o dataset personalizado
|
|
|
42 |
"A girl wearing a form-fitting black leather top, with long pink hair cascading down, creating a striking contrast in a neutral background."
|
43 |
]
|
44 |
|
45 |
+
|
46 |
+
# Criar transformações usando Albumentations
|
47 |
+
albumentations_transform = A.Compose([
|
48 |
+
A.Resize(512, 512), # Redimensionar para o tamanho desejado
|
49 |
+
A.HorizontalFlip(p=0.5), # Flip horizontal com probabilidade de 50%
|
50 |
+
A.RandomBrightnessContrast(p=0.2), # Ajuste de brilho e contraste
|
51 |
+
A.GaussNoise(var_limit=(10.0, 50.0), p=0.3), # Adicionar ruído gaussiano
|
52 |
+
])
|
53 |
+
|
54 |
+
# Caminho temporário para salvar imagens transformadas
|
55 |
+
transformed_images_dir = "./transformed_images"
|
56 |
+
os.makedirs(transformed_images_dir, exist_ok=True)
|
57 |
+
|
58 |
+
# Aplicar transformações no dataset
|
59 |
+
def apply_transformations(example, idx):
|
60 |
+
# Carregar imagem usando PIL
|
61 |
+
image = Image.open(example["image"]).convert("RGB")
|
62 |
+
image_np = np.array(image)
|
63 |
+
|
64 |
+
# Aplicar Albumentations
|
65 |
+
transformed = albumentations_transform(image=image_np)
|
66 |
+
transformed_image = transformed["image"]
|
67 |
+
|
68 |
+
# Salvar imagem transformada
|
69 |
+
transformed_image_pil = Image.fromarray(transformed_image)
|
70 |
+
transformed_path = os.path.join(transformed_images_dir, f"transformed_{idx}.png")
|
71 |
+
transformed_image_pil.save(transformed_path)
|
72 |
+
|
73 |
+
return {"image": transformed_path}
|
74 |
+
|
75 |
+
# Mapear transformações no dataset
|
76 |
+
dataset = dataset.map(apply_transformations, with_indices=True)
|
77 |
+
|
78 |
+
|
79 |
# Definir parâmetros padrão para geração rápida
|
80 |
DEFAULT_PROMPT = "A beautiful brunette woman wearing a blue leather pants "
|
81 |
DEFAULT_INFERENCE_STEPS = 10
|