qnguyen3 commited on
Commit
2002e2a
·
verified ·
1 Parent(s): 08bc998

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -22,7 +22,7 @@ model.to("cuda:0")
22
 
23
  @spaces.GPU
24
  def bot_streaming(message, history):
25
- chat_history = []
26
  if message["files"]:
27
  image = message["files"][-1]["path"]
28
  else:
@@ -32,21 +32,21 @@ def bot_streaming(message, history):
32
  image_turn = i
33
 
34
  if len(history) > 0 and image is not None:
35
- chat_history.append({"role": "user", "content": f'<image>\n{history[1][0]}'})
36
- chat_history.append({"role": "assistant", "content": history[1][1] })
37
  for human, assistant in history[2:]:
38
- chat_history.append({"role": "user", "content": human })
39
- chat_history.append({"role": "assistant", "content": assistant })
40
- chat_history.append({"role": "user", "content": message['text']})
41
  elif len(history) > 0 and image is None:
42
  for human, assistant in history:
43
- chat_history.append({"role": "user", "content": human })
44
- chat_history.append({"role": "assistant", "content": assistant })
45
- chat_history.append({"role": "user", "content": message['text']})
46
  elif len(history) == 0 and image is not None:
47
- chat_history.append({"role": "user", "content": f"<image>\n{message['text']}"})
48
  elif len(history) == 0 and image is None:
49
- chat_history.append({"role": "user", "content": message['text'] })
50
 
51
  # if image is None:
52
  # gr.Error("You need to upload an image for LLaVA to work.")
 
22
 
23
  @spaces.GPU
24
  def bot_streaming(message, history):
25
+ messages = []
26
  if message["files"]:
27
  image = message["files"][-1]["path"]
28
  else:
 
32
  image_turn = i
33
 
34
  if len(history) > 0 and image is not None:
35
+ messages.append({"role": "user", "content": f'<image>\n{history[1][0]}'})
36
+ messages.append({"role": "assistant", "content": history[1][1] })
37
  for human, assistant in history[2:]:
38
+ messages.append({"role": "user", "content": human })
39
+ messages.append({"role": "assistant", "content": assistant })
40
+ messages.append({"role": "user", "content": message['text']})
41
  elif len(history) > 0 and image is None:
42
  for human, assistant in history:
43
+ messages.append({"role": "user", "content": human })
44
+ messages.append({"role": "assistant", "content": assistant })
45
+ messages.append({"role": "user", "content": message['text']})
46
  elif len(history) == 0 and image is not None:
47
+ messages.append({"role": "user", "content": f"<image>\n{message['text']}"})
48
  elif len(history) == 0 and image is None:
49
+ messages.append({"role": "user", "content": message['text'] })
50
 
51
  # if image is None:
52
  # gr.Error("You need to upload an image for LLaVA to work.")