Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files2 unmodified lines345678910111213141516171819202122232425262728293031323334353637383940414243444 unmodified lines495051525354555657585960612 unmodified linesfrom PIL import Imageimport ioimport osimport tempfile# Importa a função melhorada do seu módulo (que já está ajustado)from faceless_processing import build_faceless_embroidery_assets, LineartConfig@spaces.GPUdef process_faceless(input_image, prompt="", negative_prompt=""):if input_image is None:return None, None# NÃO REDIMENSIONAMOS A IMAGEM – a função interna já lida com tamanhos variados.# Gera lineart e cutout usando a função otimizadatry:cfg = LineartConfig(prompt=prompt or "technical line art, clean vector, simple continuous lines, white background",negative_prompt=negative_prompt or "shading, realism, messy lines, noisy, double lines, background clutter")lineart, cutout = build_faceless_embroidery_assets(input_image, cfg)# Save to temp files to preserve RGBA transparency channelslineart_path = os.path.join(tempfile.gettempdir(), f"lineart_{os.getpid()}_{os.urandom(4).hex()}.png")cutout_path = os.path.join(tempfile.gettempdir(), f"cutout_{os.getpid()}_{os.urandom(4).hex()}.png")lineart.save(lineart_path, "PNG")if cutout:cutout.save(cutout_path, "PNG")return lineart_path, cutout_pathelse:return lineart_path, Noneexcept Exception as e:print(f"[ERRO] process_faceless: {e}")# Save original to temp file to be safeorig_path = os.path.join(tempfile.gettempdir(), f"orig_{os.getpid()}_{os.urandom(4).hex()}.png")input_image.save(orig_path, "PNG")return orig_path, None# Interface Gradiodemo = gr.Interface(4 unmodified linesgr.Textbox(label="Prompt Negativo (Opcional)", value="")],outputs=[gr.Image(label="Lineart Final (Transparente)", image_mode="RGBA", format="png"),gr.Image(label="Recorte do Rosto (Sem Fundo)", image_mode="RGBA", format="png")],title="Faceless Embroidery Studio Generator",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.")if __name__ == "__main__":demo.launch()2 unmodified lines3456789101112131415161718192021222324252627282930314 unmodified lines3637383940414243444546472 unmodified linesfrom PIL import Imageimport ioimport os# Importa a função melhorada do seu módulo (que já está ajustado )from faceless_processing import build_faceless_embroidery_assets@spaces.GPUdef process_faceless(input_image, prompt="", negative_prompt=""):if input_image is None:return None, None# NÃO REDIMENSIONAMOS A IMAGEM – a função interna ( embroidery_processing.py) já lida com tamanhos variados.# Gera lineart e cutout usando a função otimizadatry:lineart, cutout = build_faceless_embroidery_assets(input_image,use_huggingface=False, # Desativa Hugging Face (pode ativar se tiver token)prompt=prompt or None,negative_prompt=negative_prompt or None,)return lineart, cutoutexcept Exception as e:print(f"[ERRO] process_faceless: {e}")# Fallback: retorna a imagem original e uma mensagem de erroreturn input_image, None# Interface Gradiodemo = gr.Interface(4 unmodified linesgr.Textbox(label="Prompt Negativo (Opcional)", value="")],outputs=[gr.Image(label="Lineart Final (Transparente)"),gr.Image(label="Recorte do Rosto (Sem Fundo)")],title="Faceless Embroidery Studio Generator",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.")if __name__ == "__main__":demo.launch()
app.py+13-27