Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -61,17 +61,15 @@ def procesar_video(video):
|
|
61 |
collage_path = os.path.join(temp_dir, "collage.jpg")
|
62 |
collage.save(collage_path)
|
63 |
|
64 |
-
# Generación del ZIP
|
65 |
base_name = os.path.splitext(original_name)[0]
|
66 |
zip_filename = f"{base_name}.zip"
|
67 |
final_zip_path = os.path.join(temp_dir, zip_filename)
|
68 |
|
69 |
with zipfile.ZipFile(final_zip_path, mode="w") as zipf:
|
70 |
-
# Añadir frames
|
71 |
for img_path in frame_paths:
|
72 |
zipf.write(img_path, os.path.basename(img_path))
|
73 |
|
74 |
-
# Cadena de custodia con formato mejorado
|
75 |
with open(video_path, "rb") as f:
|
76 |
video_hash = hashlib.md5(f.read()).hexdigest()
|
77 |
|
@@ -82,7 +80,7 @@ def procesar_video(video):
|
|
82 |
f"• Fotogramas extraídos: {frame_count}\r\n"
|
83 |
f"• Hash MD5 del video original: {video_hash}\r\n\r\n"
|
84 |
"Firmado digitalmente por:\n"
|
85 |
-
"Sistema de Extracción Forense -
|
86 |
)
|
87 |
zipf.writestr("cadena_custodia.txt", chain_content)
|
88 |
|
@@ -91,24 +89,54 @@ def procesar_video(video):
|
|
91 |
except Exception as e:
|
92 |
raise gr.Error(f"Error al procesar el video: {str(e)}")
|
93 |
|
94 |
-
|
|
|
|
|
|
|
|
|
95 |
|
96 |
with gr.Blocks(title="Extracción de Fotogramas Forenses") as demo:
|
97 |
-
gr.Markdown("# Herramienta de Extracción de Fotogramas Forenses")
|
98 |
gr.Markdown("**Carga un video para extraer TODOS los fotogramas y generar un collage de muestra.**")
|
99 |
gr.Markdown("Desarrollado por José R. Leonett para el Grupo de Peritos Forenses Digitales de Guatemala - [www.forensedigital.gt](https://www.forensedigital.gt)")
|
100 |
|
101 |
with gr.Row():
|
102 |
with gr.Column():
|
103 |
-
# Video input sin webcam
|
104 |
video_input = gr.Video(
|
105 |
label="Subir Video",
|
106 |
interactive=True,
|
107 |
-
sources=["upload"]
|
|
|
108 |
)
|
109 |
procesar_btn = gr.Button("Procesar Fotogramas", interactive=False)
|
110 |
with gr.Column():
|
111 |
gallery_output = gr.Image(label="Collage de Muestra")
|
112 |
download_file = gr.File(label="Archivo ZIP generado", visible=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
-
|
|
|
|
61 |
collage_path = os.path.join(temp_dir, "collage.jpg")
|
62 |
collage.save(collage_path)
|
63 |
|
64 |
+
# Generación del ZIP
|
65 |
base_name = os.path.splitext(original_name)[0]
|
66 |
zip_filename = f"{base_name}.zip"
|
67 |
final_zip_path = os.path.join(temp_dir, zip_filename)
|
68 |
|
69 |
with zipfile.ZipFile(final_zip_path, mode="w") as zipf:
|
|
|
70 |
for img_path in frame_paths:
|
71 |
zipf.write(img_path, os.path.basename(img_path))
|
72 |
|
|
|
73 |
with open(video_path, "rb") as f:
|
74 |
video_hash = hashlib.md5(f.read()).hexdigest()
|
75 |
|
|
|
80 |
f"• Fotogramas extraídos: {frame_count}\r\n"
|
81 |
f"• Hash MD5 del video original: {video_hash}\r\n\r\n"
|
82 |
"Firmado digitalmente por:\n"
|
83 |
+
"Sistema de Extracción Forense - GPFD Guatemala"
|
84 |
)
|
85 |
zipf.writestr("cadena_custodia.txt", chain_content)
|
86 |
|
|
|
89 |
except Exception as e:
|
90 |
raise gr.Error(f"Error al procesar el video: {str(e)}")
|
91 |
|
92 |
+
def limpiar_cache(temp_dir):
|
93 |
+
if temp_dir and os.path.exists(temp_dir):
|
94 |
+
for file in os.listdir(temp_dir):
|
95 |
+
os.remove(os.path.join(temp_dir, file))
|
96 |
+
os.rmdir(temp_dir)
|
97 |
|
98 |
with gr.Blocks(title="Extracción de Fotogramas Forenses") as demo:
|
99 |
+
gr.Markdown("# 📷 Herramienta de Extracción de Fotogramas Forenses")
|
100 |
gr.Markdown("**Carga un video para extraer TODOS los fotogramas y generar un collage de muestra.**")
|
101 |
gr.Markdown("Desarrollado por José R. Leonett para el Grupo de Peritos Forenses Digitales de Guatemala - [www.forensedigital.gt](https://www.forensedigital.gt)")
|
102 |
|
103 |
with gr.Row():
|
104 |
with gr.Column():
|
|
|
105 |
video_input = gr.Video(
|
106 |
label="Subir Video",
|
107 |
interactive=True,
|
108 |
+
sources=["upload"],
|
109 |
+
format="mp4"
|
110 |
)
|
111 |
procesar_btn = gr.Button("Procesar Fotogramas", interactive=False)
|
112 |
with gr.Column():
|
113 |
gallery_output = gr.Image(label="Collage de Muestra")
|
114 |
download_file = gr.File(label="Archivo ZIP generado", visible=True)
|
115 |
+
|
116 |
+
temp_dir_state = gr.State()
|
117 |
+
zip_path_state = gr.State()
|
118 |
+
|
119 |
+
def on_video_change(video):
|
120 |
+
return gr.update(interactive=bool(video))
|
121 |
+
|
122 |
+
video_input.change(
|
123 |
+
fn=on_video_change,
|
124 |
+
inputs=video_input,
|
125 |
+
outputs=procesar_btn,
|
126 |
+
queue=False
|
127 |
+
)
|
128 |
+
|
129 |
+
def procesar_y_mostrar(video):
|
130 |
+
if temp_dir_state.value:
|
131 |
+
limpiar_cache(temp_dir_state.value)
|
132 |
+
collage_path, zip_path, temp_dir = procesar_video(video)
|
133 |
+
return collage_path, zip_path, temp_dir, zip_path # 4 outputs
|
134 |
+
|
135 |
+
procesar_btn.click(
|
136 |
+
fn=procesar_y_mostrar,
|
137 |
+
inputs=video_input,
|
138 |
+
outputs=[gallery_output, download_file, temp_dir_state, zip_path_state]
|
139 |
+
)
|
140 |
|
141 |
+
if __name__ == "__main__":
|
142 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|