amarax commited on
Commit
00eb369
·
1 Parent(s): 617f9b6

Clicking the chatbot message now appends the image filename, if there's one.

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -130,7 +130,7 @@ class ConversationBot:
130
  return state, state, f'{txt} {image_filename} '
131
 
132
  def init_agent(self, openai_api_key):
133
- self.llm = OpenAI(temperature=0.5, max_tokens=512, openai_api_key=openai_api_key)
134
  self.agent = initialize_agent(
135
  self.tools,
136
  self.llm,
@@ -218,6 +218,14 @@ with gr.Blocks(css="#chatbot {overflow:auto; height:500px;} .message img {max-wi
218
  run.click(bot.run_text, [txt, state], [chatbot, state])
219
  run.click(lambda: "", None, txt)
220
 
 
 
 
 
 
 
 
 
221
  btn.upload(bot.run_image, [btn, state, txt], [chatbot, state, txt])
222
 
223
  clear.click(bot.memory.clear)
 
130
  return state, state, f'{txt} {image_filename} '
131
 
132
  def init_agent(self, openai_api_key):
133
+ self.llm = OpenAI(temperature=0, max_tokens=512, openai_api_key=openai_api_key)
134
  self.agent = initialize_agent(
135
  self.tools,
136
  self.llm,
 
218
  run.click(bot.run_text, [txt, state], [chatbot, state])
219
  run.click(lambda: "", None, txt)
220
 
221
+ def refer_to_image(evt: gr.SelectData, text):
222
+ result = re.search(r"image\/\S+\.png", evt.value)
223
+ if result:
224
+ text = text + " " + result.group() + " "
225
+ return text
226
+
227
+ chatbot.select(refer_to_image, [txt], [txt])
228
+
229
  btn.upload(bot.run_image, [btn, state, txt], [chatbot, state, txt])
230
 
231
  clear.click(bot.memory.clear)