Spaces:
Running
Running
Update qa.py
Browse files
qa.py
CHANGED
@@ -7,7 +7,6 @@ from utils import generate_audio_mp3
|
|
7 |
def transcribe_audio_deepgram(local_audio_path: str) -> str:
|
8 |
"""
|
9 |
Sends a local audio file to Deepgram for STT (Speech-to-Text).
|
10 |
-
Returns the transcript text if successful, or raises an error if failed.
|
11 |
"""
|
12 |
DEEPGRAM_API_KEY = os.environ.get("DEEPGRAM_API_KEY")
|
13 |
if not DEEPGRAM_API_KEY:
|
@@ -24,14 +23,11 @@ def transcribe_audio_deepgram(local_audio_path: str) -> str:
|
|
24 |
response.raise_for_status()
|
25 |
|
26 |
data = response.json()
|
27 |
-
|
28 |
-
return transcript
|
29 |
-
|
30 |
|
31 |
def call_llm_for_qa(conversation_so_far: str, user_question: str) -> dict:
|
32 |
"""
|
33 |
-
Calls
|
34 |
-
Returns a Python dict: {"speaker": "Guest", "text": "..."}
|
35 |
"""
|
36 |
system_prompt = f"""
|
37 |
You are an expert guest in a podcast session. The user is asking a follow-up question.
|
@@ -51,11 +47,10 @@ def call_llm_for_qa(conversation_so_far: str, user_question: str) -> dict:
|
|
51 |
response_dict = json.loads(raw_json_response)
|
52 |
return response_dict
|
53 |
|
54 |
-
|
55 |
def handle_qa_exchange(user_question: str) -> (bytes, str):
|
56 |
"""
|
57 |
1) Reads conversation_so_far from session_state
|
58 |
-
2) Calls the LLM for a
|
59 |
3) Generates TTS audio
|
60 |
4) Returns (audio_bytes, answer_text)
|
61 |
"""
|
@@ -71,7 +66,6 @@ def handle_qa_exchange(user_question: str) -> (bytes, str):
|
|
71 |
if not answer_text.strip():
|
72 |
return (None, "")
|
73 |
|
74 |
-
# Generate text-to-speech audio response
|
75 |
audio_file_path = generate_audio_mp3(answer_text, speaker)
|
76 |
with open(audio_file_path, "rb") as f:
|
77 |
audio_bytes = f.read()
|
|
|
7 |
def transcribe_audio_deepgram(local_audio_path: str) -> str:
|
8 |
"""
|
9 |
Sends a local audio file to Deepgram for STT (Speech-to-Text).
|
|
|
10 |
"""
|
11 |
DEEPGRAM_API_KEY = os.environ.get("DEEPGRAM_API_KEY")
|
12 |
if not DEEPGRAM_API_KEY:
|
|
|
23 |
response.raise_for_status()
|
24 |
|
25 |
data = response.json()
|
26 |
+
return data["results"]["channels"][0]["alternatives"][0].get("transcript", "")
|
|
|
|
|
27 |
|
28 |
def call_llm_for_qa(conversation_so_far: str, user_question: str) -> dict:
|
29 |
"""
|
30 |
+
Calls LLM (Groq API) to generate a structured response to a follow-up question.
|
|
|
31 |
"""
|
32 |
system_prompt = f"""
|
33 |
You are an expert guest in a podcast session. The user is asking a follow-up question.
|
|
|
47 |
response_dict = json.loads(raw_json_response)
|
48 |
return response_dict
|
49 |
|
|
|
50 |
def handle_qa_exchange(user_question: str) -> (bytes, str):
|
51 |
"""
|
52 |
1) Reads conversation_so_far from session_state
|
53 |
+
2) Calls the LLM for a follow-up answer
|
54 |
3) Generates TTS audio
|
55 |
4) Returns (audio_bytes, answer_text)
|
56 |
"""
|
|
|
66 |
if not answer_text.strip():
|
67 |
return (None, "")
|
68 |
|
|
|
69 |
audio_file_path = generate_audio_mp3(answer_text, speaker)
|
70 |
with open(audio_file_path, "rb") as f:
|
71 |
audio_bytes = f.read()
|