Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,42 +3,29 @@ import gradio as gr
|
|
| 3 |
from PIL import Image
|
| 4 |
import io
|
| 5 |
import os
|
| 6 |
-
import tempfile
|
| 7 |
|
| 8 |
-
# Importa a função melhorada do seu módulo (que já está ajustado)
|
| 9 |
-
from faceless_processing import build_faceless_embroidery_assets
|
| 10 |
|
| 11 |
@spaces.GPU
|
| 12 |
def process_faceless(input_image, prompt="", negative_prompt=""):
|
| 13 |
if input_image is None:
|
| 14 |
return None, None
|
| 15 |
|
| 16 |
-
# NÃO REDIMENSIONAMOS A IMAGEM – a função interna já lida com tamanhos variados.
|
| 17 |
# Gera lineart e cutout usando a função otimizada
|
| 18 |
try:
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
)
|
| 23 |
-
lineart, cutout
|
| 24 |
-
|
| 25 |
-
# Save to temp files to preserve RGBA transparency channels
|
| 26 |
-
lineart_path = os.path.join(tempfile.gettempdir(), f"lineart_{os.getpid()}_{os.urandom(4).hex()}.png")
|
| 27 |
-
cutout_path = os.path.join(tempfile.gettempdir(), f"cutout_{os.getpid()}_{os.urandom(4).hex()}.png")
|
| 28 |
-
|
| 29 |
-
lineart.save(lineart_path, "PNG")
|
| 30 |
-
if cutout:
|
| 31 |
-
cutout.save(cutout_path, "PNG")
|
| 32 |
-
return lineart_path, cutout_path
|
| 33 |
-
else:
|
| 34 |
-
return lineart_path, None
|
| 35 |
except Exception as e:
|
| 36 |
print(f"[ERRO] process_faceless: {e}")
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
input_image.save(orig_path, "PNG")
|
| 40 |
-
return orig_path, None
|
| 41 |
-
|
| 42 |
|
| 43 |
# Interface Gradio
|
| 44 |
demo = gr.Interface(
|
|
@@ -49,13 +36,12 @@ demo = gr.Interface(
|
|
| 49 |
gr.Textbox(label="Prompt Negativo (Opcional)", value="")
|
| 50 |
],
|
| 51 |
outputs=[
|
| 52 |
-
gr.Image(label="Lineart Final (Transparente)"
|
| 53 |
-
gr.Image(label="Recorte do Rosto (Sem Fundo)"
|
| 54 |
],
|
| 55 |
title="Faceless Embroidery Studio Generator",
|
| 56 |
description="Gera contornos e linearts minimalistas (Faceless) para bordados a partir de retratos.\n\n**Nota:** O rosto é completamente apagado e apenas a silhueta externa é desenhada."
|
| 57 |
)
|
| 58 |
|
| 59 |
-
|
| 60 |
if __name__ == "__main__":
|
| 61 |
demo.launch()
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
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 build_faceless_embroidery_assets
|
| 9 |
|
| 10 |
@spaces.GPU
|
| 11 |
def process_faceless(input_image, prompt="", negative_prompt=""):
|
| 12 |
if input_image is None:
|
| 13 |
return None, None
|
| 14 |
|
| 15 |
+
# NÃO REDIMENSIONAMOS A IMAGEM – a função interna ( embroidery_processing.py) já lida com tamanhos variados.
|
| 16 |
# Gera lineart e cutout usando a função otimizada
|
| 17 |
try:
|
| 18 |
+
lineart, cutout = build_faceless_embroidery_assets(
|
| 19 |
+
input_image,
|
| 20 |
+
use_huggingface=False, # Desativa Hugging Face (pode ativar se tiver token)
|
| 21 |
+
prompt=prompt or None,
|
| 22 |
+
negative_prompt=negative_prompt or None,
|
| 23 |
)
|
| 24 |
+
return lineart, cutout
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
except Exception as e:
|
| 26 |
print(f"[ERRO] process_faceless: {e}")
|
| 27 |
+
# Fallback: retorna a imagem original e uma mensagem de erro
|
| 28 |
+
return input_image, None
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# Interface Gradio
|
| 31 |
demo = gr.Interface(
|
|
|
|
| 36 |
gr.Textbox(label="Prompt Negativo (Opcional)", value="")
|
| 37 |
],
|
| 38 |
outputs=[
|
| 39 |
+
gr.Image(label="Lineart Final (Transparente)"),
|
| 40 |
+
gr.Image(label="Recorte do Rosto (Sem Fundo)")
|
| 41 |
],
|
| 42 |
title="Faceless Embroidery Studio Generator",
|
| 43 |
description="Gera contornos e linearts minimalistas (Faceless) para bordados a partir de retratos.\n\n**Nota:** O rosto é completamente apagado e apenas a silhueta externa é desenhada."
|
| 44 |
)
|
| 45 |
|
|
|
|
| 46 |
if __name__ == "__main__":
|
| 47 |
demo.launch()
|