artificialguybr commited on
Commit
b03a3e4
·
verified ·
1 Parent(s): bd5b9b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -40,11 +40,16 @@ def download_youtube_audio(url):
40
  'key': 'FFmpegExtractAudio',
41
  'preferredcodec': 'wav',
42
  }],
43
- 'outtmpl': output_path
 
44
  }
45
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
46
  ydl.download([url])
47
 
 
 
 
 
48
  if os.path.exists(output_path):
49
  print(f"Audio download completed. File saved at: {output_path}")
50
  print(f"File size: {os.path.getsize(output_path)} bytes")
@@ -109,7 +114,9 @@ def transcribe_audio(file_path):
109
  print("Transcription completed.")
110
 
111
  # Cleanup
112
- cleanup_files(temp_audio, output_file)
 
 
113
 
114
  return result
115
 
@@ -137,6 +144,7 @@ def process_youtube(url):
137
  return "Please enter a YouTube URL.", None
138
  print(f"Processing YouTube URL: {url}")
139
 
 
140
  try:
141
  audio_file = download_youtube_audio(url)
142
  if not os.path.exists(audio_file):
@@ -151,7 +159,8 @@ def process_youtube(url):
151
  print(f"Error processing YouTube: {e}")
152
  return f"Processing error: {str(e)}", None
153
  finally:
154
- cleanup_files(audio_file)
 
155
  print(f"Directory content after processing: {os.listdir('.')}")
156
 
157
  def process_uploaded_video(video_path):
@@ -164,8 +173,6 @@ def process_uploaded_video(video_path):
164
  except Exception as e:
165
  print(f"Error processing video: {e}")
166
  return f"Processing error: {str(e)}", None
167
- finally:
168
- cleanup_files(video_path)
169
 
170
  print("Setting up Gradio interface...")
171
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
 
40
  'key': 'FFmpegExtractAudio',
41
  'preferredcodec': 'wav',
42
  }],
43
+ 'outtmpl': output_path,
44
+ 'keepvideo': True,
45
  }
46
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
47
  ydl.download([url])
48
 
49
+ # Check if the file was renamed to .wav.wav
50
+ if os.path.exists(output_path + ".wav"):
51
+ os.rename(output_path + ".wav", output_path)
52
+
53
  if os.path.exists(output_path):
54
  print(f"Audio download completed. File saved at: {output_path}")
55
  print(f"File size: {os.path.getsize(output_path)} bytes")
 
114
  print("Transcription completed.")
115
 
116
  # Cleanup
117
+ cleanup_files(output_file)
118
+ if temp_audio:
119
+ cleanup_files(temp_audio)
120
 
121
  return result
122
 
 
144
  return "Please enter a YouTube URL.", None
145
  print(f"Processing YouTube URL: {url}")
146
 
147
+ audio_file = None
148
  try:
149
  audio_file = download_youtube_audio(url)
150
  if not os.path.exists(audio_file):
 
159
  print(f"Error processing YouTube: {e}")
160
  return f"Processing error: {str(e)}", None
161
  finally:
162
+ if audio_file and os.path.exists(audio_file):
163
+ cleanup_files(audio_file)
164
  print(f"Directory content after processing: {os.listdir('.')}")
165
 
166
  def process_uploaded_video(video_path):
 
173
  except Exception as e:
174
  print(f"Error processing video: {e}")
175
  return f"Processing error: {str(e)}", None
 
 
176
 
177
  print("Setting up Gradio interface...")
178
  with gr.Blocks(theme=gr.themes.Soft()) as demo: