|
|
|
|
|
import os |
|
|
import gradio as gr |
|
|
from utils.editor import run_pipeline |
|
|
from PIL import Image |
|
|
import io |
|
|
|
|
|
DESCRIPTION = """ |
|
|
# 👗 Fashion Editor — Stable Diffusion + ControlNet (OpenPose) |
|
|
Envie a foto da modelo e uma foto da peça (jaqueta, camiseta etc.). A ferramenta |
|
|
irá alinhar a peça, extrair a pose e usar Stable Diffusion + ControlNet para gerar |
|
|
a composição fotorrealista. |
|
|
""" |
|
|
|
|
|
examples = [ |
|
|
|
|
|
] |
|
|
|
|
|
def infer(model_image, garment_image, prompt_extra): |
|
|
if model_image is None or garment_image is None: |
|
|
return None, "Envie as duas imagens (modelo e peça)." |
|
|
|
|
|
try: |
|
|
result, info = run_pipeline(model_image, garment_image, prompt_extra) |
|
|
return result, f"OK — steps: {info.get('steps')}, guidance: {info.get('guidance_scale')}" |
|
|
except Exception as e: |
|
|
return None, f"Erro durante a geração: {str(e)}" |
|
|
|
|
|
with gr.Blocks(title="Fashion Editor (SD + ControlNet)") as demo: |
|
|
gr.Markdown(DESCRIPTION) |
|
|
with gr.Row(): |
|
|
with gr.Column(): |
|
|
model_input = gr.Image(label="Foto da Modelo", type="pil") |
|
|
garment_input = gr.Image(label="Foto da Peça (Roupa)", type="pil") |
|
|
prompt_extra = gr.Textbox(label="Prompt extra (opcional)", lines=2) |
|
|
run_button = gr.Button("Gerar Edição") |
|
|
status = gr.Textbox(label="Status / Informações", interactive=False) |
|
|
with gr.Column(): |
|
|
output = gr.Image(label="Resultado (Final)") |
|
|
|
|
|
run_button.click(fn=infer, inputs=[model_input, garment_input, prompt_extra], outputs=[output, status]) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |