Vinay Kerai commited on
Commit
b762719
·
1 Parent(s): 2051cf0

try adding image tool

Browse files
Files changed (2) hide show
  1. agent.py +37 -1
  2. app.py +1 -1
agent.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import re
2
  from dotenv import load_dotenv
3
  import requests
@@ -154,6 +155,40 @@ def transcribe_audio(url: str) -> str:
154
  except Exception as e:
155
  return f"An error occured using transcribe_audio tool: {e}"
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  def view_py_file(url: str) -> str:
158
  """
159
  A tool to view the contents of a python file (.py)
@@ -172,7 +207,8 @@ def view_py_file(url: str) -> str:
172
  return response.text
173
  except Exception as e:
174
  return f"An error occured using view_py_file tool: {e}"
175
-
 
176
  def view_xlsx_file(url: str) -> str:
177
  """
178
  A tool to view the contents of an excel file (.xlsx)
 
1
+ import base64
2
  import re
3
  from dotenv import load_dotenv
4
  import requests
 
155
  except Exception as e:
156
  return f"An error occured using transcribe_audio tool: {e}"
157
 
158
+ @tool(response_format='content_and_artifact')
159
+ def view_png_file(url: str) -> str:
160
+ """
161
+ A tool to view the contents of an image file (.png)
162
+
163
+ Args:
164
+ url (str): link to image file (.png)
165
+
166
+ Returns:
167
+ str: image contents
168
+ """
169
+ try:
170
+ # fetch the image
171
+ response = requests.get(url)
172
+ response.raise_for_status()
173
+
174
+ # convert image bytes to base64
175
+ image = base64.b64encode(response.content).decode('utf-8')
176
+
177
+ # text + image artifact
178
+ return (
179
+ "Here is the image.",
180
+ [{
181
+ "type": "image",
182
+ "source": {
183
+ "type": "url",
184
+ "url": image,
185
+ }
186
+ }]
187
+ )
188
+ except Exception as e:
189
+ return f"An error occured using view_png_file tool: {e}"
190
+
191
+ @tool
192
  def view_py_file(url: str) -> str:
193
  """
194
  A tool to view the contents of a python file (.py)
 
207
  return response.text
208
  except Exception as e:
209
  return f"An error occured using view_py_file tool: {e}"
210
+
211
+ @tool
212
  def view_xlsx_file(url: str) -> str:
213
  """
214
  A tool to view the contents of an excel file (.xlsx)
app.py CHANGED
@@ -85,7 +85,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
85
  # if question has an attached file, add the URL to the question prompt
86
  file_ext = file_name.split('.')[-1]
87
  file_url = f"{api_url}/files/{task_id}"
88
- question_text += f'\nFILE URL ({file_ext}): "{file_url}"'
89
 
90
  try:
91
  submitted_answer = agent(question_text)
 
85
  # if question has an attached file, add the URL to the question prompt
86
  file_ext = file_name.split('.')[-1]
87
  file_url = f"{api_url}/files/{task_id}"
88
+ question_text += f'\nFILE URL (.{file_ext}): "{file_url}"'
89
 
90
  try:
91
  submitted_answer = agent(question_text)