Spaces:
Paused
Paused
File size: 2,186 Bytes
47eec30 76feb60 fa99f16 47eec30 5fb0db9 76feb60 5fb0db9 76feb60 5fb0db9 76feb60 5fb0db9 76feb60 5fb0db9 76feb60 5fb0db9 47eec30 5fb0db9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import gradio as gr
import tempfile
import shutil
import os
from modules.split import split_file
from modules.frame_creator import render_frame
from modules.video import create_video_from_images, extract_frames_from_video
from modules.frame_decoder import recover_binary_files
from modules.merge import merge_cunks
# π Encoding Function
def encode(file):
if not file:
return "No file uploaded!"
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_vid:
video_path = temp_vid.name
split_file(input_file=file)
render_frame()
create_video_from_images(output_video=video_path)
# Cleanup
shutil.rmtree("./chunks", ignore_errors=True)
shutil.rmtree("./images", ignore_errors=True)
shutil.rmtree("./extracted_frames", ignore_errors=True)
shutil.rmtree("./recovered", ignore_errors=True)
return video_path
# π Decoding Function
def decode(video):
if not video:
return "No video uploaded!"
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
output_file = temp_file.name
extract_frames_from_video(video)
recover_binary_files()
merge_cunks("./recovered", output_file)
# Cleanup
shutil.rmtree("./extracted_frames", ignore_errors=True)
shutil.rmtree("./chunks", ignore_errors=True)
shutil.rmtree("./recovered", ignore_errors=True)
shutil.rmtree("./images", ignore_errors=True)
return output_file
# π¨ Gradio UI
with gr.Blocks() as app:
gr.Markdown("# π File to Video Encoder & Decoder")
with gr.Tab("Encode"):
with gr.Row():
file_input = gr.File(label="Upload a file to encode")
encode_button = gr.Button("Encode")
video_output = gr.File(label="Download encoded video")
with gr.Tab("Decode"):
with gr.Row():
video_input = gr.File(label="Upload encoded video")
decode_button = gr.Button("Decode")
file_output = gr.File(label="Download decoded file")
encode_button.click(encode, inputs=[file_input], outputs=[video_output])
decode_button.click(decode, inputs=[video_input], outputs=[file_output])
# π Run the app
app.launch() |