Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -69,16 +69,26 @@ def model(text):
|
|
69 |
for response in stream:
|
70 |
if not response.token.text == "</s>":
|
71 |
output += response.token.text
|
72 |
-
return output
|
|
|
73 |
|
74 |
# Text-to-Speech function using edge_tts
|
75 |
async def generate_audio_feedback(feedback_text):
|
76 |
communicate = edge_tts.Communicate(feedback_text)
|
77 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
78 |
tmp_path = tmp_file.name
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
return tmp_path
|
81 |
|
|
|
82 |
# Generating feedback for the Oral Coach
|
83 |
async def generate_feedback(user_id, question_choice, strategy_choice, message, feedback_level):
|
84 |
current_question_index = thinkingframes.questions.index(question_choice)
|
@@ -124,9 +134,9 @@ async def generate_feedback(user_id, question_choice, strategy_choice, message,
|
|
124 |
chat_history = [] # Initialize chat history outside the loop
|
125 |
full_feedback = "" # Accumulate the entire feedback message
|
126 |
try:
|
127 |
-
for chunk in response:
|
128 |
-
if chunk
|
129 |
-
feedback_chunk = chunk
|
130 |
yield feedback_chunk # Yield each feedback chunk as it is generated
|
131 |
await asyncio.sleep(0)
|
132 |
|
@@ -136,6 +146,7 @@ async def generate_feedback(user_id, question_choice, strategy_choice, message,
|
|
136 |
questionNo = current_question_index + 1
|
137 |
add_submission(user_id, message, full_feedback, int(0), "", questionNo)
|
138 |
|
|
|
139 |
# Function to predict and handle the entire workflow
|
140 |
async def predict(question_choice, strategy_choice, feedback_level, audio):
|
141 |
current_audio_output = None # Initialize current_audio_output to None
|
|
|
69 |
for response in stream:
|
70 |
if not response.token.text == "</s>":
|
71 |
output += response.token.text
|
72 |
+
return {"choices": [{"delta": {"content": output}}]}
|
73 |
+
|
74 |
|
75 |
# Text-to-Speech function using edge_tts
|
76 |
async def generate_audio_feedback(feedback_text):
|
77 |
communicate = edge_tts.Communicate(feedback_text)
|
78 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
79 |
tmp_path = tmp_file.name
|
80 |
+
try:
|
81 |
+
await communicate.save(tmp_path)
|
82 |
+
except asyncio.TimeoutError:
|
83 |
+
logging.error("Timeout occurred during TTS generation. Retrying...")
|
84 |
+
try:
|
85 |
+
await communicate.save(tmp_path)
|
86 |
+
except asyncio.TimeoutError:
|
87 |
+
logging.error("Retry failed. Unable to generate TTS.")
|
88 |
+
return None
|
89 |
return tmp_path
|
90 |
|
91 |
+
|
92 |
# Generating feedback for the Oral Coach
|
93 |
async def generate_feedback(user_id, question_choice, strategy_choice, message, feedback_level):
|
94 |
current_question_index = thinkingframes.questions.index(question_choice)
|
|
|
134 |
chat_history = [] # Initialize chat history outside the loop
|
135 |
full_feedback = "" # Accumulate the entire feedback message
|
136 |
try:
|
137 |
+
for chunk in response["choices"]:
|
138 |
+
if chunk["delta"] and chunk["delta"]["content"]:
|
139 |
+
feedback_chunk = chunk["delta"]["content"]
|
140 |
yield feedback_chunk # Yield each feedback chunk as it is generated
|
141 |
await asyncio.sleep(0)
|
142 |
|
|
|
146 |
questionNo = current_question_index + 1
|
147 |
add_submission(user_id, message, full_feedback, int(0), "", questionNo)
|
148 |
|
149 |
+
|
150 |
# Function to predict and handle the entire workflow
|
151 |
async def predict(question_choice, strategy_choice, feedback_level, audio):
|
152 |
current_audio_output = None # Initialize current_audio_output to None
|