ar08 commited on
Commit
c8affc0
·
verified ·
1 Parent(s): fa99f16

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -18
app.py CHANGED
@@ -11,39 +11,47 @@ 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)
@@ -58,20 +66,20 @@ with gr.Blocks() as demo:
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()
 
11
  """
12
  Encodes a file by splitting it into chunks, rendering frames, and creating a video from the frames.
13
  """
14
+ steps = gr.Steps()
15
+ steps.append("Splitting file into chunks...")
16
  split_file(input_file=file_path)
17
 
18
+ steps.append("Rendering frames from chunks...")
19
  render_frame()
20
 
21
+ steps.append("Creating video from frames...")
22
  create_video_from_images()
23
 
24
+ steps.append("Cleaning up temporary files...")
25
+ shutil.rmtree("./chunks", ignore_errors=True)
26
+ shutil.rmtree("./images", ignore_errors=True)
27
+ shutil.rmtree("./extracted_frames", ignore_errors=True)
28
+ shutil.rmtree("./recovered", ignore_errors=True)
29
 
30
+ steps.append("Encoding completed! Encoded video is ready.")
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
+ steps = gr.Steps()
38
+ steps.append("Extracting frames from video...")
39
  extract_frames_from_video()
40
 
41
+ steps.append("Recovering binary files from frames...")
42
  recover_binary_files()
43
 
44
+ steps.append("Merging chunks to reconstruct the original file...")
45
  merge_cunks("./recovered", output_file)
46
 
47
+ steps.append("Cleaning up temporary files...")
48
+ shutil.rmtree("./extracted_frames", ignore_errors=True)
49
+ shutil.rmtree("./chunks", ignore_errors=True)
50
+ shutil.rmtree("./recovered", ignore_errors=True)
51
+ shutil.rmtree("./images", ignore_errors=True)
52
 
53
+ steps.append("Decoding completed! File successfully reconstructed.")
54
+ return steps, f"Decoding completed! Output file: {output_file}"
55
 
56
  def encode_interface(file):
57
  return encode(file.name)
 
66
  with gr.Tab("Encode"):
67
  file_input = gr.File(label="Upload file to encode")
68
  encode_button = gr.Button("Encode")
69
+ steps_output = gr.Steps(label="Encoding Steps")
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=[steps_output, video_output])
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
+ decode_steps = gr.Steps(label="Decoding Steps")
81
 
82
+ decode_button.click(decode_interface, inputs=[video_input, output_file_input], outputs=decode_steps)
83
 
84
  # Launch the Gradio app
85
  demo.launch()