developer28 commited on
Commit
536d676
Β·
verified Β·
1 Parent(s): 3d3b497

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -116,19 +116,22 @@ def save_cookies(file):
116
  return None
117
 
118
  # βœ… YouTube pipeline
119
- def run_pipeline(url, cookies_file):
120
  try:
121
  if not WHISPER_AVAILABLE:
122
  return "❌ Whisper is not installed. Run: pip install openai-whisper", ""
123
- if not url:
124
- return "❌ YouTube URL required", ""
125
 
126
- cookie_path = save_cookies(cookies_file)
127
- audio_path, status = download_audio(url, cookie_path)
128
- if not audio_path:
129
- return status, ""
 
 
 
130
 
131
- transcript = transcribe_audio(audio_path)
132
  if transcript.startswith("❌"):
133
  return transcript, ""
134
 
@@ -140,6 +143,7 @@ def run_pipeline(url, cookies_file):
140
  print(tb)
141
  return f"❌ Unhandled Error:\n{tb}", ""
142
 
 
143
  # βœ… Audio file upload pipeline
144
  def run_pipeline_audio(audio_file):
145
  try:
 
116
  return None
117
 
118
  # βœ… YouTube pipeline
119
+ def run_pipeline_audio(audio_file):
120
  try:
121
  if not WHISPER_AVAILABLE:
122
  return "❌ Whisper is not installed. Run: pip install openai-whisper", ""
123
+ if audio_file is None:
124
+ return "❌ No audio file uploaded", ""
125
 
126
+ # Handle both file-like and NamedString (path string)
127
+ temp_audio_path = tempfile.mktemp(suffix=os.path.splitext(str(audio_file))[-1])
128
+ if hasattr(audio_file, "read"):
129
+ with open(temp_audio_path, "wb") as f:
130
+ f.write(audio_file.read())
131
+ else:
132
+ shutil.copy(str(audio_file), temp_audio_path)
133
 
134
+ transcript = transcribe_audio(temp_audio_path)
135
  if transcript.startswith("❌"):
136
  return transcript, ""
137
 
 
143
  print(tb)
144
  return f"❌ Unhandled Error:\n{tb}", ""
145
 
146
+
147
  # βœ… Audio file upload pipeline
148
  def run_pipeline_audio(audio_file):
149
  try: