Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,42 +5,61 @@ import io
|
|
| 5 |
import os
|
| 6 |
|
| 7 |
# Importa a função melhorada do seu módulo (que já está ajustado )
|
| 8 |
-
from faceless_processing import
|
| 9 |
-
build_faceless_embroidery_assets,
|
| 10 |
-
LineartConfig
|
| 11 |
-
)
|
| 12 |
|
| 13 |
@spaces.GPU
|
| 14 |
-
def process_faceless(input_image, prompt="", negative_prompt="", is_cartoon=False):
|
| 15 |
if input_image is None:
|
| 16 |
return None, None
|
| 17 |
|
|
|
|
| 18 |
cfg = LineartConfig()
|
|
|
|
| 19 |
if is_cartoon:
|
| 20 |
# Afrouxa as regras para não apagar detalhes do desenho
|
| 21 |
cfg.lineart_threshold = 30 # Deixa os traços mais fracos passarem
|
| 22 |
cfg.lineart_min_perimeter = 0.0 # Aceita QUALQUER traço, mesmo 1 pixel
|
| 23 |
cfg.lineart_min_area = 0.0
|
| 24 |
cfg.lineart_morph_open = False
|
| 25 |
-
cfg.lineart_coarse = False # OBRIGA a IA a enxergar detalhes finos
|
| 26 |
-
cfg.force_canny = True # Força a usar o detector de bordas
|
| 27 |
-
cfg.min_contour_perimeter = 0.0 # Evita que o Canny apague
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
cfg.detect_eyebrows = False
|
| 33 |
cfg.erase_faces = False
|
| 34 |
cfg.erase_borders = False
|
|
|
|
|
|
|
| 35 |
cfg.face_min_size = (9999, 9999)
|
|
|
|
|
|
|
| 36 |
cfg.silhouette_line_thickness = 5
|
| 37 |
cfg.interior_line_thickness = 4
|
| 38 |
|
|
|
|
| 39 |
# Gera lineart e cutout usando a função otimizada
|
| 40 |
try:
|
| 41 |
lineart, cutout = build_faceless_embroidery_assets(
|
| 42 |
input_image,
|
| 43 |
cfg=cfg,
|
|
|
|
| 44 |
prompt=prompt or None,
|
| 45 |
negative_prompt=negative_prompt or None,
|
| 46 |
)
|
|
@@ -57,7 +76,8 @@ demo = gr.Interface(
|
|
| 57 |
gr.Image(type="pil", label="Imagem de Entrada"),
|
| 58 |
gr.Textbox(label="Prompt (Opcional)", value=""),
|
| 59 |
gr.Textbox(label="Prompt Negativo (Opcional)", value=""),
|
| 60 |
-
gr.Checkbox(label="Modo Cartoon / Desenho (Mantém detalhes e rostos)", value=False)
|
|
|
|
| 61 |
],
|
| 62 |
outputs=[
|
| 63 |
gr.Image(label="Lineart Final (Transparente)"),
|
|
|
|
| 5 |
import os
|
| 6 |
|
| 7 |
# Importa a função melhorada do seu módulo (que já está ajustado )
|
| 8 |
+
from faceless_processing import build_faceless_embroidery_assets, LineartConfig
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
@spaces.GPU
|
| 11 |
+
def process_faceless(input_image, prompt="", negative_prompt="", is_cartoon=False, detail="balanced"):
|
| 12 |
if input_image is None:
|
| 13 |
return None, None
|
| 14 |
|
| 15 |
+
# Configuração base
|
| 16 |
cfg = LineartConfig()
|
| 17 |
+
|
| 18 |
if is_cartoon:
|
| 19 |
# Afrouxa as regras para não apagar detalhes do desenho
|
| 20 |
cfg.lineart_threshold = 30 # Deixa os traços mais fracos passarem
|
| 21 |
cfg.lineart_min_perimeter = 0.0 # Aceita QUALQUER traço, mesmo 1 pixel
|
| 22 |
cfg.lineart_min_area = 0.0
|
| 23 |
cfg.lineart_morph_open = False
|
| 24 |
+
cfg.lineart_coarse = False # OBRIGA a IA a enxergar detalhes finos (teias)
|
| 25 |
+
cfg.force_canny = True # Força a usar o detector perfeito de bordas (para preencher as linhas de desenhos simples)
|
| 26 |
+
cfg.min_contour_perimeter = 0.0 # Evita que o Canny apague as pupilas e bolinhas pequenas
|
| 27 |
+
|
| 28 |
+
# Ajuste dinâmico com base no nível de detalhe (Detail Level)
|
| 29 |
+
if detail == "detailed":
|
| 30 |
+
cfg.gaussian_ksize = 3
|
| 31 |
+
cfg.bilateral_d = 3
|
| 32 |
+
cfg.canny_low = 30
|
| 33 |
+
cfg.canny_high = 70
|
| 34 |
+
elif detail == "soft":
|
| 35 |
+
cfg.gaussian_ksize = 7
|
| 36 |
+
cfg.bilateral_d = 9
|
| 37 |
+
cfg.canny_low = 60
|
| 38 |
+
cfg.canny_high = 120
|
| 39 |
+
else: # balanced e matendo linhas que Bugariam na Produção ficaremn Juntas
|
| 40 |
+
cfg.gaussian_ksize = 5
|
| 41 |
+
cfg.bilateral_d = 5
|
| 42 |
+
cfg.canny_low = 45
|
| 43 |
+
cfg.canny_high = 95
|
| 44 |
+
|
| 45 |
cfg.detect_eyebrows = False
|
| 46 |
cfg.erase_faces = False
|
| 47 |
cfg.erase_borders = False
|
| 48 |
+
|
| 49 |
+
# Impede de achar rosto e apagar os olhos/boca do desenho
|
| 50 |
cfg.face_min_size = (9999, 9999)
|
| 51 |
+
|
| 52 |
+
# Mantém grossinho para bordar!
|
| 53 |
cfg.silhouette_line_thickness = 5
|
| 54 |
cfg.interior_line_thickness = 4
|
| 55 |
|
| 56 |
+
# NÃO REDIMENSIONAMOS A IMAGEM – a função interna ( embroidery_processing.py) já lida com tamanhos variados.
|
| 57 |
# Gera lineart e cutout usando a função otimizada
|
| 58 |
try:
|
| 59 |
lineart, cutout = build_faceless_embroidery_assets(
|
| 60 |
input_image,
|
| 61 |
cfg=cfg,
|
| 62 |
+
use_huggingface=False, # Desativa Hugging Face (pode ativar se tiver token)
|
| 63 |
prompt=prompt or None,
|
| 64 |
negative_prompt=negative_prompt or None,
|
| 65 |
)
|
|
|
|
| 76 |
gr.Image(type="pil", label="Imagem de Entrada"),
|
| 77 |
gr.Textbox(label="Prompt (Opcional)", value=""),
|
| 78 |
gr.Textbox(label="Prompt Negativo (Opcional)", value=""),
|
| 79 |
+
gr.Checkbox(label="Modo Cartoon / Desenho (Mantém detalhes e rostos)", value=False),
|
| 80 |
+
gr.Dropdown(choices=["soft", "balanced", "detailed"], value="balanced", label="Nível de Detalhe (Apenas Modo Cartoon)")
|
| 81 |
],
|
| 82 |
outputs=[
|
| 83 |
gr.Image(label="Lineart Final (Transparente)"),
|