not-lain commited on
Commit
34ac220
·
verified ·
1 Parent(s): 014763e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -6
app.py CHANGED
@@ -26,8 +26,10 @@ cur_dir = os.path.dirname(os.path.abspath(__file__))
26
  def ovis_chat(message, history):
27
  try :
28
  image_input = Image.open(message["files"][0]).convert("RGB")
 
29
  except :
30
  image_input = None
 
31
  # preprocess inputs
32
  conversations = []
33
  response = ""
@@ -47,10 +49,9 @@ def ovis_chat(message, history):
47
  elif isinstance(msg[0],tuple):
48
  # case history pair is an image and user did not pass a new image
49
  # we override the none with the history image
50
- if image_input is None :
51
- # if someone uploads a file and not an image this will break
52
  image_input = Image.open(msg[0][0]).convert("RGB")
53
- print("conversations : ",conversations)
54
 
55
  text_input = text_input.replace(image_placeholder, '')
56
  conversations.append({
@@ -138,9 +139,6 @@ latex_delimiters_set = [{
138
  "display": True
139
  }]
140
 
141
- # send_click_event = send_btn.click(submit_chat, [chatbot, text_input], [chatbot, text_input]).then(ovis_chat,[chatbot, image_input],chatbot)
142
- # submit_event = text_input.submit(submit_chat, [chatbot, text_input], [chatbot, text_input]).then(ovis_chat,[chatbot, image_input],chatbot)
143
- # clear_btn.click(clear_chat, outputs=[chatbot, image_input, text_input])
144
 
145
  demo = gr.ChatInterface(fn=ovis_chat, textbox=gr.MultimodalTextbox(),multimodal=True)
146
  demo.launch(debug=True)
 
26
  def ovis_chat(message, history):
27
  try :
28
  image_input = Image.open(message["files"][0]).convert("RGB")
29
+ new_image = True
30
  except :
31
  image_input = None
32
+ new_image = False
33
  # preprocess inputs
34
  conversations = []
35
  response = ""
 
49
  elif isinstance(msg[0],tuple):
50
  # case history pair is an image and user did not pass a new image
51
  # we override the none with the history image
52
+ if new_image is False :
53
+ # always aim for the latest image in the history
54
  image_input = Image.open(msg[0][0]).convert("RGB")
 
55
 
56
  text_input = text_input.replace(image_placeholder, '')
57
  conversations.append({
 
139
  "display": True
140
  }]
141
 
 
 
 
142
 
143
  demo = gr.ChatInterface(fn=ovis_chat, textbox=gr.MultimodalTextbox(),multimodal=True)
144
  demo.launch(debug=True)