amarax commited on
Commit
29537a2
·
1 Parent(s): ff3a5fb

Working immediate input from chat

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -72,7 +72,6 @@ def cut_dialogue_history(history_memory, keep_last_n_words=400):
72
 
73
  class ConversationBot:
74
  def __init__(self, load_dict):
75
- # load_dict = {'VisualQuestionAnswering':'cuda:0', 'ImageCaptioning':'cuda:1',...}
76
  print(f"Initializing VisualChatGPT, load_dict={load_dict}")
77
  if 'ImageCaptioning' not in load_dict:
78
  raise ValueError("You have to load ImageCaptioning as a basic function for VisualChatGPT")
@@ -94,7 +93,9 @@ class ConversationBot:
94
  res = self.agent({"input": text})
95
  res['output'] = res['output'].replace("\\", "/")
96
  response = re.sub('(image/\S*png)', lambda m: f'![](/file={m.group(0)})*{m.group(0)}*', res['output'])
 
97
  state = state + [(text, response)]
 
98
  print(f"\nProcessed run_text, Input text: {text}\nCurrent state: {state}\n"
99
  f"Current Memory: {self.agent.memory.buffer}")
100
  return state, state
@@ -197,19 +198,21 @@ with gr.Blocks(css="#chatbot {overflow:auto; height:500px;}") as demo:
197
  inputs=txt
198
  )
199
 
200
- gr.HTML('''<br><br><br><center>You can duplicate this Space to skip the queue:
201
- <a href="https://huggingface.co/spaces/microsoft/visual_chatgpt?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a><br>
202
- </center>''')
203
-
204
-
205
-
206
  if not OPENAI_API_KEY:
207
  openai_api_key_textbox.submit(bot.init_agent, [openai_api_key_textbox], [input_raws])
208
 
 
 
 
 
 
209
  txt.submit(bot.run_text, [txt, state], [chatbot, state])
210
  txt.submit(lambda: "", None, txt)
 
 
211
  run.click(bot.run_text, [txt, state], [chatbot, state])
212
  run.click(lambda: "", None, txt)
 
213
  btn.upload(bot.run_image, [btn, state, txt], [chatbot, state, txt])
214
  clear.click(bot.memory.clear)
215
  clear.click(lambda: [], None, chatbot)
 
72
 
73
  class ConversationBot:
74
  def __init__(self, load_dict):
 
75
  print(f"Initializing VisualChatGPT, load_dict={load_dict}")
76
  if 'ImageCaptioning' not in load_dict:
77
  raise ValueError("You have to load ImageCaptioning as a basic function for VisualChatGPT")
 
93
  res = self.agent({"input": text})
94
  res['output'] = res['output'].replace("\\", "/")
95
  response = re.sub('(image/\S*png)', lambda m: f'![](/file={m.group(0)})*{m.group(0)}*', res['output'])
96
+
97
  state = state + [(text, response)]
98
+
99
  print(f"\nProcessed run_text, Input text: {text}\nCurrent state: {state}\n"
100
  f"Current Memory: {self.agent.memory.buffer}")
101
  return state, state
 
198
  inputs=txt
199
  )
200
 
 
 
 
 
 
 
201
  if not OPENAI_API_KEY:
202
  openai_api_key_textbox.submit(bot.init_agent, [openai_api_key_textbox], [input_raws])
203
 
204
+ def update_text(text, state):
205
+ chat = state + [(text, None)]
206
+ return chat
207
+
208
+ txt.submit(update_text, [txt, state], [chatbot])
209
  txt.submit(bot.run_text, [txt, state], [chatbot, state])
210
  txt.submit(lambda: "", None, txt)
211
+
212
+ run.click(update_text, [txt, state], [chatbot])
213
  run.click(bot.run_text, [txt, state], [chatbot, state])
214
  run.click(lambda: "", None, txt)
215
+
216
  btn.upload(bot.run_image, [btn, state, txt], [chatbot, state, txt])
217
  clear.click(bot.memory.clear)
218
  clear.click(lambda: [], None, chatbot)