Maxkillor commited on
Commit
ca1036e
·
verified ·
1 Parent(s): 73b0620

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -35,11 +35,12 @@ def extract_audio_from_video(video_path):
35
 
36
  def generate_output(file_obj, model_size, task, output_format, language):
37
  with tempfile.TemporaryDirectory() as tmpdirname:
38
- # Save the uploaded file
39
  file_name = os.path.join(tmpdirname, file_obj.name)
40
  with open(file_name, 'wb') as f:
41
- f.write(file_obj.read())
42
 
 
43
  # If it's a video file, extract the audio
44
  if is_video_file(file_name):
45
  audio_path = extract_audio_from_video(file_name)
@@ -56,8 +57,6 @@ def generate_output(file_obj, model_size, task, output_format, language):
56
  language=None if language == "Auto-detect" else language
57
  )
58
 
59
- base_filename = os.path.splitext(file_name)[0]
60
-
61
  # Prepare the output file
62
  if 'Subtitles' in output_format:
63
  # Generate SRT content
@@ -71,13 +70,13 @@ def generate_output(file_obj, model_size, task, output_format, language):
71
  subtitles.append(subtitle)
72
 
73
  srt_content = srt.compose(subtitles)
74
- output_file = base_filename + '.srt'
75
  with open(output_file, "w", encoding='utf-8') as file:
76
  file.write(srt_content)
77
  else:
78
  # Generate TXT content
79
  transcription_text = " ".join([segment['text'] for segment in result['segments']])
80
- output_file = base_filename + '.txt'
81
  with open(output_file, "w", encoding='utf-8') as file:
82
  file.write(transcription_text)
83
 
@@ -94,6 +93,7 @@ with gr.Blocks() as demo:
94
  file_input = gr.File(
95
  label="Upload Video or Audio File",
96
  file_types=['video', 'audio']
 
97
  )
98
 
99
  with gr.Row():
 
35
 
36
  def generate_output(file_obj, model_size, task, output_format, language):
37
  with tempfile.TemporaryDirectory() as tmpdirname:
38
+ # Save the uploaded file to a temporary directory
39
  file_name = os.path.join(tmpdirname, file_obj.name)
40
  with open(file_name, 'wb') as f:
41
+ f.write(file_obj.read()) # Read the file content and write it to the temp file
42
 
43
+ # Proceed with the rest of the processing using file_name
44
  # If it's a video file, extract the audio
45
  if is_video_file(file_name):
46
  audio_path = extract_audio_from_video(file_name)
 
57
  language=None if language == "Auto-detect" else language
58
  )
59
 
 
 
60
  # Prepare the output file
61
  if 'Subtitles' in output_format:
62
  # Generate SRT content
 
70
  subtitles.append(subtitle)
71
 
72
  srt_content = srt.compose(subtitles)
73
+ output_file = file_name + '.srt'
74
  with open(output_file, "w", encoding='utf-8') as file:
75
  file.write(srt_content)
76
  else:
77
  # Generate TXT content
78
  transcription_text = " ".join([segment['text'] for segment in result['segments']])
79
+ output_file = file_name + '.txt'
80
  with open(output_file, "w", encoding='utf-8') as file:
81
  file.write(transcription_text)
82
 
 
93
  file_input = gr.File(
94
  label="Upload Video or Audio File",
95
  file_types=['video', 'audio']
96
+ type='file'
97
  )
98
 
99
  with gr.Row():