SinghAbhinav04 commited on
Commit
b920dbb
·
verified ·
1 Parent(s): 7162e5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -196,8 +196,12 @@ class InternVLChatBot:
196
  chat_history = []
197
  if history:
198
  for item in history:
199
- if len(item) == 2:
200
- chat_history.append((item[0], item[1]))
 
 
 
 
201
 
202
  # Generate response
203
  if num_patches_list is not None:
@@ -221,10 +225,11 @@ class InternVLChatBot:
221
  )
222
 
223
  # Update history
224
- history.append([message, response])
225
-
226
  return "", history, None, None
227
 
 
228
  except Exception as e:
229
  logger.error(f"Error in chat: {str(e)}")
230
  error_msg = f"Sorry, I encountered an error: {str(e)}"
 
196
  chat_history = []
197
  if history:
198
  for item in history:
199
+ if isinstance(item, dict) and "role" in item:
200
+ if item["role"] == "user":
201
+ last_user = item["content"]
202
+ elif item["role"] == "assistant":
203
+ chat_history.append((last_user, item["content"]))
204
+
205
 
206
  # Generate response
207
  if num_patches_list is not None:
 
225
  )
226
 
227
  # Update history
228
+ history.append({"role": "user", "content": message})
229
+ history.append({"role": "assistant", "content": response})
230
  return "", history, None, None
231
 
232
+
233
  except Exception as e:
234
  logger.error(f"Error in chat: {str(e)}")
235
  error_msg = f"Sorry, I encountered an error: {str(e)}"