BenjaminKaindu0506 commited on
Commit
85904f7
·
verified ·
1 Parent(s): 9121c5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -78,25 +78,27 @@ class BasicAgent:
78
  else:
79
  df = pd.read_excel(file_path)
80
  return df.to_string()
81
-
82
- @tool
83
- def read_pdf(file_path: str) -> str:
84
- """
85
- Extracts text from a PDF file.
86
- Args:
87
- file_path: Local path to the PDF file.
88
- Returns:
89
- The extracted text content
90
- """
91
- from pypdf import PdfReader
92
- reader = PdfReader(file_path)
93
- return "\n".join(page.extract_text() or "" for page in reader.pages)
94
- print(read_pdf.description)
95
- print(read_pdf.inputs)
 
96
  #pdf_tool = load_tool(
97
  #"matterattetatte/pdf-upload-extractor-tool",
98
  # trust_remote_code = True
99
  #)
 
100
  self.agent = CodeAgent(
101
  tools=[
102
  DuckDuckGoSearchTool(),
@@ -110,7 +112,7 @@ class BasicAgent:
110
  get_youtube_transcript,
111
  ],
112
  model= InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct"),
113
- additional_authorized_imports=["pandas", "requests", "re"],
114
  #instructions = "If the question includes a task_id and mentions a file, call fetch_task_file first; route YouTube URLs to get_youtube_transcript, other URLs to visit_webpage, PDFs to pdf_tool, and spreadsheets to read_spreadsheet, using web_search only when no URL or file is given,then respond with only the exact final answer value, no explanation, no prefix.",
115
  max_steps=20,
116
  )
 
78
  else:
79
  df = pd.read_excel(file_path)
80
  return df.to_string()
81
+
82
+ class ReadPDFTool(Tool):
83
+ name = "read_pdf"
84
+ description = "Extracts text from a PDF file."
85
+ inputs = {
86
+ "file_path": {
87
+ "type": "string",
88
+ "description": "Local path to the PDF file.",
89
+ }
90
+ }
91
+ output_type = "string"
92
+
93
+ def forward(self, file_path: str) -> str:
94
+ from pypdf import PdfReader
95
+ reader = PdfReader(file_path)
96
+ return "\n".join(page.extract_text() or "" for page in reader.pages)
97
  #pdf_tool = load_tool(
98
  #"matterattetatte/pdf-upload-extractor-tool",
99
  # trust_remote_code = True
100
  #)
101
+ read_pdf = ReadPDFTool()
102
  self.agent = CodeAgent(
103
  tools=[
104
  DuckDuckGoSearchTool(),
 
112
  get_youtube_transcript,
113
  ],
114
  model= InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct"),
115
+ #additional_authorized_imports=["pandas", "requests", "re"],
116
  #instructions = "If the question includes a task_id and mentions a file, call fetch_task_file first; route YouTube URLs to get_youtube_transcript, other URLs to visit_webpage, PDFs to pdf_tool, and spreadsheets to read_spreadsheet, using web_search only when no URL or file is given,then respond with only the exact final answer value, no explanation, no prefix.",
117
  max_steps=20,
118
  )