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()