euIaxs22 commited on
Commit
b5aeef7
·
verified ·
1 Parent(s): 43a9022

Update app_vince.py

Browse files
Files changed (1) hide show
  1. app_vince.py +13 -63
app_vince.py CHANGED
@@ -5,12 +5,6 @@ VINCIE Service UI (Gradio) — in-process
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
@@ -20,11 +14,10 @@ from typing import List, Tuple, Optional
20
  import gradio as gr
21
 
22
  # Servidor persistente (pipeline aquecida)
23
- from services.vince_server import VinceServer as 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] = []
@@ -36,39 +29,7 @@ def _list_media(out_dir: Path, max_images: int = 24) -> Tuple[List[str], Optiona
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:
42
- for base in paths:
43
- try:
44
- p = Path(base)
45
- print(f"[debug-ls] >>> {p}")
46
- if p.is_dir():
47
- entries = sorted(p.iterdir(), key=lambda x: x.name.lower())
48
- for e in entries:
49
- print(f" - {e.name}{'/' if e.is_dir() else ''}")
50
- if depth > 1:
51
- for e in entries:
52
- if e.is_dir():
53
- try:
54
- sub = sorted(e.iterdir(), key=lambda x: x.name.lower())
55
- print(f" [{e.name}/]")
56
- for s in sub:
57
- print(f" - {s.name}{'/' if s.is_dir() else ''}")
58
- except Exception as se:
59
- print(f" (erro listando {e}): {se}")
60
- elif p.exists():
61
- print(f" - arquivo: {p.name}")
62
- else:
63
- print(" - (inexistente)")
64
- except Exception as ie:
65
- print(f"[debug-ls] erro listando {base}: {ie}")
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],
74
  turns_text: Optional[str],
@@ -79,40 +40,36 @@ def ui_multi_turn(
79
  ):
80
  if not input_image or not str(input_image).strip():
81
  print("[multi_turn] input_image ausente")
82
- _debug_ls([Path("/app"), Path("/data")], depth=1)
83
  return [], None
84
  if not turns_text or not turns_text.strip():
85
  print("[multi_turn] turns ausentes")
86
  return [], None
87
 
88
  turns = [ln.strip() for ln in turns_text.splitlines() if ln.strip()]
 
89
  try:
90
  out_dir = server.generate_multi_turn(
91
- image_path=input_image,
92
  turns=turns,
93
  cfg_scale=float(cfg_scale_input) if cfg_scale_input is not None else None,
94
- aspect_ratio_input=str(aspect_ratio_input) if aspect_ratio_input else None,
95
- resolution_input=int(resolution_input) if resolution_input is not None else None,
96
  steps=int(steps_input) if steps_input is not None else None,
97
  )
98
  except Exception as e:
99
- print(f"[multi_turn] erro na geração: {e}")
100
- _debug_ls([Path("/app/outputs"), Path("/app/VINCIE"), Path("/data")], depth=2)
101
  return [], None
102
 
103
  out_path = Path(out_dir)
104
  if not out_path.exists():
105
  print(f"[multi_turn] saída inexistente: {out_path}")
106
- _debug_ls([out_path.parent, Path("/app/outputs")], depth=2)
107
  return [], None
108
 
109
  imgs, vid = _list_media(out_path)
110
  if not imgs and not vid:
111
  print(f"[multi_turn] sem mídias em {out_path}")
112
- _debug_ls([out_path], depth=2)
113
  return imgs, vid
114
 
115
-
116
  def ui_multi_concept(
117
  files: Optional[List[str]],
118
  descs_text: Optional[str],
@@ -124,7 +81,6 @@ def ui_multi_concept(
124
  ):
125
  if not files:
126
  print("[multi_concept] files ausentes")
127
- _debug_ls([Path("/data"), Path("/app")], depth=1)
128
  return [], None
129
  if not descs_text or not descs_text.strip():
130
  print("[multi_concept] descs ausentes")
@@ -136,7 +92,6 @@ def ui_multi_concept(
136
  descs = [ln.strip() for ln in descs_text.splitlines() if ln.strip()]
137
  if len(descs) != len(files):
138
  print(f"[multi_concept] mismatch descs({len(descs)}) vs files({len(files)})")
139
- _debug_ls([Path("/data")], depth=1)
140
  return [], None
141
 
142
  try:
@@ -145,37 +100,33 @@ def ui_multi_concept(
145
  concept_prompts=descs,
146
  final_prompt=final_prompt,
147
  cfg_scale=float(cfg_scale_input) if cfg_scale_input is not None else None,
148
- aspect_ratio_input=str(aspect_ratio_input) if aspect_ratio_input else None,
149
- resolution_input=int(resolution_input) if resolution_input is not None else None,
150
  steps=int(steps_input) if steps_input is not None else None,
 
151
  )
152
  except Exception as e:
153
- print(f"[multi_concept] erro na geração: {e}")
154
- _debug_ls([Path("/app/outputs"), Path("/app/VINCIE"), Path("/data")], depth=2)
155
  return [], None
156
 
157
  out_path = Path(out_dir)
158
  if not out_path.exists():
159
  print(f"[multi_concept] saída inexistente: {out_path}")
160
- _debug_ls([out_path.parent, Path("/app/outputs")], depth=2)
161
  return [], None
162
 
163
  imgs, vid = _list_media(out_path)
164
  if not imgs and not vid:
165
  print(f"[multi_concept] sem mídias em {out_path}")
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(
174
  "\n".join(
175
  [
176
  "# VINCIE — Edição Multi-Turn e Composição Multi-Concept (in-process)",
177
- "- Pipeline carregada uma única vez; pesos permanecem em VRAM entre requisições.",
178
- "- UI exibe apenas imagens e vídeo; logs no terminal.",
179
  ]
180
  )
181
  )
@@ -220,7 +171,6 @@ with gr.Blocks(title="VINCIE Service (in-process)") as demo:
220
  )
221
 
222
  if __name__ == "__main__":
223
-
224
  demo.launch(
225
  server_name=os.getenv("GRADIO_SERVER_NAME", "0.0.0.0"),
226
  server_port=int(os.getenv("GRADIO_SERVER_PORT", os.getenv("PORT", "7860"))),
 
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
  """
9
 
10
  import os
 
14
  import gradio as gr
15
 
16
  # Servidor persistente (pipeline aquecida)
17
+ # Se o vince_server.py estiver no mesmo diretório deste app, use:
18
+ from vince_server import VinceServer as server # [ajuste de import para o novo servidor]
19
 
20
  # -------- util --------
 
21
  def _list_media(out_dir: Path, max_images: int = 24) -> Tuple[List[str], Optional[str]]:
22
  img_globs = ("*.png", "*.jpg", "*.jpeg", "*.webp")
23
  images: List[Path] = []
 
29
  video_path = str(videos[-1]) if videos else None
30
  return image_paths, video_path
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  # -------- UI handlers --------
 
33
  def ui_multi_turn(
34
  input_image: Optional[str],
35
  turns_text: Optional[str],
 
40
  ):
41
  if not input_image or not str(input_image).strip():
42
  print("[multi_turn] input_image ausente")
 
43
  return [], None
44
  if not turns_text or not turns_text.strip():
45
  print("[multi_turn] turns ausentes")
46
  return [], None
47
 
48
  turns = [ln.strip() for ln in turns_text.splitlines() if ln.strip()]
49
+
50
  try:
51
  out_dir = server.generate_multi_turn(
52
+ input_image=input_image,
53
  turns=turns,
54
  cfg_scale=float(cfg_scale_input) if cfg_scale_input is not None else None,
55
+ aspect_ratio=str(aspect_ratio_input) if aspect_ratio_input else None,
56
+ resolution=int(resolution_input) if resolution_input is not None else None,
57
  steps=int(steps_input) if steps_input is not None else None,
58
  )
59
  except Exception as e:
60
+ print(f"[multi_turn] erro: {e}")
 
61
  return [], None
62
 
63
  out_path = Path(out_dir)
64
  if not out_path.exists():
65
  print(f"[multi_turn] saída inexistente: {out_path}")
 
66
  return [], None
67
 
68
  imgs, vid = _list_media(out_path)
69
  if not imgs and not vid:
70
  print(f"[multi_turn] sem mídias em {out_path}")
 
71
  return imgs, vid
72
 
 
73
  def ui_multi_concept(
74
  files: Optional[List[str]],
75
  descs_text: Optional[str],
 
81
  ):
82
  if not files:
83
  print("[multi_concept] files ausentes")
 
84
  return [], None
85
  if not descs_text or not descs_text.strip():
86
  print("[multi_concept] descs ausentes")
 
92
  descs = [ln.strip() for ln in descs_text.splitlines() if ln.strip()]
93
  if len(descs) != len(files):
94
  print(f"[multi_concept] mismatch descs({len(descs)}) vs files({len(files)})")
 
95
  return [], None
96
 
97
  try:
 
100
  concept_prompts=descs,
101
  final_prompt=final_prompt,
102
  cfg_scale=float(cfg_scale_input) if cfg_scale_input is not None else None,
103
+ aspect_ratio=str(aspect_ratio_input) if aspect_ratio_input else None,
104
+ resolution=int(resolution_input) if resolution_input is not None else None,
105
  steps=int(steps_input) if steps_input is not None else None,
106
+ pad_placeholder=False,
107
  )
108
  except Exception as e:
109
+ print(f"[multi_concept] erro: {e}")
 
110
  return [], None
111
 
112
  out_path = Path(out_dir)
113
  if not out_path.exists():
114
  print(f"[multi_concept] saída inexistente: {out_path}")
 
115
  return [], None
116
 
117
  imgs, vid = _list_media(out_path)
118
  if not imgs and not vid:
119
  print(f"[multi_concept] sem mídias em {out_path}")
 
120
  return imgs, vid
121
 
 
122
  # -------- UI --------
 
123
  with gr.Blocks(title="VINCIE Service (in-process)") as demo:
124
  gr.Markdown(
125
  "\n".join(
126
  [
127
  "# VINCIE — Edição Multi-Turn e Composição Multi-Concept (in-process)",
128
+ "- Pipeline é carregada uma única vez; pesos permanecem em VRAM.",
129
+ "- UI exibe imagens e vídeo; logs no terminal.",
130
  ]
131
  )
132
  )
 
171
  )
172
 
173
  if __name__ == "__main__":
 
174
  demo.launch(
175
  server_name=os.getenv("GRADIO_SERVER_NAME", "0.0.0.0"),
176
  server_port=int(os.getenv("GRADIO_SERVER_PORT", os.getenv("PORT", "7860"))),