JabrilJacobs commited on
Commit
565eb66
·
verified ·
1 Parent(s): 94d5f0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -6,7 +6,7 @@ import pandas as pd
6
  from typing import TypedDict, Annotated, Union, Dict, Any
7
  from smolagents import DuckDuckGoSearchTool
8
  from langchain_community.tools import DuckDuckGoSearchRun
9
- from tools import get_hub_stats, analyze_image, read_excel_file
10
  from langchain.tools import Tool
11
  from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
12
  from langchain_openai import ChatOpenAI
@@ -33,7 +33,7 @@ class BasicAgent:
33
  class NewAgent:
34
  def __init__(self):
35
  print("NewAgent initialized.")
36
- def __call__(self, question: str, file_name: str = "") -> str:
37
  print(f"Agent received question (first 50 chars): {question[:50]}...")
38
 
39
  # Initialize the web search tool
@@ -56,6 +56,12 @@ class NewAgent:
56
  func=read_excel_file,
57
  description="Reads an Excel file and returns structured information about its contents."
58
  )
 
 
 
 
 
 
59
  # Generate the chat interface, including the tools
60
  tools = [
61
  search_tool,
@@ -63,6 +69,7 @@ class NewAgent:
63
  hub_stats_tool,
64
  image_analysis_tool,
65
  read_excel_tool,
 
66
  ]
67
  # llm = ChatOpenAI(model="gpt-4o")
68
  llm = ChatOpenAI(model="gpt-4.1")
@@ -76,12 +83,15 @@ class NewAgent:
76
  content=f"""
77
  You are a general AI assistant. I will ask you a question.
78
  If a file_name is provided, it indicates there's an associated file you may need to analyze.
 
 
79
  If you cannot find an answer, you may report your thoughts.
80
  If you find an answer, your response should only contain your final answer. Report nothing before or after this answer.
81
  YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
82
  If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
83
  If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
84
  If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
 
85
  Current file (if any): {file_name}"""
86
  )
87
  return {
@@ -173,7 +183,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
173
  print(f"Skipping item with missing task_id or question: {item}")
174
  continue
175
  try:
176
- submitted_answer = agent(question_text, file_name)
177
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
178
  results_log.append({"Task ID": task_id, "Question": question_text, "File": file_name, "Submitted Answer": submitted_answer})
179
  except Exception as e:
 
6
  from typing import TypedDict, Annotated, Union, Dict, Any
7
  from smolagents import DuckDuckGoSearchTool
8
  from langchain_community.tools import DuckDuckGoSearchRun
9
+ from tools import get_hub_stats, analyze_image, read_excel_file, download_file
10
  from langchain.tools import Tool
11
  from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
12
  from langchain_openai import ChatOpenAI
 
33
  class NewAgent:
34
  def __init__(self):
35
  print("NewAgent initialized.")
36
+ def __call__(self, question: str, file_name: str = "", task_id: str = "") -> str:
37
  print(f"Agent received question (first 50 chars): {question[:50]}...")
38
 
39
  # Initialize the web search tool
 
56
  func=read_excel_file,
57
  description="Reads an Excel file and returns structured information about its contents."
58
  )
59
+ # Initialize the Download File tool
60
+ download_file_tool = Tool(
61
+ name="download_file",
62
+ func=lambda task_id_filename: download_file(*task_id_filename.split(",", 1)),
63
+ description="Downloads a file associated with a task_id. Input should be 'task_id,filename'"
64
+ )
65
  # Generate the chat interface, including the tools
66
  tools = [
67
  search_tool,
 
69
  hub_stats_tool,
70
  image_analysis_tool,
71
  read_excel_tool,
72
+ download_file_tool,
73
  ]
74
  # llm = ChatOpenAI(model="gpt-4o")
75
  llm = ChatOpenAI(model="gpt-4.1")
 
83
  content=f"""
84
  You are a general AI assistant. I will ask you a question.
85
  If a file_name is provided, it indicates there's an associated file you may need to analyze.
86
+ You can download files using the download_file tool with the format 'task_id,filename'.
87
+ After downloading, you can analyze images with analyze_image or Excel files with read_excel_file.
88
  If you cannot find an answer, you may report your thoughts.
89
  If you find an answer, your response should only contain your final answer. Report nothing before or after this answer.
90
  YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
91
  If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
92
  If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
93
  If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
94
+ Current task_id: {task_id}
95
  Current file (if any): {file_name}"""
96
  )
97
  return {
 
183
  print(f"Skipping item with missing task_id or question: {item}")
184
  continue
185
  try:
186
+ submitted_answer = agent(question_text, file_name, task_id)
187
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
188
  results_log.append({"Task ID": task_id, "Question": question_text, "File": file_name, "Submitted Answer": submitted_answer})
189
  except Exception as e: