Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -116,22 +116,19 @@ def save_cookies(file):
|
|
116 |
return None
|
117 |
|
118 |
# β
YouTube pipeline
|
119 |
-
def
|
120 |
try:
|
121 |
if not WHISPER_AVAILABLE:
|
122 |
return "β Whisper is not installed. Run: pip install openai-whisper", ""
|
123 |
-
if
|
124 |
-
return "β
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
if
|
129 |
-
|
130 |
-
f.write(audio_file.read())
|
131 |
-
else:
|
132 |
-
shutil.copy(str(audio_file), temp_audio_path)
|
133 |
|
134 |
-
transcript = transcribe_audio(
|
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 |
-
|
156 |
-
|
157 |
-
|
|
|
|
|
|
|
|
|
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("β"):
|