Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import uuid
|
|
| 4 |
from gtts import gTTS
|
| 5 |
import whisper
|
| 6 |
import openai
|
|
|
|
| 7 |
|
| 8 |
# Load models once
|
| 9 |
# Force whisper to use a writable cache dir
|
|
@@ -46,7 +47,17 @@ def generate_feedback_with_llm(transcript):
|
|
| 46 |
|
| 47 |
return response.choices[0].message["content"]
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
def tutor_feedback(audio_file):
|
|
|
|
|
|
|
|
|
|
| 50 |
# Step 1: Transcribe
|
| 51 |
result = model.transcribe(audio_file)
|
| 52 |
transcript = result["text"]
|
|
|
|
| 4 |
from gtts import gTTS
|
| 5 |
import whisper
|
| 6 |
import openai
|
| 7 |
+
import wave
|
| 8 |
|
| 9 |
# Load models once
|
| 10 |
# Force whisper to use a writable cache dir
|
|
|
|
| 47 |
|
| 48 |
return response.choices[0].message["content"]
|
| 49 |
|
| 50 |
+
def is_valid_audio(filepath):
|
| 51 |
+
try:
|
| 52 |
+
with wave.open(filepath, 'rb') as wf:
|
| 53 |
+
return wf.getnframes() > 0
|
| 54 |
+
except Exception:
|
| 55 |
+
return False
|
| 56 |
+
|
| 57 |
def tutor_feedback(audio_file):
|
| 58 |
+
if not audio_file or not os.path.exists(audio_file) or not is_valid_audio(audio_file):
|
| 59 |
+
return "No valid audio received.", "Please record again.", None
|
| 60 |
+
|
| 61 |
# Step 1: Transcribe
|
| 62 |
result = model.transcribe(audio_file)
|
| 63 |
transcript = result["text"]
|