Ericwang commited on
Commit
3d64725
·
1 Parent(s): c29e499

edited delete function

Browse files
Files changed (2) hide show
  1. app.py +31 -3
  2. utlis.py +1 -0
app.py CHANGED
@@ -1,10 +1,22 @@
1
  import os
 
 
 
2
 
3
  import gradio as gr
4
 
5
- from pathlib import Path
 
 
6
 
7
- from utlis import HHMMSS_to_sec, convert_video_format, trim_media, molly_xlsx_to_table, table_to_ELAN_tsv
 
 
 
 
 
 
 
8
 
9
  def trim_video_wt(input_file, input_transcript, output_format, start_time, end_time):
10
  # trim video with transcript
@@ -32,6 +44,12 @@ def trim_video_wt(input_file, input_transcript, output_format, start_time, end_t
32
  transcript_name = f"{Path(input_transcript.name).stem.partition('.')[0]}_trimmed.tsv"
33
  transcript_file = os.path.join(output_folder, transcript_name)
34
  table_to_ELAN_tsv(table, transcript_file)
 
 
 
 
 
 
35
  return output_file, transcript_file
36
  except Exception as e:
37
  return f"Error: {str(e)}"
@@ -54,7 +72,12 @@ def trim_video(input_file, output_format, start_time, end_time):
54
  # Trim the video
55
  print("start trimming")
56
  output_file = trim_media(input_file.name, output_file, start_time, end_time)
57
-
 
 
 
 
 
58
  return output_file
59
  except Exception as e:
60
  return f"Error: {str(e)}"
@@ -74,6 +97,11 @@ def convert_video(input_file, output_format):
74
  print("start converting")
75
  output_file = convert_video_format(input_file.name, output_file)
76
 
 
 
 
 
 
77
  return output_file
78
  except Exception as e:
79
  return f"Error: {str(e)}"
 
1
  import os
2
+ import threading
3
+ import time
4
+ from pathlib import Path
5
 
6
  import gradio as gr
7
 
8
+ from utlis import (HHMMSS_to_sec, convert_video_format, molly_xlsx_to_table,
9
+ table_to_ELAN_tsv, trim_media)
10
+
11
 
12
+ def delete_files(files):
13
+ time.sleep(300)
14
+ for file in files:
15
+ try:
16
+ os.remove(file)
17
+ except FileNotFoundError:
18
+ pass
19
+ print("files deleted")
20
 
21
  def trim_video_wt(input_file, input_transcript, output_format, start_time, end_time):
22
  # trim video with transcript
 
44
  transcript_name = f"{Path(input_transcript.name).stem.partition('.')[0]}_trimmed.tsv"
45
  transcript_file = os.path.join(output_folder, transcript_name)
46
  table_to_ELAN_tsv(table, transcript_file)
47
+
48
+ # remove file after 10 minutes for security
49
+ print("start deleting files")
50
+ path_to_delete = [input_file.name, input_transcript.name, output_file, transcript_file]
51
+ threading.Thread(target=delete_files, args=([path_to_delete])).start()
52
+
53
  return output_file, transcript_file
54
  except Exception as e:
55
  return f"Error: {str(e)}"
 
72
  # Trim the video
73
  print("start trimming")
74
  output_file = trim_media(input_file.name, output_file, start_time, end_time)
75
+
76
+ # remove file after 10 minutes for security
77
+ print("start deleting files")
78
+ path_to_delete = [input_file.name, output_file]
79
+ threading.Thread(target=delete_files, args=([path_to_delete])).start()
80
+
81
  return output_file
82
  except Exception as e:
83
  return f"Error: {str(e)}"
 
97
  print("start converting")
98
  output_file = convert_video_format(input_file.name, output_file)
99
 
100
+ # remove file after 10 minutes for security
101
+ print("start deleting files")
102
+ path_to_delete = [input_file.name, output_file]
103
+ threading.Thread(target=delete_files, args=([path_to_delete])).start()
104
+
105
  return output_file
106
  except Exception as e:
107
  return f"Error: {str(e)}"
utlis.py CHANGED
@@ -6,6 +6,7 @@ from pathlib import Path
6
 
7
  import pandas as pd
8
 
 
9
  def convert_video_format(media_in, media_out):
10
  WAV_CHANNELS = 1
11
  WAV_SAMPLE_RATE = 16000
 
6
 
7
  import pandas as pd
8
 
9
+
10
  def convert_video_format(media_in, media_out):
11
  WAV_CHANNELS = 1
12
  WAV_SAMPLE_RATE = 16000