Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,51 +7,63 @@ from modules.video import create_video_from_images, extract_frames_from_video
|
|
| 7 |
from modules.frame_decoder import recover_binary_files
|
| 8 |
from modules.merge import merge_cunks
|
| 9 |
|
| 10 |
-
def encode(file_path):
|
| 11 |
"""
|
| 12 |
Encodes a file by splitting it into chunks, rendering frames, and creating a video from the frames.
|
| 13 |
"""
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
return steps, "encoded_video.mp4"
|
| 32 |
|
| 33 |
-
def decode(output_file):
|
| 34 |
"""
|
| 35 |
Decodes a video by extracting frames, recovering binary files, and merging the chunks back into the original file.
|
| 36 |
"""
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
return steps, f"Decoding completed! Output file: {output_file}"
|
| 55 |
|
| 56 |
def encode_interface(file):
|
| 57 |
return encode(file.name)
|
|
@@ -66,20 +78,20 @@ with gr.Blocks() as demo:
|
|
| 66 |
with gr.Tab("Encode"):
|
| 67 |
file_input = gr.File(label="Upload file to encode")
|
| 68 |
encode_button = gr.Button("Encode")
|
| 69 |
-
|
| 70 |
video_output = gr.Video(label="Encoded Video")
|
| 71 |
download_button = gr.Button("Download Encoded Video")
|
| 72 |
|
| 73 |
-
encode_button.click(encode_interface, inputs=file_input, outputs=[
|
| 74 |
download_button.click(lambda: "encoded_video.mp4", inputs=None, outputs=gr.File(label="Download Encoded Video"))
|
| 75 |
|
| 76 |
with gr.Tab("Decode"):
|
| 77 |
video_input = gr.Video(label="Upload video to decode")
|
| 78 |
output_file_input = gr.Textbox(label="Output file name")
|
| 79 |
decode_button = gr.Button("Decode")
|
| 80 |
-
|
| 81 |
|
| 82 |
-
decode_button.click(decode_interface, inputs=[video_input, output_file_input], outputs=
|
| 83 |
|
| 84 |
# Launch the Gradio app
|
| 85 |
demo.launch()
|
|
|
|
| 7 |
from modules.frame_decoder import recover_binary_files
|
| 8 |
from modules.merge import merge_cunks
|
| 9 |
|
| 10 |
+
def encode(file_path, progress=gr.Progress()):
|
| 11 |
"""
|
| 12 |
Encodes a file by splitting it into chunks, rendering frames, and creating a video from the frames.
|
| 13 |
"""
|
| 14 |
+
with progress.tqdm(total=5) as pbar:
|
| 15 |
+
pbar.set_description("Splitting file into chunks...")
|
| 16 |
+
split_file(input_file=file_path)
|
| 17 |
+
pbar.update(1)
|
| 18 |
+
|
| 19 |
+
pbar.set_description("Rendering frames from chunks...")
|
| 20 |
+
render_frame()
|
| 21 |
+
pbar.update(1)
|
| 22 |
+
|
| 23 |
+
pbar.set_description("Creating video from frames...")
|
| 24 |
+
create_video_from_images()
|
| 25 |
+
pbar.update(1)
|
| 26 |
+
|
| 27 |
+
pbar.set_description("Cleaning up temporary files...")
|
| 28 |
+
shutil.rmtree("./chunks", ignore_errors=True)
|
| 29 |
+
shutil.rmtree("./images", ignore_errors=True)
|
| 30 |
+
shutil.rmtree("./extracted_frames", ignore_errors=True)
|
| 31 |
+
shutil.rmtree("./recovered", ignore_errors=True)
|
| 32 |
+
pbar.update(1)
|
| 33 |
+
|
| 34 |
+
pbar.set_description("Encoding completed!")
|
| 35 |
+
pbar.update(1)
|
| 36 |
|
| 37 |
+
return "encoded_video.mp4"
|
|
|
|
| 38 |
|
| 39 |
+
def decode(output_file, progress=gr.Progress()):
|
| 40 |
"""
|
| 41 |
Decodes a video by extracting frames, recovering binary files, and merging the chunks back into the original file.
|
| 42 |
"""
|
| 43 |
+
with progress.tqdm(total=5) as pbar:
|
| 44 |
+
pbar.set_description("Extracting frames from video...")
|
| 45 |
+
extract_frames_from_video()
|
| 46 |
+
pbar.update(1)
|
| 47 |
+
|
| 48 |
+
pbar.set_description("Recovering binary files from frames...")
|
| 49 |
+
recover_binary_files()
|
| 50 |
+
pbar.update(1)
|
| 51 |
+
|
| 52 |
+
pbar.set_description("Merging chunks to reconstruct the original file...")
|
| 53 |
+
merge_cunks("./recovered", output_file)
|
| 54 |
+
pbar.update(1)
|
| 55 |
+
|
| 56 |
+
pbar.set_description("Cleaning up temporary files...")
|
| 57 |
+
shutil.rmtree("./extracted_frames", ignore_errors=True)
|
| 58 |
+
shutil.rmtree("./chunks", ignore_errors=True)
|
| 59 |
+
shutil.rmtree("./recovered", ignore_errors=True)
|
| 60 |
+
shutil.rmtree("./images", ignore_errors=True)
|
| 61 |
+
pbar.update(1)
|
| 62 |
+
|
| 63 |
+
pbar.set_description("Decoding completed!")
|
| 64 |
+
pbar.update(1)
|
| 65 |
|
| 66 |
+
return f"Decoding completed! Output file: {output_file}"
|
|
|
|
| 67 |
|
| 68 |
def encode_interface(file):
|
| 69 |
return encode(file.name)
|
|
|
|
| 78 |
with gr.Tab("Encode"):
|
| 79 |
file_input = gr.File(label="Upload file to encode")
|
| 80 |
encode_button = gr.Button("Encode")
|
| 81 |
+
progress_bar = gr.Progress()
|
| 82 |
video_output = gr.Video(label="Encoded Video")
|
| 83 |
download_button = gr.Button("Download Encoded Video")
|
| 84 |
|
| 85 |
+
encode_button.click(encode_interface, inputs=file_input, outputs=[video_output], progress=progress_bar)
|
| 86 |
download_button.click(lambda: "encoded_video.mp4", inputs=None, outputs=gr.File(label="Download Encoded Video"))
|
| 87 |
|
| 88 |
with gr.Tab("Decode"):
|
| 89 |
video_input = gr.Video(label="Upload video to decode")
|
| 90 |
output_file_input = gr.Textbox(label="Output file name")
|
| 91 |
decode_button = gr.Button("Decode")
|
| 92 |
+
decode_progress = gr.Progress()
|
| 93 |
|
| 94 |
+
decode_button.click(decode_interface, inputs=[video_input, output_file_input], outputs=gr.Textbox(label="Status"), progress=decode_progress)
|
| 95 |
|
| 96 |
# Launch the Gradio app
|
| 97 |
demo.launch()
|