Tonic commited on
Commit
44de538
β€’
1 Parent(s): 8399349

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -7,6 +7,7 @@ import re
7
  import secrets
8
  from pathlib import Path
9
  from pydub import AudioSegment
 
10
 
11
  torch.manual_seed(420)
12
  tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-Audio-Chat", trust_remote_code=True)
@@ -49,6 +50,9 @@ def predict(_chatbot, task_history, user_input):
49
  print("Type of task_history:", type(task_history))
50
  if task_history is None or not isinstance(task_history, list):
51
  task_history = []
 
 
 
52
  print("Predict - Start: task_history =", task_history)
53
  if not isinstance(task_history, list) or not all(isinstance(item, tuple) and len(item) == 2 for item in task_history):
54
  print("Error: task_history should be a list of tuples of length 2.")
@@ -109,7 +113,17 @@ def predict(_chatbot, task_history, user_input):
109
  print("Predict - End: task_history =", task_history)
110
  return _chatbot[-1][1], _chatbot
111
 
112
-
 
 
 
 
 
 
 
 
 
 
113
  def regenerate(_chatbot, task_history):
114
  if task_history is None or not isinstance(task_history, list):
115
  task_history = []
 
7
  import secrets
8
  from pathlib import Path
9
  from pydub import AudioSegment
10
+ import ast
11
 
12
  torch.manual_seed(420)
13
  tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-Audio-Chat", trust_remote_code=True)
 
50
  print("Type of task_history:", type(task_history))
51
  if task_history is None or not isinstance(task_history, list):
52
  task_history = []
53
+ else
54
+ task_history = parse_task_history(task_history)
55
+
56
  print("Predict - Start: task_history =", task_history)
57
  if not isinstance(task_history, list) or not all(isinstance(item, tuple) and len(item) == 2 for item in task_history):
58
  print("Error: task_history should be a list of tuples of length 2.")
 
113
  print("Predict - End: task_history =", task_history)
114
  return _chatbot[-1][1], _chatbot
115
 
116
+ def parse_task_history(task_history_str):
117
+ try:
118
+ parsed_task_history = ast.literal_eval(task_history_str)
119
+ if isinstance(parsed_task_history, list) and all(isinstance(item, tuple) and len(item) == 2 for item in parsed_task_history):
120
+ return parsed_task_history
121
+ else:
122
+ raise ValueError("Parsed task history is not a list of tuples")
123
+ except Exception as e:
124
+ print(f"Error parsing task history: {e}")
125
+ return []
126
+
127
  def regenerate(_chatbot, task_history):
128
  if task_history is None or not isinstance(task_history, list):
129
  task_history = []