Tonic commited on
Commit
c6878b9
·
1 Parent(s): 6f1dcd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -134,32 +134,36 @@ def predict(_chatbot, task_history) -> tuple:
134
  query = [{'image': chat_query}]
135
  else:
136
  query = [{'text': _parse_text(chat_query)}]
137
-
138
  inputs = tokenizer.from_list_format(query)
139
  tokenized_inputs = tokenizer(inputs, return_tensors='pt')
140
  tokenized_inputs = tokenized_inputs.to(model.device)
141
  pred = model.generate(**tokenized_inputs)
142
  response = tokenizer.decode(pred.cpu()[0], skip_special_tokens=False)
143
-
144
  if 'image' in query[0]:
145
  print("Model response:", response)
146
-
147
  if 'image' in query[0]:
148
  image = tokenizer.draw_bbox_on_latest_picture(response)
149
  if image is not None:
150
  image_path = save_image(image, uploaded_file_dir)
151
  _chatbot[-1] = (chat_query, (image_path,))
152
- task_history[-1] = (chat_query, image_path)
 
 
 
153
  else:
154
- _chatbot[-1] = (chat_query, response) # Make sure this is a tuple of two elements
155
- task_history[-1] = (chat_query, response)
 
 
 
156
  else:
157
  _chatbot[-1] = (chat_query, response)
158
- task_history[-1] = (chat_query, response)
159
-
 
 
160
  return _chatbot, task_history
161
 
162
-
163
  def save_uploaded_image(image_file, upload_dir):
164
  if image is None:
165
  return None
 
134
  query = [{'image': chat_query}]
135
  else:
136
  query = [{'text': _parse_text(chat_query)}]
 
137
  inputs = tokenizer.from_list_format(query)
138
  tokenized_inputs = tokenizer(inputs, return_tensors='pt')
139
  tokenized_inputs = tokenized_inputs.to(model.device)
140
  pred = model.generate(**tokenized_inputs)
141
  response = tokenizer.decode(pred.cpu()[0], skip_special_tokens=False)
 
142
  if 'image' in query[0]:
143
  print("Model response:", response)
 
144
  if 'image' in query[0]:
145
  image = tokenizer.draw_bbox_on_latest_picture(response)
146
  if image is not None:
147
  image_path = save_image(image, uploaded_file_dir)
148
  _chatbot[-1] = (chat_query, (image_path,))
149
+ if task_history:
150
+ task_history[-1] = (chat_query, image_path)
151
+ else:
152
+ task_history.append((chat_query, image_path))
153
  else:
154
+ _chatbot[-1] = (chat_query, response)
155
+ if task_history:
156
+ task_history[-1] = (chat_query, response)
157
+ else:
158
+ task_history.append((chat_query, response))
159
  else:
160
  _chatbot[-1] = (chat_query, response)
161
+ if task_history:
162
+ task_history[-1] = (chat_query, response)
163
+ else:
164
+ task_history.append((chat_query, response))
165
  return _chatbot, task_history
166
 
 
167
  def save_uploaded_image(image_file, upload_dir):
168
  if image is None:
169
  return None