Tonic commited on
Commit
c8b3893
β€’
1 Parent(s): 4591b17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -54,10 +54,10 @@ def predict(_chatbot, task_history, user_input):
54
  audio_idx = 1
55
  pre = ""
56
  last_audio = None
57
- for i, item in enumerate(history_cp):
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]
@@ -115,28 +115,24 @@ def regenerate(_chatbot, task_history):
115
  _chatbot.append((chatbot_item[0], None))
116
  return predict(_chatbot, task_history)
117
 
 
118
  def add_text(history, task_history, text):
119
- history = history + [(_parse_text(text), None)]
120
- task_history = task_history + [(text, None)]
121
  return history, task_history, ""
122
 
123
  def add_file(history, task_history, file):
124
- history = history + [((file.name,), None)]
125
- task_history = task_history + [((file.name,), None)]
126
  return history, task_history
127
 
128
  def add_mic(history, task_history, file):
129
  if file is None:
130
  return history, task_history
131
- os.rename(file, file + '.wav')
132
- print("add_mic file:", file)
133
- print("add_mic history:", history)
134
- print("add_mic task_history:", task_history)
135
- # history = history + [((file.name,), None)]
136
- # task_history = task_history + [((file.name,), None)]
137
- task_history = task_history + [((file + '.wav',), None)]
138
- history = history + [((file + '.wav',), None)]
139
- print("task_history", task_history)
140
  return history, task_history
141
 
142
  def reset_user_input():
 
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]
 
115
  _chatbot.append((chatbot_item[0], None))
116
  return predict(_chatbot, task_history)
117
 
118
+
119
  def add_text(history, task_history, text):
120
+ history.append((_parse_text(text), None))
121
+ task_history.append((text, None))
122
  return history, task_history, ""
123
 
124
  def add_file(history, task_history, file):
125
+ history.append(((file.name,), None))
126
+ task_history.append(((file.name,), None))
127
  return history, task_history
128
 
129
  def add_mic(history, task_history, file):
130
  if file is None:
131
  return history, task_history
132
+ file_with_extension = file + '.wav'
133
+ os.rename(file, file_with_extension)
134
+ history.append(((file_with_extension,), None))
135
+ task_history.append(((file_with_extension,), None))
 
 
 
 
 
136
  return history, task_history
137
 
138
  def reset_user_input():