Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,77 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from modules.split import split_file
|
| 3 |
from modules.frame_creator import render_frame
|
| 4 |
from modules.video import create_video_from_images, extract_frames_from_video
|
| 5 |
from modules.frame_decoder import recover_binary_files
|
| 6 |
-
import shutil
|
| 7 |
from modules.merge import merge_cunks
|
| 8 |
-
import os
|
| 9 |
|
| 10 |
-
# 🌝 Defining Encode functions
|
| 11 |
def encode(file_path):
|
| 12 |
"""
|
| 13 |
Encodes a file by splitting it into chunks, rendering frames, and creating a video from the frames.
|
| 14 |
"""
|
|
|
|
| 15 |
split_file(input_file=file_path)
|
|
|
|
|
|
|
| 16 |
render_frame()
|
|
|
|
|
|
|
| 17 |
create_video_from_images()
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
def decode(output_file):
|
| 24 |
"""
|
| 25 |
Decodes a video by extracting frames, recovering binary files, and merging the chunks back into the original file.
|
| 26 |
"""
|
|
|
|
| 27 |
extract_frames_from_video()
|
|
|
|
|
|
|
| 28 |
recover_binary_files()
|
|
|
|
|
|
|
| 29 |
merge_cunks("./recovered", output_file)
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
# Gradio interface
|
| 36 |
def encode_interface(file):
|
| 37 |
-
encode(file.name)
|
| 38 |
-
video_path = "encoded_video.mp4" # Assuming the encoded video is saved as "encoded_video.mp4"
|
| 39 |
-
return video_path
|
| 40 |
|
| 41 |
def decode_interface(video, output_file):
|
| 42 |
-
decode(output_file)
|
| 43 |
-
return "Decoding completed!"
|
| 44 |
|
| 45 |
-
#
|
| 46 |
with gr.Blocks() as demo:
|
| 47 |
gr.Markdown("# File Encoder/Decoder using Video Frames")
|
| 48 |
-
|
| 49 |
with gr.Tab("Encode"):
|
| 50 |
file_input = gr.File(label="Upload file to encode")
|
| 51 |
encode_button = gr.Button("Encode")
|
|
|
|
| 52 |
video_output = gr.Video(label="Encoded Video")
|
| 53 |
download_button = gr.Button("Download Encoded Video")
|
| 54 |
-
|
|
|
|
| 55 |
download_button.click(lambda: "encoded_video.mp4", inputs=None, outputs=gr.File(label="Download Encoded Video"))
|
| 56 |
-
|
| 57 |
with gr.Tab("Decode"):
|
| 58 |
video_input = gr.Video(label="Upload video to decode")
|
| 59 |
output_file_input = gr.Textbox(label="Output file name")
|
| 60 |
decode_button = gr.Button("Decode")
|
| 61 |
-
|
|
|
|
|
|
|
| 62 |
|
| 63 |
# Launch the Gradio app
|
| 64 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import shutil
|
| 3 |
+
import os
|
| 4 |
from modules.split import split_file
|
| 5 |
from modules.frame_creator import render_frame
|
| 6 |
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 |
+
yield "Splitting file into chunks..."
|
| 15 |
split_file(input_file=file_path)
|
| 16 |
+
|
| 17 |
+
yield "Rendering frames from chunks..."
|
| 18 |
render_frame()
|
| 19 |
+
|
| 20 |
+
yield "Creating video from frames..."
|
| 21 |
create_video_from_images()
|
| 22 |
+
|
| 23 |
+
yield "Cleaning up temporary files..."
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
yield "Encoding completed! Encoded video is ready."
|
| 27 |
+
return "encoded_video.mp4"
|
| 28 |
|
| 29 |
def decode(output_file):
|
| 30 |
"""
|
| 31 |
Decodes a video by extracting frames, recovering binary files, and merging the chunks back into the original file.
|
| 32 |
"""
|
| 33 |
+
yield "Extracting frames from video..."
|
| 34 |
extract_frames_from_video()
|
| 35 |
+
|
| 36 |
+
yield "Recovering binary files from frames..."
|
| 37 |
recover_binary_files()
|
| 38 |
+
|
| 39 |
+
yield "Merging chunks to reconstruct the original file..."
|
| 40 |
merge_cunks("./recovered", output_file)
|
| 41 |
+
|
| 42 |
+
yield "Cleaning up temporary files..."
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
yield "Decoding completed! File successfully reconstructed."
|
| 46 |
+
return f"Decoding completed! Output file: {output_file}"
|
| 47 |
|
|
|
|
| 48 |
def encode_interface(file):
|
| 49 |
+
return encode(file.name)
|
|
|
|
|
|
|
| 50 |
|
| 51 |
def decode_interface(video, output_file):
|
| 52 |
+
return decode(output_file)
|
|
|
|
| 53 |
|
| 54 |
+
# Gradio interface
|
| 55 |
with gr.Blocks() as demo:
|
| 56 |
gr.Markdown("# File Encoder/Decoder using Video Frames")
|
| 57 |
+
|
| 58 |
with gr.Tab("Encode"):
|
| 59 |
file_input = gr.File(label="Upload file to encode")
|
| 60 |
encode_button = gr.Button("Encode")
|
| 61 |
+
status_output = gr.Textbox(label="Status", interactive=False)
|
| 62 |
video_output = gr.Video(label="Encoded Video")
|
| 63 |
download_button = gr.Button("Download Encoded Video")
|
| 64 |
+
|
| 65 |
+
encode_button.click(encode_interface, inputs=file_input, outputs=[status_output, video_output])
|
| 66 |
download_button.click(lambda: "encoded_video.mp4", inputs=None, outputs=gr.File(label="Download Encoded Video"))
|
| 67 |
+
|
| 68 |
with gr.Tab("Decode"):
|
| 69 |
video_input = gr.Video(label="Upload video to decode")
|
| 70 |
output_file_input = gr.Textbox(label="Output file name")
|
| 71 |
decode_button = gr.Button("Decode")
|
| 72 |
+
decode_status = gr.Textbox(label="Status", interactive=False)
|
| 73 |
+
|
| 74 |
+
decode_button.click(decode_interface, inputs=[video_input, output_file_input], outputs=decode_status)
|
| 75 |
|
| 76 |
# Launch the Gradio app
|
| 77 |
demo.launch()
|