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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -45,7 +45,7 @@ def _parse_text(text):
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
@@ -104,9 +104,11 @@ def predict(_chatbot, task_history, user_input):
104
  full_response = _parse_text(response)
105
  task_history[-1] = (query, full_response)
106
  print("Qwen-Audio-Chat: " + _parse_text(full_response))
 
107
  return _chatbot
108
 
109
  def regenerate(_chatbot, task_history):
 
110
  if not task_history:
111
  return _chatbot
112
  item = task_history[-1]
@@ -115,36 +117,44 @@ def regenerate(_chatbot, task_history):
115
  task_history[-1] = (item[0], None)
116
  chatbot_item = _chatbot.pop(-1)
117
  if chatbot_item[0] is None:
118
- _chatbot[-1] = (_chatbot[-1][0], None)
119
  else:
120
  _chatbot.append((chatbot_item[0], None))
 
121
  return predict(_chatbot, task_history)
122
 
123
-
124
  def add_text(history, task_history, text):
 
125
  history.append((_parse_text(text), None))
126
  task_history.append((text, None))
 
127
  return history, task_history, ""
128
 
129
  def add_file(history, task_history, file):
 
130
  history.append(((file.name,), None))
131
  task_history.append(((file.name,), None))
 
132
  return history, task_history
133
 
134
  def add_mic(history, task_history, file):
 
135
  if file is None:
136
  return history, task_history
137
  file_with_extension = file + '.wav'
138
  os.rename(file, file_with_extension)
139
  history.append(((file_with_extension,), None))
140
  task_history.append(((file_with_extension,), None))
 
141
  return history, task_history
142
 
143
  def reset_user_input():
144
  return gr.update(value="")
145
 
146
  def reset_state(task_history):
 
147
  task_history.clear()
 
148
  return []
149
 
150
  iface = gr.Interface(
 
45
  return text
46
 
47
  def predict(_chatbot, task_history, user_input):
48
+ print("Predict - Start: task_history =", task_history)
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
 
104
  full_response = _parse_text(response)
105
  task_history[-1] = (query, full_response)
106
  print("Qwen-Audio-Chat: " + _parse_text(full_response))
107
+ print("Predict - End: task_history =", task_history)
108
  return _chatbot
109
 
110
  def regenerate(_chatbot, task_history):
111
+ print("Regenerate - Start: task_history =", task_history)
112
  if not task_history:
113
  return _chatbot
114
  item = task_history[-1]
 
117
  task_history[-1] = (item[0], None)
118
  chatbot_item = _chatbot.pop(-1)
119
  if chatbot_item[0] is None:
120
+ _chatbot[-1] = (_chatbot[-1][0], None)
121
  else:
122
  _chatbot.append((chatbot_item[0], None))
123
+ print("Regenerate - End: task_history =", task_history)
124
  return predict(_chatbot, task_history)
125
 
 
126
  def add_text(history, task_history, text):
127
+ print("Add Text - Before: task_history =", task_history)
128
  history.append((_parse_text(text), None))
129
  task_history.append((text, None))
130
+ print("Add Text - End: task_history =", task_history)
131
  return history, task_history, ""
132
 
133
  def add_file(history, task_history, file):
134
+ print("Add File - Before: task_history =", task_history)
135
  history.append(((file.name,), None))
136
  task_history.append(((file.name,), None))
137
+ print("Add File - After: task_history =", task_history)
138
  return history, task_history
139
 
140
  def add_mic(history, task_history, file):
141
+ print("Add Mic - Before: task_history =", task_history)
142
  if file is None:
143
  return history, task_history
144
  file_with_extension = file + '.wav'
145
  os.rename(file, file_with_extension)
146
  history.append(((file_with_extension,), None))
147
  task_history.append(((file_with_extension,), None))
148
+ print("Add Mic - After: task_history =", task_history)
149
  return history, task_history
150
 
151
  def reset_user_input():
152
  return gr.update(value="")
153
 
154
  def reset_state(task_history):
155
+ print("Reset State - Before: task_history =", task_history
156
  task_history.clear()
157
+ print("Reset State - After: task_history =", task_history)
158
  return []
159
 
160
  iface = gr.Interface(