BenjaminKaindu0506 commited on
Commit
c989430
·
verified ·
1 Parent(s): 489fea7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
6
- from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, Tool, tool,PythonInterpreterTool, VisitWebpageTool, FinalAnswerTool, load_tool
7
 
8
 
9
  # (Keep Constants as is)
@@ -75,19 +75,22 @@ class BasicAgent:
75
  """
76
  if file_path.endswith(".csv"):
77
  df = pd.read_csv(file_path)
78
- elif file_path.edswith(".pdf"):
79
- df = pd.read_pdf(file_path)
80
  else:
81
  df = pd.read_excel(file_path)
82
  return df.to_string()
83
-
84
- #image_analysis_tool = Tool.from_space(
85
- #"nvidia/LocateAnything",
86
- #name="image_analyser",
87
- #description="Analyses images to locate and describe objects in them.",
88
- #trust_remote_code=True,
89
- #)
90
-
 
 
 
 
 
91
  #pdf_tool = load_tool(
92
  #"matterattetatte/pdf-upload-extractor-tool",
93
  # trust_remote_code = True
@@ -100,10 +103,12 @@ class BasicAgent:
100
  FinalAnswerTool(),
101
  #pdf_tool,
102
  fetch_task_file,
 
103
  read_spreadsheet,
104
  get_youtube_transcript,
105
  ],
106
  model= InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct"),
 
107
  #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.",
108
  max_steps=20,
109
  )
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool,Tool,tool,PythonInterpreterTool,VisitWebpageTool,FinalAnswerTool,load_tool
7
 
8
 
9
  # (Keep Constants as is)
 
75
  """
76
  if file_path.endswith(".csv"):
77
  df = pd.read_csv(file_path)
 
 
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
  #pdf_tool = load_tool(
95
  #"matterattetatte/pdf-upload-extractor-tool",
96
  # trust_remote_code = True
 
103
  FinalAnswerTool(),
104
  #pdf_tool,
105
  fetch_task_file,
106
+ read_pdf,
107
  read_spreadsheet,
108
  get_youtube_transcript,
109
  ],
110
  model= InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct"),
111
+ additional_authorized_imports=["pandas", "requests", "re"],
112
  #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.",
113
  max_steps=20,
114
  )