Daniel Amendoeira commited on
Commit
406ca82
·
verified ·
1 Parent(s): 065b485

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +21 -2
tools.py CHANGED
@@ -4,6 +4,7 @@ import requests
4
  import openai
5
  import os
6
  import tempfile
 
7
  from urllib.parse import urlparse, parse_qs
8
  from openai import OpenAI
9
  from youtube_transcript_api import YouTubeTranscriptApi
@@ -95,7 +96,6 @@ def transcribe_audio(audio_file: str, file_extension: str) -> str:
95
  Args:
96
  audio_file (str): local file path to the audio file (.mp3, .m4a, etc.)
97
  file_extension (str): file extension of the audio, e.g. mp3
98
-
99
  Returns:
100
  str: The transcribed text from the audio.
101
  """
@@ -181,7 +181,6 @@ def webpage_content(url: str) -> str:
181
  """ Fetch text from a webpage or PDF file.
182
  Args:
183
  url (str): The URL of the webpage to fetch.
184
-
185
  Returns:
186
  str: Extracted text.
187
  """
@@ -204,3 +203,23 @@ def webpage_content(url: str) -> str:
204
 
205
  except Exception as e:
206
  return f"webpage_content failed: {e}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  import openai
5
  import os
6
  import tempfile
7
+ import pandas as pd
8
  from urllib.parse import urlparse, parse_qs
9
  from openai import OpenAI
10
  from youtube_transcript_api import YouTubeTranscriptApi
 
96
  Args:
97
  audio_file (str): local file path to the audio file (.mp3, .m4a, etc.)
98
  file_extension (str): file extension of the audio, e.g. mp3
 
99
  Returns:
100
  str: The transcribed text from the audio.
101
  """
 
181
  """ Fetch text from a webpage or PDF file.
182
  Args:
183
  url (str): The URL of the webpage to fetch.
 
184
  Returns:
185
  str: Extracted text.
186
  """
 
203
 
204
  except Exception as e:
205
  return f"webpage_content failed: {e}"
206
+
207
+ @tool
208
+ def read_excel(file_url: str) -> str:
209
+ """ Reads an Excel file from a URL and returns the content as CSV text.
210
+ Args:
211
+ file_url (str): URL to the Excel file (.xlsx, .xls)
212
+ Returns:
213
+ str: Content of the Excel file as CSV text.
214
+ """
215
+ try:
216
+ response = requests.get(file_url)
217
+ response.raise_for_status()
218
+
219
+ excel_content = BytesIO(response.content)
220
+ df = pd.read_excel(excel_content)
221
+
222
+ return df.to_csv(index=False) # convert dataframe to CSV string for easy processing
223
+
224
+ except Exception as e:
225
+ return f"read_excel failed: {str(e)}"