xplhack1 commited on
Commit
294eb7e
·
verified ·
1 Parent(s): 4888228

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -39
app.py CHANGED
@@ -1,69 +1,96 @@
1
  import gradio as gr
2
  import os
3
  import subprocess
4
- from huggingface_hub import HfApi, hf_hub_download
5
  import spaces
6
 
7
  api = HfApi()
8
 
9
  @spaces.GPU
10
- def process_video(token, source_dataset, target_dataset, file_path):
11
- if not token or not source_dataset or not target_dataset or not file_path:
12
  return "❌ Error: Faltan datos obligatorios."
13
 
14
  try:
15
- # Limpiamos posibles espacios o puntos accidentales en la ruta
16
- file_path = file_path.strip().rstrip('.')
17
 
18
- # 1. Descargar el archivo original desde el dataset origen
19
- local_path = hf_hub_download(
20
- repo_id=source_dataset,
21
- filename=file_path,
22
- repo_type="dataset",
23
- token=token
24
- )
25
 
26
- # 2. Procesar con FFmpeg (Remux y Faststart)
27
- output_path = "video_arreglado.mp4"
28
- command = [
29
- "ffmpeg", "-y", "-i", local_path,
30
- "-c", "copy", "-movflags", "+faststart", output_path
31
  ]
32
- subprocess.run(command, check=True)
33
 
34
- # 3. Subir el archivo ya reparado al dataset destino (clean)
35
- api.upload_file(
36
- path_or_fileobj=output_path,
37
- path_in_repo=file_path,
38
- repo_id=target_dataset,
39
- repo_type="dataset",
40
- token=token
41
- )
42
 
43
- # Limpieza del disco temporal
44
- os.remove(output_path)
 
 
 
45
 
46
- return f"✅ ¡Listo bro! Copiado de '{source_dataset}', reparado y guardado limpio en '{target_dataset}' ({file_path})"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
  except Exception as e:
49
- return f"❌ Algo falló: {str(e)}"
50
 
51
- # Interfaz gráfica adaptada para origen y destino
52
  with gr.Blocks() as demo:
53
- gr.Markdown("# 🛠️ Migrador y Reparador v3 de MP4")
54
- gr.Markdown("Descarga el video malo del dataset viejo, lo repara y lo sube limpio al dataset nuevo sin tocar tu VPS.")
55
 
56
  token_input = gr.Textbox(label="Tu HF_TOKEN (Con permisos de WRITE)", type="password")
57
 
58
  with gr.Row():
59
- source_input = gr.Textbox(label="Dataset ORIGEN (De dónde lo descarga)", value="xplhack1/bylatamsrc2")
60
- target_input = gr.Textbox(label="Dataset DESTINO (A dónde lo sube limpio)", value="xplhack1/bylatamsrc2-clean")
61
 
62
- filepath_input = gr.Textbox(label="Ruta exacta del archivo", value="SERIES/EN_EMISION/Rivales_2024/TEMPORADA1/Rivales_S01E08_Episodio_8.mp4")
 
 
 
63
 
64
- btn = gr.Button("Migrar y Reparar 🔥", variant="primary")
65
- output = gr.Textbox(label="Estado del proceso")
66
 
67
- btn.click(fn=process_video, inputs=[token_input, source_input, target_input, filepath_input], outputs=output)
68
 
69
  demo.launch(theme=gr.themes.Soft())
 
1
  import gradio as gr
2
  import os
3
  import subprocess
4
+ from huggingface_hub import HfApi, hf_hub_download, list_repo_files
5
  import spaces
6
 
7
  api = HfApi()
8
 
9
  @spaces.GPU
10
+ def process_batch_videos(token, source_dataset, target_dataset, folder_path):
11
+ if not token or not source_dataset or not target_dataset or not folder_path:
12
  return "❌ Error: Faltan datos obligatorios."
13
 
14
  try:
15
+ folder_path = folder_path.strip().rstrip('/')
 
16
 
17
+ # 1. Listar todos los archivos del repo origen
18
+ all_files = list_repo_files(repo_id=source_dataset, repo_type="dataset", token=token)
 
 
 
 
 
19
 
20
+ # Filtrar los archivos mp4 dentro de la carpeta especificada
21
+ mp4_files = [
22
+ f for f in all_files
23
+ if f.startswith(folder_path) and f.endswith('.mp4')
 
24
  ]
 
25
 
26
+ # Ordenar para consistencia y tomar estrictamente los primeros 3
27
+ mp4_files = sorted(mp4_files)[:3]
 
 
 
 
 
 
28
 
29
+ if not mp4_files:
30
+ return f"⚠️ No se encontraron archivos .mp4 en la ruta: {folder_path}"
31
+
32
+ results = []
33
+ results.append(f"📁 Encontrados {len(mp4_files)} archivos para procesar (Modo WIP - Primeros 3):")
34
 
35
+ for idx, file_path in enumerate(mp4_files, 1):
36
+ results.append(f"\n--- Procesando [{idx}/3]: {file_path} ---")
37
+
38
+ # Descargar archivo original
39
+ local_path = hf_hub_download(
40
+ repo_id=source_dataset,
41
+ filename=file_path,
42
+ repo_type="dataset",
43
+ token=token
44
+ )
45
+
46
+ # Procesar con FFmpeg (Remux y Faststart)
47
+ output_path = f"video_arreglado_{idx}.mp4"
48
+ command = [
49
+ "ffmpeg", "-y", "-i", local_path,
50
+ "-c", "copy", "-movflags", "+faststart", output_path
51
+ ]
52
+ subprocess.run(command, check=True)
53
+
54
+ # Subir al dataset destino limpio
55
+ api.upload_file(
56
+ path_or_fileobj=output_path,
57
+ path_in_repo=file_path,
58
+ repo_id=target_dataset,
59
+ repo_type="dataset",
60
+ token=token
61
+ )
62
+
63
+ # Limpieza local
64
+ if os.path.exists(output_path):
65
+ os.remove(output_path)
66
+
67
+ results.append(f"✅ ¡Reparado y subido con éxito a {target_dataset}!")
68
+
69
+ results.append("\n🎉 ¡Lote de prueba de los primeros 3 completado exitosamente!")
70
+ return "\n".join(results)
71
 
72
  except Exception as e:
73
+ return f"❌ Algo falló en el proceso por lotes: {str(e)}"
74
 
75
+ # Interfaz gráfica adaptada para procesamiento por lotes (WIP)
76
  with gr.Blocks() as demo:
77
+ gr.Markdown("# 🛠️ Migrador y Reparador Masivo (Modo WIP - Primeros 3)")
78
+ gr.Markdown("Escanea la carpeta, verifica y repara únicamente los primeros 3 archivos MP4 encontrados.")
79
 
80
  token_input = gr.Textbox(label="Tu HF_TOKEN (Con permisos de WRITE)", type="password")
81
 
82
  with gr.Row():
83
+ source_input = gr.Textbox(label="Dataset ORIGEN", value="xplhack1/bylatamsrc2")
84
+ target_input = gr.Textbox(label="Dataset DESTINO", value="orglatamsrc/latamsrcfixed")
85
 
86
+ folder_input = gr.Textbox(
87
+ label="Carpeta a escanear",
88
+ value="SERIES/EN_EMISION/Rivales_2024/TEMPORADA1"
89
+ )
90
 
91
+ btn = gr.Button("Verificar y Reparar Primeros 3 🚀", variant="primary")
92
+ output = gr.Textbox(label="Estado del proceso / Log", lines=15)
93
 
94
+ btn.click(fn=process_batch_videos, inputs=[token_input, source_input, target_input, folder_input], outputs=output)
95
 
96
  demo.launch(theme=gr.themes.Soft())