Tonic commited on
Commit
374896d
β€’
1 Parent(s): c8b3893

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -45,20 +45,25 @@ def _parse_text(text):
45
  return text
46
 
47
  def predict(_chatbot, task_history, user_input):
48
- query = user_input if user_input else task_history[-1][0]
 
 
 
 
 
49
  print("User: " + _parse_text(query))
 
50
  if not task_history:
51
  return _chatbot
 
52
  history_cp = copy.deepcopy(task_history)
53
  history_filter = []
54
  audio_idx = 1
55
  pre = ""
56
  last_audio = None
57
- for item in task_history:
58
- if len(item) != 2:
59
- print(f"Error: Expected a tuple of length 2, but got {item}")
60
- continue
61
- q, a = item
62
  if isinstance(q, (tuple, list)):
63
  last_audio = q[0]
64
  q = f'Audio {audio_idx}: <audio>{q[0]}</audio>'
 
45
  return text
46
 
47
  def predict(_chatbot, task_history, user_input):
48
+ # Ensure task_history is a list of tuples
49
+ if not isinstance(task_history, list) or not all(isinstance(item, tuple) and len(item) == 2 for item in task_history):
50
+ print("Error: task_history should be a list of tuples of length 2.")
51
+ return _chatbot
52
+
53
+ query = user_input if user_input else (task_history[-1][0] if task_history else "")
54
  print("User: " + _parse_text(query))
55
+
56
  if not task_history:
57
  return _chatbot
58
+
59
  history_cp = copy.deepcopy(task_history)
60
  history_filter = []
61
  audio_idx = 1
62
  pre = ""
63
  last_audio = None
64
+
65
+ for item in history_cp:
66
+ q, a = item
 
 
67
  if isinstance(q, (tuple, list)):
68
  last_audio = q[0]
69
  q = f'Audio {audio_idx}: <audio>{q[0]}</audio>'