rodrigomasini commited on
Commit
202a516
·
verified ·
1 Parent(s): 24accb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -17
app.py CHANGED
@@ -91,20 +91,20 @@ def extract_user_input(transcription_response):
91
  print(f"[ERROR] KeyError in transcription response: {e}")
92
  return ""
93
 
94
- def format_generated_response(response):
95
- print("[DEBUG] Formatting the generated response.")
96
- if response is None:
97
- print("[ERROR] No response to format.")
98
- return "Error: No valid response received."
99
- try:
100
- generated_text = response['choices'][0]['message']['content']
101
- partial_text = re.sub(r'<.*?>', '', generated_text)
102
- cleaned_text = re.sub(r'#.*?\n', '', partial_text)
103
- print(f"[DEBUG] Formatted response: {cleaned_text.strip()}")
104
- return cleaned_text.strip()
105
- except (KeyError, IndexError) as e:
106
- print(f"[ERROR] Error formatting response: {e}")
107
- return f"Error: Missing key or index {e} in response."
108
 
109
  def generate_speech(text):
110
  print("[DEBUG] Generating speech from text.")
@@ -165,13 +165,14 @@ def chatbot_conversation(audio_file_path):
165
  response += token
166
  # Optional: print tokens as they arrive for debugging
167
  print(f"[DEBUG] Partial response token received: {token}")
 
168
  except Exception as e:
169
  print(f"[ERROR] Error during streaming response: {e}")
170
  return "I could not understand you. Please try again.", None
171
 
172
- formatted_output = format_generated_response(
173
- {"choices": [{"message": {"content": response}}]}
174
- )
175
 
176
  if response:
177
  # Append the conversation turn to history
 
91
  print(f"[ERROR] KeyError in transcription response: {e}")
92
  return ""
93
 
94
+ #def format_generated_response(response):
95
+ # print("[DEBUG] Formatting the generated response.")
96
+ # if response is None:
97
+ # print("[ERROR] No response to format.")
98
+ # return "Error: No valid response received."
99
+ # try:
100
+ # generated_text = response['choices'][0]['message']['content']
101
+ # partial_text = re.sub(r'<.*?>', '', generated_text)
102
+ # cleaned_text = re.sub(r'#.*?\n', '', partial_text)
103
+ # print(f"[DEBUG] Formatted response: {cleaned_text.strip()}")
104
+ # return cleaned_text.strip()
105
+ # except (KeyError, IndexError) as e:
106
+ # print(f"[ERROR] Error formatting response: {e}")
107
+ # return f"Error: Missing key or index {e} in response."
108
 
109
  def generate_speech(text):
110
  print("[DEBUG] Generating speech from text.")
 
165
  response += token
166
  # Optional: print tokens as they arrive for debugging
167
  print(f"[DEBUG] Partial response token received: {token}")
168
+ yield response
169
  except Exception as e:
170
  print(f"[ERROR] Error during streaming response: {e}")
171
  return "I could not understand you. Please try again.", None
172
 
173
+ #formatted_output = format_generated_response(
174
+ # {"choices": [{"message": {"content": response}}]}
175
+ #)
176
 
177
  if response:
178
  # Append the conversation turn to history