Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -298,42 +298,43 @@ def find_matching_filename(transcribed_filename: str, reference_map: Dict[str, s
|
|
| 298 |
log_message(f"⚠️ No matching filename found for: {transcribed_filename}", "WARNING")
|
| 299 |
return None
|
| 300 |
|
| 301 |
-
def check_ffmpeg() -> bool:
|
| 302 |
-
"""Check if ffmpeg is installed"""
|
| 303 |
-
try:
|
| 304 |
-
subprocess.run(["ffmpeg", "-version"], capture_output=True, check=True)
|
| 305 |
-
return True
|
| 306 |
-
except (FileNotFoundError, subprocess.CalledProcessError):
|
| 307 |
-
return False
|
| 308 |
-
|
| 309 |
def transcribe_audio(wav_path: str) -> Optional[Dict[str, Any]]:
|
| 310 |
-
"""Transcribe audio file using Whisper."""
|
| 311 |
log_message(f"🎤 Transcribing audio file: {wav_path}", "INFO")
|
| 312 |
|
| 313 |
try:
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
|
| 329 |
# Transcribe
|
| 330 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
|
| 332 |
log_message(f"✅ Successfully transcribed: {wav_path}", "INFO")
|
| 333 |
-
return
|
| 334 |
|
| 335 |
-
except ImportError:
|
| 336 |
-
|
|
|
|
|
|
|
| 337 |
return None
|
| 338 |
except Exception as e:
|
| 339 |
log_message(f"❌ Failed to transcribe {wav_path}: {str(e)}", "ERROR")
|
|
@@ -680,17 +681,12 @@ async def startup_event():
|
|
| 680 |
"""Auto-start processing when server starts"""
|
| 681 |
log_message("🚀 Server startup: Checking dependencies...", "INFO")
|
| 682 |
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
log_message("
|
| 686 |
-
|
| 687 |
-
log_message("
|
| 688 |
-
log_message("
|
| 689 |
-
log_message(" - Windows (Scoop): scoop install ffmpeg", "WARNING")
|
| 690 |
-
log_message(" - Linux (Ubuntu): sudo apt-get install ffmpeg", "WARNING")
|
| 691 |
-
log_message(" - macOS (Homebrew): brew install ffmpeg", "WARNING")
|
| 692 |
-
else:
|
| 693 |
-
log_message("✅ ffmpeg found", "INFO")
|
| 694 |
|
| 695 |
log_message("🚀 Server startup: Auto-starting processing loop", "INFO")
|
| 696 |
|
|
|
|
| 298 |
log_message(f"⚠️ No matching filename found for: {transcribed_filename}", "WARNING")
|
| 299 |
return None
|
| 300 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
def transcribe_audio(wav_path: str) -> Optional[Dict[str, Any]]:
|
| 302 |
+
"""Transcribe audio file using Whisper from Transformers."""
|
| 303 |
log_message(f"🎤 Transcribing audio file: {wav_path}", "INFO")
|
| 304 |
|
| 305 |
try:
|
| 306 |
+
from transformers import pipeline
|
| 307 |
+
import librosa
|
| 308 |
+
|
| 309 |
+
# Load audio with librosa
|
| 310 |
+
log_message(f"Loading audio file: {wav_path}", "INFO")
|
| 311 |
+
audio, sr = librosa.load(wav_path, sr=16000)
|
| 312 |
+
|
| 313 |
+
# Initialize Whisper pipeline
|
| 314 |
+
log_message(f"Loading Whisper {WHISPER_MODEL} model from Transformers...", "INFO")
|
| 315 |
+
pipe = pipeline(
|
| 316 |
+
"automatic-speech-recognition",
|
| 317 |
+
model=f"openai/whisper-{WHISPER_MODEL}",
|
| 318 |
+
device=0 if __import__('torch').cuda.is_available() else -1 # GPU if available, else CPU
|
| 319 |
+
)
|
| 320 |
|
| 321 |
# Transcribe
|
| 322 |
+
log_message("Transcribing audio...", "INFO")
|
| 323 |
+
result = pipe(audio)
|
| 324 |
+
|
| 325 |
+
# Format result to match openai-whisper format
|
| 326 |
+
formatted_result = {
|
| 327 |
+
"text": result["text"],
|
| 328 |
+
"segments": [{"text": result["text"]}]
|
| 329 |
+
}
|
| 330 |
|
| 331 |
log_message(f"✅ Successfully transcribed: {wav_path}", "INFO")
|
| 332 |
+
return formatted_result
|
| 333 |
|
| 334 |
+
except ImportError as e:
|
| 335 |
+
missing_lib = str(e)
|
| 336 |
+
log_message(f"❌ Missing library. Install with: pip install transformers librosa torch torchaudio", "ERROR")
|
| 337 |
+
log_message(f" Error: {missing_lib}", "ERROR")
|
| 338 |
return None
|
| 339 |
except Exception as e:
|
| 340 |
log_message(f"❌ Failed to transcribe {wav_path}: {str(e)}", "ERROR")
|
|
|
|
| 681 |
"""Auto-start processing when server starts"""
|
| 682 |
log_message("🚀 Server startup: Checking dependencies...", "INFO")
|
| 683 |
|
| 684 |
+
try:
|
| 685 |
+
import transformers
|
| 686 |
+
log_message("✅ Transformers found", "INFO")
|
| 687 |
+
except ImportError:
|
| 688 |
+
log_message("⚠️ WARNING: Transformers not installed!", "WARNING")
|
| 689 |
+
log_message(" Install with: pip install transformers librosa torch torchaudio", "WARNING")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 690 |
|
| 691 |
log_message("🚀 Server startup: Auto-starting processing loop", "INFO")
|
| 692 |
|