Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
import uuid
|
| 4 |
-
import
|
| 5 |
from gtts import gTTS
|
| 6 |
import subprocess
|
| 7 |
import openai
|
|
@@ -12,7 +12,7 @@ os.environ["XDG_CACHE_HOME"] = "/tmp/.cache"
|
|
| 12 |
os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib"
|
| 13 |
|
| 14 |
# Load Whisper and set OpenAI key
|
| 15 |
-
model =
|
| 16 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 17 |
|
| 18 |
# Prompt template
|
|
@@ -50,7 +50,7 @@ def generate_feedback_with_llm(transcript):
|
|
| 50 |
prompt = PROMPT_TEMPLATE.format(transcript=transcript.strip())
|
| 51 |
|
| 52 |
response = client.chat.completions.create(
|
| 53 |
-
model="gpt-
|
| 54 |
temperature=0.7,
|
| 55 |
messages=[
|
| 56 |
{"role": "system", "content": "You are a helpful communication tutor."},
|
|
@@ -60,7 +60,11 @@ def generate_feedback_with_llm(transcript):
|
|
| 60 |
|
| 61 |
return response.choices[0].message.content
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
# Main function
|
| 65 |
def tutor_feedback(audio_file):
|
| 66 |
if not audio_file or not os.path.exists(audio_file):
|
|
@@ -73,8 +77,8 @@ def tutor_feedback(audio_file):
|
|
| 73 |
wav_path = convert_to_wav(audio_file)
|
| 74 |
|
| 75 |
# Transcribe
|
| 76 |
-
|
| 77 |
-
|
| 78 |
|
| 79 |
# Feedback via GPT
|
| 80 |
feedback_text = generate_feedback_with_llm(transcript)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
import uuid
|
| 4 |
+
from faster_whisper import WhisperModel
|
| 5 |
from gtts import gTTS
|
| 6 |
import subprocess
|
| 7 |
import openai
|
|
|
|
| 12 |
os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib"
|
| 13 |
|
| 14 |
# Load Whisper and set OpenAI key
|
| 15 |
+
model = WhisperModel("base", compute_type="int8") # Fastest CPU option
|
| 16 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 17 |
|
| 18 |
# Prompt template
|
|
|
|
| 50 |
prompt = PROMPT_TEMPLATE.format(transcript=transcript.strip())
|
| 51 |
|
| 52 |
response = client.chat.completions.create(
|
| 53 |
+
model="gpt-4-1106-preview",
|
| 54 |
temperature=0.7,
|
| 55 |
messages=[
|
| 56 |
{"role": "system", "content": "You are a helpful communication tutor."},
|
|
|
|
| 60 |
|
| 61 |
return response.choices[0].message.content
|
| 62 |
|
| 63 |
+
def transcribe_audio(audio_path):
|
| 64 |
+
segments, info = model.transcribe(audio_path)
|
| 65 |
+
transcript = " ".join([segment.text for segment in segments])
|
| 66 |
+
return transcript
|
| 67 |
+
|
| 68 |
# Main function
|
| 69 |
def tutor_feedback(audio_file):
|
| 70 |
if not audio_file or not os.path.exists(audio_file):
|
|
|
|
| 77 |
wav_path = convert_to_wav(audio_file)
|
| 78 |
|
| 79 |
# Transcribe
|
| 80 |
+
transcript = transcribe_audio(wav_path)
|
| 81 |
+
|
| 82 |
|
| 83 |
# Feedback via GPT
|
| 84 |
feedback_text = generate_feedback_with_llm(transcript)
|