Create test_app.py
Browse files- test_app.py +42 -0
test_app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# test_app.py
|
| 2 |
+
# Simple testing script for Whisper Spaces App
|
| 3 |
+
# This script verifies imports, model loading, and WAV conversion.
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
import tempfile
|
| 7 |
+
from pydub import AudioSegment
|
| 8 |
+
import whisper
|
| 9 |
+
|
| 10 |
+
print("TEST: Starting basic tests...")
|
| 11 |
+
|
| 12 |
+
# 1. Test Whisper model loading
|
| 13 |
+
try:
|
| 14 |
+
model = whisper.load_model("small")
|
| 15 |
+
print("TEST: Whisper model loaded ✔️")
|
| 16 |
+
except Exception as e:
|
| 17 |
+
print("TEST FAIL: Whisper model load error:", e)
|
| 18 |
+
|
| 19 |
+
# 2. Test creating a dummy WAV file
|
| 20 |
+
try:
|
| 21 |
+
tmp = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
|
| 22 |
+
tmp_path = tmp.name
|
| 23 |
+
tmp.close()
|
| 24 |
+
|
| 25 |
+
# Generate 1 second of silence
|
| 26 |
+
AudioSegment.silent(duration=1000).export(tmp_path, format="wav")
|
| 27 |
+
|
| 28 |
+
if os.path.exists(tmp_path) and os.path.getsize(tmp_path) > 100:
|
| 29 |
+
print("TEST: WAV generation ✔️ ->", tmp_path)
|
| 30 |
+
else:
|
| 31 |
+
print("TEST FAIL: WAV file too small or missing.")
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print("TEST FAIL: WAV generation error:", e)
|
| 34 |
+
|
| 35 |
+
# 3. Test transcription on the silent audio
|
| 36 |
+
try:
|
| 37 |
+
result = model.transcribe(tmp_path)
|
| 38 |
+
print("TEST: Transcription output ✔️ ->", result.get("text"))
|
| 39 |
+
except Exception as e:
|
| 40 |
+
print("TEST FAIL: Transcription error:", e)
|
| 41 |
+
|
| 42 |
+
print("TEST: Completed.")
|