zxcgqq commited on
Commit
4729025
·
1 Parent(s): 51f0ac5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -126,19 +126,13 @@ class ConversationBot:
126
  f"Current Memory: {self.agent.memory.buffer}")
127
  return state, state
128
 
129
- def run_image(self, image, state, txt, lang):
130
- if lang == 'Chinese':
131
- Human_prompt = f'\nHuman: 提供一张名为 123的图片。它的描述是: 一只猫和一只狗。 这些信息帮助你理解这个图像,但是你应该使用工具来完成下面的任务,而不是直接从我的描述中想象。 如果你明白了, 说 \"收到\". \n'
132
- AI_prompt = "收到。 "
133
- else:
134
- Human_prompt = f'\nHuman: provide a figure named {image_filename}. The description is: {description}. This information helps you to understand this image, but you should use tools to finish following tasks, rather than directly imagine from my description. If you understand, say \"Received\". \n'
135
- AI_prompt = "Received. "
136
  self.agent.memory.buffer = self.agent.memory.buffer + Human_prompt + 'AI: ' + AI_prompt
137
- state = state + [(f"![](/file={image_filename})*{image_filename}*", AI_prompt)]
138
- print(f"\nProcessed run_image, Input image: {image_filename}\nCurrent state: {state}\n"
139
- f"Current Memory: {self.agent.memory.buffer}")
140
- return state, state, f'{txt} {image_filename} '
141
-
142
  def init_agent(self, openai_api_key, lang):
143
  self.memory.clear()
144
  if lang=='English':
@@ -191,7 +185,7 @@ with gr.Blocks(css="#chatbot {overflow:auto; height:500px;}") as demo:
191
  with gr.Column(scale=0.10, min_width=0):
192
  clear = gr.Button("🔄Clear️")
193
  with gr.Column(scale=0.10, min_width=0):
194
- btn = gr.UploadButton("🖼️Upload", file_types=["image"])
195
 
196
  gr.Examples(
197
  examples=["Generate a figure of a cat running in the garden",
@@ -216,6 +210,7 @@ with gr.Blocks(css="#chatbot {overflow:auto; height:500px;}") as demo:
216
  txt.submit(bot.run_text, [txt, state], [chatbot, state])
217
  txt.submit(lambda: "", None, txt)
218
  run.click(bot.run_text, [txt, state], [chatbot, state])
 
219
  run.click(lambda: "", None, txt)
220
  clear.click(bot.memory.clear)
221
  clear.click(lambda: [], None, chatbot)
 
126
  f"Current Memory: {self.agent.memory.buffer}")
127
  return state, state
128
 
129
+ def run_image(self):
130
+
131
+ Human_prompt = f'\nHuman: 提供一张名为 123的图片。它的描述是: 一只猫和一只狗。 这些信息帮助你理解这个图像,但是你应该使用工具来完成下面的任务,而不是直接从我的描述中想象。 如果你明白了, 说 \"收到\". \n'
132
+ AI_prompt = "收到。 "
 
 
 
133
  self.agent.memory.buffer = self.agent.memory.buffer + Human_prompt + 'AI: ' + AI_prompt
134
+ print(f"Current Memory: {self.agent.memory.buffer}")
135
+
 
 
 
136
  def init_agent(self, openai_api_key, lang):
137
  self.memory.clear()
138
  if lang=='English':
 
185
  with gr.Column(scale=0.10, min_width=0):
186
  clear = gr.Button("🔄Clear️")
187
  with gr.Column(scale=0.10, min_width=0):
188
+ btn = gr.Button("🖼️Upload")
189
 
190
  gr.Examples(
191
  examples=["Generate a figure of a cat running in the garden",
 
210
  txt.submit(bot.run_text, [txt, state], [chatbot, state])
211
  txt.submit(lambda: "", None, txt)
212
  run.click(bot.run_text, [txt, state], [chatbot, state])
213
+ btn.click(bot.run_image, [txt, state], [chatbot, state])
214
  run.click(lambda: "", None, txt)
215
  clear.click(bot.memory.clear)
216
  clear.click(lambda: [], None, chatbot)