rosyvs commited on
Commit
a80ecb7
·
1 Parent(s): 21f97b6

single results directory

Browse files

catch bug in trimmer when start time was lefft blank

Files changed (3) hide show
  1. .gitignore +1 -1
  2. app.py +10 -10
  3. utils.py +5 -4
.gitignore CHANGED
@@ -1,5 +1,5 @@
1
  .DS_Store
2
  __pycache__/
3
  flagged/
4
- results_*/
5
  logs/
 
1
  .DS_Store
2
  __pycache__/
3
  flagged/
4
+ results*/
5
  logs/
app.py CHANGED
@@ -45,10 +45,10 @@ def set_output_file(input_file, output_format, folder, insert_string = 'trimmed'
45
  return output_file
46
 
47
  def trim_video_helper(input_file, output_file, start_time, end_time):
48
- if start_time == "":
49
  start_time = 0
50
  end_time = 300
51
- elif start_time != "" and end_time == "":
52
  end_time = 300 + HHMMSS_to_sec(time_str=start_time)
53
  print("start time (s): ", start_time)
54
  print("end time (s): ", end_time)
@@ -89,11 +89,11 @@ def trim_video_vtr(input_file, output_format):
89
 
90
  # set output file
91
  insert_string = f"start{start_time}_end{end_time}"
92
- output_folder = f"{os.getcwd()}/results_vtr/"
93
  output_file = set_output_file(input_file, output_format, output_folder, insert_string)
94
 
95
  # write the start time, and end time to a txt file
96
- log_file = f"{os.getcwd()}/results_vtr/{audio_base_name}_start_end_time.txt"
97
  print("log_file: ", log_file)
98
  with open(log_file, "w") as f:
99
  f.write(f"{start_time}\n")
@@ -115,7 +115,7 @@ def trim_video_wt(input_file, input_transcript, output_format, start_time, end_t
115
  # trim video with transcript
116
  try:
117
  # set output file
118
- output_folder = f"{os.getcwd()}/results_wt/"
119
  output_file = set_output_file(input_file, output_format, output_folder)
120
  output_transcript = set_output_file(input_transcript, "tsv", output_folder)
121
 
@@ -145,7 +145,7 @@ def sort_transcript_helper(input_transcript, output_transcript):
145
  return output_transcript
146
 
147
  def sort_transcript_wrapper(input_file):
148
- output_folder = f"{os.getcwd()}/results_st/"
149
  output_file_path = set_output_file(input_file, "tsv", output_folder, insert_string = 'sorted')
150
  output_file_path = sort_transcript_helper(input_file.name, output_file_path)
151
  return output_file_path
@@ -153,7 +153,7 @@ def sort_transcript_wrapper(input_file):
153
  def trim_video(input_file, output_format, start_time, end_time):
154
  try:
155
  # Set output file
156
- output_folder = f"{os.getcwd()}/results_vt/"
157
  output_file = set_output_file(input_file, output_format, output_folder)
158
 
159
  # Trim the video
@@ -171,7 +171,7 @@ def trim_video(input_file, output_format, start_time, end_time):
171
  def convert_video(input_file, output_format):
172
  try:
173
  # Set output file
174
- output_folder = f"{os.getcwd()}/results_vc/"
175
  output_file = set_output_file(input_file, output_format, output_folder, \
176
  insert_string = 'converted')
177
  print(f"Begin converting to output format: {output_format}" )
@@ -192,7 +192,7 @@ def convert_video(input_file, output_format):
192
  input_file = gr.File(label="Select video file")
193
  output_format = gr.Dropdown(choices=["mkv", "MOV", "mp4", "wav"], label="Select output format", value="mp4", )
194
  start_time = gr.Textbox(label="Start time (in seconds or HH:MM:SS). Leave blank to start at beginning.")
195
- end_time = gr.Textbox(label="End time (in seconds or HH:MM:SS). Leave blank to trim a 5-minute interval since start.")
196
  output_file = gr.File(label="Download trimmed file")
197
  interface = gr.Interface(fn=trim_video, inputs=[input_file, output_format, start_time, end_time], outputs=output_file, title="Video Trimmer", allow_flagging="never",
198
  description="Trim a video file to a specific time interval. Please wait for the file to upload before clicking the 'Submit' button.")
@@ -249,4 +249,4 @@ interface_wt = gr.Interface(fn=trim_video_wt, inputs=[input_file_wt, input_trans
249
  `Error Type`: a string that may be blank, representing any errors in the transcription of the utterance. ")
250
 
251
  demo = gr.TabbedInterface([interface_c, interface, interface_vtr, interface_wt ], ["Video Converter", "Video Trimmer", "Video Trimmer with Random Start Time", "Video Trimmer with Transcript"])
252
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
45
  return output_file
46
 
47
  def trim_video_helper(input_file, output_file, start_time, end_time):
48
+ if not start_time:
49
  start_time = 0
50
  end_time = 300
51
+ elif start_time and not end_time:
52
  end_time = 300 + HHMMSS_to_sec(time_str=start_time)
53
  print("start time (s): ", start_time)
54
  print("end time (s): ", end_time)
 
89
 
90
  # set output file
91
  insert_string = f"start{start_time}_end{end_time}"
92
+ output_folder = f"{os.getcwd()}/results/"
93
  output_file = set_output_file(input_file, output_format, output_folder, insert_string)
94
 
95
  # write the start time, and end time to a txt file
96
+ log_file = f"{os.getcwd()}/results/{audio_base_name}_start_end_time.txt"
97
  print("log_file: ", log_file)
98
  with open(log_file, "w") as f:
99
  f.write(f"{start_time}\n")
 
115
  # trim video with transcript
116
  try:
117
  # set output file
118
+ output_folder = f"{os.getcwd()}/results/"
119
  output_file = set_output_file(input_file, output_format, output_folder)
120
  output_transcript = set_output_file(input_transcript, "tsv", output_folder)
121
 
 
145
  return output_transcript
146
 
147
  def sort_transcript_wrapper(input_file):
148
+ output_folder = f"{os.getcwd()}/results/"
149
  output_file_path = set_output_file(input_file, "tsv", output_folder, insert_string = 'sorted')
150
  output_file_path = sort_transcript_helper(input_file.name, output_file_path)
151
  return output_file_path
 
153
  def trim_video(input_file, output_format, start_time, end_time):
154
  try:
155
  # Set output file
156
+ output_folder = f"{os.getcwd()}/results/"
157
  output_file = set_output_file(input_file, output_format, output_folder)
158
 
159
  # Trim the video
 
171
  def convert_video(input_file, output_format):
172
  try:
173
  # Set output file
174
+ output_folder = f"{os.getcwd()}/results/"
175
  output_file = set_output_file(input_file, output_format, output_folder, \
176
  insert_string = 'converted')
177
  print(f"Begin converting to output format: {output_format}" )
 
192
  input_file = gr.File(label="Select video file")
193
  output_format = gr.Dropdown(choices=["mkv", "MOV", "mp4", "wav"], label="Select output format", value="mp4", )
194
  start_time = gr.Textbox(label="Start time (in seconds or HH:MM:SS). Leave blank to start at beginning.")
195
+ end_time = gr.Textbox(label="End time (in seconds or HH:MM:SS). Leave blank to trim a 5-minute interval since start.")
196
  output_file = gr.File(label="Download trimmed file")
197
  interface = gr.Interface(fn=trim_video, inputs=[input_file, output_format, start_time, end_time], outputs=output_file, title="Video Trimmer", allow_flagging="never",
198
  description="Trim a video file to a specific time interval. Please wait for the file to upload before clicking the 'Submit' button.")
 
249
  `Error Type`: a string that may be blank, representing any errors in the transcription of the utterance. ")
250
 
251
  demo = gr.TabbedInterface([interface_c, interface, interface_vtr, interface_wt ], ["Video Converter", "Video Trimmer", "Video Trimmer with Random Start Time", "Video Trimmer with Transcript"])
252
+ demo.launch(server_name="0.0.0.0", server_port=7860, show_error=True)
utils.py CHANGED
@@ -9,6 +9,8 @@ import gradio as gr
9
  import pandas as pd
10
 
11
  os.makedirs(f'{os.getcwd()}/logs', exist_ok=True)
 
 
12
  logging.basicConfig(filename=f'{os.getcwd()}/logs/logfile.log', level=logging.INFO,
13
  format='%(asctime)s - %(levelname)s - %(message)s')
14
  logging.info('Starting the application...')
@@ -185,19 +187,18 @@ def convert_and_trim_video(media_in, media_out, start=None, end=None):
185
  start_sec = HHMMSS_to_sec(start)
186
  end_sec = HHMMSS_to_sec(end)
187
  try:
188
- if start is None and end is None:
189
  logging.info(f'...No start and end times provided. Converting entire video without trimming...')
190
  trim_command=[]
191
  else:
192
- if start is None:
193
  logging.info(f'...No start time provided. Trimming video from start to specified end...')
194
  start_sec = 0.0
195
  trim_command = ['-ss',f'{start_sec}']
196
- if end is None:
197
  logging.info(f'...No end time provided. Trimming video from specified start to end of video...')
198
  end_sec = None
199
  else:
200
- end_sec = HHMMSS_to_sec(end)
201
  trim_command.extend(['-to', f'{end_sec}'])
202
 
203
  if not isinstance(media_in, (str, Path)):
 
9
  import pandas as pd
10
 
11
  os.makedirs(f'{os.getcwd()}/logs', exist_ok=True)
12
+ os.makedirs(f'{os.getcwd()}/results', exist_ok=True)
13
+
14
  logging.basicConfig(filename=f'{os.getcwd()}/logs/logfile.log', level=logging.INFO,
15
  format='%(asctime)s - %(levelname)s - %(message)s')
16
  logging.info('Starting the application...')
 
187
  start_sec = HHMMSS_to_sec(start)
188
  end_sec = HHMMSS_to_sec(end)
189
  try:
190
+ if start_sec is None and end_sec is None:
191
  logging.info(f'...No start and end times provided. Converting entire video without trimming...')
192
  trim_command=[]
193
  else:
194
+ if start_sec is None:
195
  logging.info(f'...No start time provided. Trimming video from start to specified end...')
196
  start_sec = 0.0
197
  trim_command = ['-ss',f'{start_sec}']
198
+ if end_sec is None:
199
  logging.info(f'...No end time provided. Trimming video from specified start to end of video...')
200
  end_sec = None
201
  else:
 
202
  trim_command.extend(['-to', f'{end_sec}'])
203
 
204
  if not isinstance(media_in, (str, Path)):