Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,4 @@
|
|
| 1 |
# app.py
|
| 2 |
-
|
| 3 |
-
# --- 🚨 CORREÇÃO DE EMERGÊNCIA: Garantir websockets >= 11.0.3 ANTES de importar qualquer coisa ---
|
| 4 |
-
import subprocess
|
| 5 |
-
import sys
|
| 6 |
-
|
| 7 |
-
def install_package(package):
|
| 8 |
-
subprocess.check_call([sys.executable, "-m", "pip", "install", "--no-cache-dir", package])
|
| 9 |
-
|
| 10 |
-
try:
|
| 11 |
-
import websockets
|
| 12 |
-
# Verifica se o submódulo 'asyncio' existe (presente só a partir da v11+)
|
| 13 |
-
if not hasattr(websockets, 'asyncio'):
|
| 14 |
-
raise ImportError("Versão antiga do websockets detectada. Atualizando...")
|
| 15 |
-
except (ImportError, AttributeError):
|
| 16 |
-
print("📦 Instalando websockets>=11.0.3...")
|
| 17 |
-
install_package("websockets>=11.0.3")
|
| 18 |
-
# Recarrega o módulo após instalação
|
| 19 |
-
import importlib
|
| 20 |
-
import websockets
|
| 21 |
-
importlib.reload(websockets)
|
| 22 |
-
print("✅ websockets atualizado com sucesso!")
|
| 23 |
-
# --- ✅ FIM DA CORREÇÃO ---
|
| 24 |
-
|
| 25 |
-
# Agora sim, importe o resto
|
| 26 |
import os
|
| 27 |
import gradio as gr
|
| 28 |
from utils.editor import run_pipeline
|
|
@@ -41,15 +17,9 @@ examples = [
|
|
| 41 |
]
|
| 42 |
|
| 43 |
def infer(model_image, garment_image, prompt_extra):
|
| 44 |
-
"""
|
| 45 |
-
model_image: PIL.Image or numpy
|
| 46 |
-
garment_image: PIL.Image or numpy
|
| 47 |
-
prompt_extra: str - description tweaks
|
| 48 |
-
"""
|
| 49 |
if model_image is None or garment_image is None:
|
| 50 |
return None, "Envie as duas imagens (modelo e peça)."
|
| 51 |
|
| 52 |
-
# run_pipeline retorna (pil_image_result, debug_info_dict)
|
| 53 |
try:
|
| 54 |
result, info = run_pipeline(model_image, garment_image, prompt_extra)
|
| 55 |
return result, f"OK — steps: {info.get('steps')}, guidance: {info.get('guidance_scale')}"
|
|
@@ -62,7 +32,7 @@ with gr.Blocks(title="Fashion Editor (SD + ControlNet)") as demo:
|
|
| 62 |
with gr.Column():
|
| 63 |
model_input = gr.Image(label="Foto da Modelo", type="pil")
|
| 64 |
garment_input = gr.Image(label="Foto da Peça (Roupa)", type="pil")
|
| 65 |
-
prompt_extra = gr.Textbox(label="Prompt extra (opcional)
|
| 66 |
run_button = gr.Button("Gerar Edição")
|
| 67 |
status = gr.Textbox(label="Status / Informações", interactive=False)
|
| 68 |
with gr.Column():
|
|
|
|
| 1 |
# app.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
from utils.editor import run_pipeline
|
|
|
|
| 17 |
]
|
| 18 |
|
| 19 |
def infer(model_image, garment_image, prompt_extra):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
if model_image is None or garment_image is None:
|
| 21 |
return None, "Envie as duas imagens (modelo e peça)."
|
| 22 |
|
|
|
|
| 23 |
try:
|
| 24 |
result, info = run_pipeline(model_image, garment_image, prompt_extra)
|
| 25 |
return result, f"OK — steps: {info.get('steps')}, guidance: {info.get('guidance_scale')}"
|
|
|
|
| 32 |
with gr.Column():
|
| 33 |
model_input = gr.Image(label="Foto da Modelo", type="pil")
|
| 34 |
garment_input = gr.Image(label="Foto da Peça (Roupa)", type="pil")
|
| 35 |
+
prompt_extra = gr.Textbox(label="Prompt extra (opcional)", lines=2)
|
| 36 |
run_button = gr.Button("Gerar Edição")
|
| 37 |
status = gr.Textbox(label="Status / Informações", interactive=False)
|
| 38 |
with gr.Column():
|