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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -116,22 +116,19 @@ def save_cookies(file):
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,7 +140,6 @@ def run_pipeline_audio(audio_file):
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:
@@ -152,9 +148,13 @@ def run_pipeline_audio(audio_file):
152
  if audio_file is None:
153
  return "❌ No audio file uploaded", ""
154
 
155
- temp_audio_path = tempfile.mktemp(suffix=os.path.splitext(audio_file.name)[-1])
156
- with open(temp_audio_path, "wb") as f:
157
- f.write(audio_file.read())
 
 
 
 
158
 
159
  transcript = transcribe_audio(temp_audio_path)
160
  if transcript.startswith("❌"):
 
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
  print(tb)
141
  return f"❌ Unhandled Error:\n{tb}", ""
142
 
 
143
  # βœ… Audio file upload pipeline
144
  def run_pipeline_audio(audio_file):
145
  try:
 
148
  if audio_file is None:
149
  return "❌ No audio file uploaded", ""
150
 
151
+ # Handle both file-like and NamedString (path string)
152
+ temp_audio_path = tempfile.mktemp(suffix=os.path.splitext(str(audio_file))[-1])
153
+ if hasattr(audio_file, "read"):
154
+ with open(temp_audio_path, "wb") as f:
155
+ f.write(audio_file.read())
156
+ else:
157
+ shutil.copy(str(audio_file), temp_audio_path)
158
 
159
  transcript = transcribe_audio(temp_audio_path)
160
  if transcript.startswith("❌"):