Spaces:
Paused
Paused
Update app_vince.py
Browse files- app_vince.py +38 -47
app_vince.py
CHANGED
|
@@ -1,20 +1,41 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
-
VINCIE Service UI (Gradio) — in-process
|
| 4 |
|
| 5 |
-
-
|
| 6 |
-
- UI minimalista:
|
| 7 |
- Opções avançadas: steps, cfg_scale, aspect_ratio, resolution.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
"""
|
| 9 |
|
| 10 |
import os
|
| 11 |
-
import importlib
|
| 12 |
from pathlib import Path
|
| 13 |
from typing import List, Tuple, Optional
|
| 14 |
|
| 15 |
import gradio as gr
|
| 16 |
|
| 17 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def _debug_ls(paths: List[Path], depth: int = 2) -> None:
|
| 20 |
try:
|
|
@@ -45,46 +66,8 @@ def _debug_ls(paths: List[Path], depth: int = 2) -> None:
|
|
| 45 |
except Exception as e:
|
| 46 |
print(f"[debug-ls] falha geral: {e}")
|
| 47 |
|
| 48 |
-
# Garante repo e ckpt; evita ModuleNotFoundError: common
|
| 49 |
-
try:
|
| 50 |
-
from services.vincie import VincieService # usa o serviço CLI apenas para preparar o ambiente
|
| 51 |
-
print("[bootstrap] garantindo repositório e checkpoint...")
|
| 52 |
-
_svc = VincieService()
|
| 53 |
-
_svc.ensure_repo()
|
| 54 |
-
_svc.ensure_model()
|
| 55 |
-
os.environ["VINCIE_DIR"] = str(_svc.repo_dir)
|
| 56 |
-
print(f"[bootstrap] repo={_svc.repo_dir} ckpt={_svc.ckpt_dir}")
|
| 57 |
-
except Exception as e:
|
| 58 |
-
print(f"[bootstrap] falha no ensure_repo/ensure_model: {e}")
|
| 59 |
-
_debug_ls([Path("/app"), Path("/app/VINCIE"), Path("/app/VINCIE/ckpt"), Path("/data/.cache/huggingface/hub")], depth=2)
|
| 60 |
-
|
| 61 |
-
# Tenta importar o servidor in-process; fallback via importlib se 'common' ainda não estiver no path
|
| 62 |
-
try:
|
| 63 |
-
from services.vince_server import server # instancia singleton internamente
|
| 64 |
-
except Exception as e:
|
| 65 |
-
print(f"[import] primeira tentativa falhou: {e}")
|
| 66 |
-
try:
|
| 67 |
-
server = importlib.import_module("services.vince_server").server
|
| 68 |
-
print("[import] servidor importado via importlib com sucesso")
|
| 69 |
-
except Exception as ee:
|
| 70 |
-
print(f"[import] falha ao importar services.vince_server: {ee}")
|
| 71 |
-
_debug_ls([Path("/app/VINCIE")], depth=2)
|
| 72 |
-
raise
|
| 73 |
|
| 74 |
-
#
|
| 75 |
-
|
| 76 |
-
def _list_media(out_dir: Path, max_images: int = 24) -> Tuple[List[str], Optional[str]]:
|
| 77 |
-
img_globs = ("*.png", "*.jpg", "*.jpeg", "*.webp")
|
| 78 |
-
images: List[Path] = []
|
| 79 |
-
for pat in img_globs:
|
| 80 |
-
images += list(out_dir.rglob(pat))
|
| 81 |
-
images = sorted(images, key=lambda p: p.stat().st_mtime) if images else []
|
| 82 |
-
image_paths = [str(p) for p in images[-max_images:]] if images else []
|
| 83 |
-
videos = sorted(out_dir.rglob("*.mp4"), key=lambda p: p.stat().st_mtime)
|
| 84 |
-
video_path = str(videos[-1]) if videos else None
|
| 85 |
-
return image_paths, video_path
|
| 86 |
-
|
| 87 |
-
# ---------- Handlers ----------
|
| 88 |
|
| 89 |
def ui_multi_turn(
|
| 90 |
input_image: Optional[str],
|
|
@@ -183,7 +166,8 @@ def ui_multi_concept(
|
|
| 183 |
_debug_ls([out_path], depth=2)
|
| 184 |
return imgs, vid
|
| 185 |
|
| 186 |
-
|
|
|
|
| 187 |
|
| 188 |
with gr.Blocks(title="VINCIE Service (in-process)") as demo:
|
| 189 |
gr.Markdown(
|
|
@@ -196,7 +180,8 @@ with gr.Blocks(title="VINCIE Service (in-process)") as demo:
|
|
| 196 |
)
|
| 197 |
)
|
| 198 |
|
| 199 |
-
|
|
|
|
| 200 |
steps_input = gr.Slider(label="Passos de Inferência", minimum=10, maximum=100, step=1, value=50)
|
| 201 |
cfg_scale_input = gr.Slider(label="Escala de Orientação (CFG)", minimum=1.0, maximum=15.0, step=0.5, value=7.5)
|
| 202 |
aspect_ratio_input = gr.Dropdown(
|
|
@@ -206,6 +191,7 @@ with gr.Blocks(title="VINCIE Service (in-process)") as demo:
|
|
| 206 |
)
|
| 207 |
resolution_input = gr.Slider(label="Resolução (lado menor)", minimum=256, maximum=1024, step=64, value=512)
|
| 208 |
|
|
|
|
| 209 |
with gr.Tab("Multi-turn Editing"):
|
| 210 |
with gr.Row():
|
| 211 |
img = gr.Image(type="filepath", label="Imagem de entrada")
|
|
@@ -219,6 +205,7 @@ with gr.Blocks(title="VINCIE Service (in-process)") as demo:
|
|
| 219 |
outputs=[out_gallery, out_video],
|
| 220 |
)
|
| 221 |
|
|
|
|
| 222 |
with gr.Tab("Multi-concept Composition"):
|
| 223 |
files = gr.File(file_count="multiple", type="filepath", label="Imagens de conceito")
|
| 224 |
descs = gr.Textbox(lines=8, label="Descrições (uma por linha, mesma ordem das imagens)")
|
|
@@ -233,7 +220,11 @@ with gr.Blocks(title="VINCIE Service (in-process)") as demo:
|
|
| 233 |
)
|
| 234 |
|
| 235 |
if __name__ == "__main__":
|
| 236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
demo.launch(
|
| 238 |
server_name=os.getenv("GRADIO_SERVER_NAME", "0.0.0.0"),
|
| 239 |
server_port=int(os.getenv("GRADIO_SERVER_PORT", os.getenv("PORT", "7860"))),
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
+
VINCIE Service UI (Gradio) — in-process
|
| 4 |
|
| 5 |
+
- Importa diretamente o servidor in-process (vince_server).
|
| 6 |
+
- UI minimalista: galeria e vídeo por aba.
|
| 7 |
- Opções avançadas: steps, cfg_scale, aspect_ratio, resolution.
|
| 8 |
+
- Logs e 'ls' de diagnóstico apenas no terminal.
|
| 9 |
+
|
| 10 |
+
Pré-requisitos garantidos pelo start.sh:
|
| 11 |
+
- Repo VINCIE íntegro e no PYTHONPATH (VINCIE_DIR).
|
| 12 |
+
- Symlink ckpt/VINCIE-3B -> snapshot (contém dit.pth, vae.pth, llm14b).
|
| 13 |
+
- Apex/Flash e demais deps instaladas pelo builder.
|
| 14 |
"""
|
| 15 |
|
| 16 |
import os
|
|
|
|
| 17 |
from pathlib import Path
|
| 18 |
from typing import List, Tuple, Optional
|
| 19 |
|
| 20 |
import gradio as gr
|
| 21 |
|
| 22 |
+
# Servidor persistente (pipeline aquecida)
|
| 23 |
+
from services.vince_server import server
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# -------- util --------
|
| 27 |
+
|
| 28 |
+
def _list_media(out_dir: Path, max_images: int = 24) -> Tuple[List[str], Optional[str]]:
|
| 29 |
+
img_globs = ("*.png", "*.jpg", "*.jpeg", "*.webp")
|
| 30 |
+
images: List[Path] = []
|
| 31 |
+
for pat in img_globs:
|
| 32 |
+
images += list(out_dir.rglob(pat))
|
| 33 |
+
images = sorted(images, key=lambda p: p.stat().st_mtime) if images else []
|
| 34 |
+
image_paths = [str(p) for p in images[-max_images:]] if images else []
|
| 35 |
+
videos = sorted(out_dir.rglob("*.mp4"), key=lambda p: p.stat().st_mtime)
|
| 36 |
+
video_path = str(videos[-1]) if videos else None
|
| 37 |
+
return image_paths, video_path
|
| 38 |
+
|
| 39 |
|
| 40 |
def _debug_ls(paths: List[Path], depth: int = 2) -> None:
|
| 41 |
try:
|
|
|
|
| 66 |
except Exception as e:
|
| 67 |
print(f"[debug-ls] falha geral: {e}")
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
# -------- UI handlers --------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
def ui_multi_turn(
|
| 73 |
input_image: Optional[str],
|
|
|
|
| 166 |
_debug_ls([out_path], depth=2)
|
| 167 |
return imgs, vid
|
| 168 |
|
| 169 |
+
|
| 170 |
+
# -------- UI --------
|
| 171 |
|
| 172 |
with gr.Blocks(title="VINCIE Service (in-process)") as demo:
|
| 173 |
gr.Markdown(
|
|
|
|
| 180 |
)
|
| 181 |
)
|
| 182 |
|
| 183 |
+
# Opções avançadas (compartilhadas entre abas)
|
| 184 |
+
with gr.Accordion("Opções Avançadas", open=False):
|
| 185 |
steps_input = gr.Slider(label="Passos de Inferência", minimum=10, maximum=100, step=1, value=50)
|
| 186 |
cfg_scale_input = gr.Slider(label="Escala de Orientação (CFG)", minimum=1.0, maximum=15.0, step=0.5, value=7.5)
|
| 187 |
aspect_ratio_input = gr.Dropdown(
|
|
|
|
| 191 |
)
|
| 192 |
resolution_input = gr.Slider(label="Resolução (lado menor)", minimum=256, maximum=1024, step=64, value=512)
|
| 193 |
|
| 194 |
+
# Aba 1 — Multi-turn Editing
|
| 195 |
with gr.Tab("Multi-turn Editing"):
|
| 196 |
with gr.Row():
|
| 197 |
img = gr.Image(type="filepath", label="Imagem de entrada")
|
|
|
|
| 205 |
outputs=[out_gallery, out_video],
|
| 206 |
)
|
| 207 |
|
| 208 |
+
# Aba 2 — Multi-concept Composition
|
| 209 |
with gr.Tab("Multi-concept Composition"):
|
| 210 |
files = gr.File(file_count="multiple", type="filepath", label="Imagens de conceito")
|
| 211 |
descs = gr.Textbox(lines=8, label="Descrições (uma por linha, mesma ordem das imagens)")
|
|
|
|
| 220 |
)
|
| 221 |
|
| 222 |
if __name__ == "__main__":
|
| 223 |
+
if os.getenv("GRADIO_ENABLE_QUEUE", "True").lower() == "true" and hasattr(demo, "queue"):
|
| 224 |
+
demo.queue(
|
| 225 |
+
concurrency_count=int(os.getenv("GRADIO_QUEUE_CONCURRENCY", "2")),
|
| 226 |
+
max_size=int(os.getenv("GRADIO_QUEUE_MAX", "32")),
|
| 227 |
+
)
|
| 228 |
demo.launch(
|
| 229 |
server_name=os.getenv("GRADIO_SERVER_NAME", "0.0.0.0"),
|
| 230 |
server_port=int(os.getenv("GRADIO_SERVER_PORT", os.getenv("PORT", "7860"))),
|