Spaces:
Sleeping
Sleeping
Commit
·
e327cd6
1
Parent(s):
e75b733
corrections
Browse files- agent/gaia_agent.py +5 -0
- app.py +5 -5
- tools/excel_sum_tool.py +17 -0
- tools/vegetable_classifier_tool.py +17 -0
agent/gaia_agent.py
CHANGED
|
@@ -3,6 +3,9 @@ from langchain.agents import initialize_agent, AgentType
|
|
| 3 |
from langchain.tools import Tool
|
| 4 |
#from langchain_community.llms import OpenAI
|
| 5 |
from tools.wikipedia_tool import wiki_search
|
|
|
|
|
|
|
|
|
|
| 6 |
from tools.audio_transcriber import transcribe_audio
|
| 7 |
from tools.file_parser import parse_file_and_summarize
|
| 8 |
from tools.image_chess_solver import solve_chess_image
|
|
@@ -23,6 +26,8 @@ def create_langchain_agent() -> AgentExecutor:
|
|
| 23 |
Tool(name="audio_transcriber", func=transcribe_audio, description="Transcribe uploaded audio files."),
|
| 24 |
Tool(name="chess_image_solver", func=solve_chess_image, description="Solve chess puzzles from images."),
|
| 25 |
Tool(name="file_parser", func=parse_file_and_summarize, description="Parse and analyze Excel or CSV files."),
|
|
|
|
|
|
|
| 26 |
]
|
| 27 |
|
| 28 |
agent = initialize_agent(
|
|
|
|
| 3 |
from langchain.tools import Tool
|
| 4 |
#from langchain_community.llms import OpenAI
|
| 5 |
from tools.wikipedia_tool import wiki_search
|
| 6 |
+
from tools.vegetable_classifier_tool import vegetable_classifier_2022
|
| 7 |
+
from tools.vegetable_classifier_tool import vegetable_classifier_2022
|
| 8 |
+
from tools.excel_sum_tool import excel_food_sales_sum
|
| 9 |
from tools.audio_transcriber import transcribe_audio
|
| 10 |
from tools.file_parser import parse_file_and_summarize
|
| 11 |
from tools.image_chess_solver import solve_chess_image
|
|
|
|
| 26 |
Tool(name="audio_transcriber", func=transcribe_audio, description="Transcribe uploaded audio files."),
|
| 27 |
Tool(name="chess_image_solver", func=solve_chess_image, description="Solve chess puzzles from images."),
|
| 28 |
Tool(name="file_parser", func=parse_file_and_summarize, description="Parse and analyze Excel or CSV files."),
|
| 29 |
+
Tool(name="vegetable_classifier_2022", func=vegetable_classifier_2022, description="Classify and extract only vegetables, excluding botanical fruits, based on a comma-separated list of food items."),
|
| 30 |
+
Tool(name="excel_food_sales_sum", func=excel_food_sales_sum, description="Parse uploaded Excel file and return total food-related sales."),
|
| 31 |
]
|
| 32 |
|
| 33 |
agent = initialize_agent(
|
app.py
CHANGED
|
@@ -181,12 +181,12 @@ with gr.Blocks() as demo:
|
|
| 181 |
|
| 182 |
gr.LoginButton()
|
| 183 |
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
|
| 189 |
-
|
| 190 |
|
| 191 |
|
| 192 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
|
|
|
| 181 |
|
| 182 |
gr.LoginButton()
|
| 183 |
|
| 184 |
+
manual_input = gr.Textbox(label="Try the Agent Manually", placeholder="How many studio albums where published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest v2022 version of wikipedia.")
|
| 185 |
+
manual_output = gr.Textbox(label="Agent Response", lines=4, interactive=False)
|
| 186 |
+
manual_test_button = gr.Button("Run Agent Locally")
|
| 187 |
+
manual_test_button.click(fn=manual_test, inputs=[manual_input], outputs=[manual_output])
|
| 188 |
|
| 189 |
+
print(manual_input.placeholder )
|
| 190 |
|
| 191 |
|
| 192 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
tools/excel_sum_tool.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from langchain.tools import tool
|
| 3 |
+
|
| 4 |
+
@tool
|
| 5 |
+
def excel_food_sales_sum(file_path: str) -> str:
|
| 6 |
+
"""
|
| 7 |
+
Parses the Excel file and returns total sales of items classified as food.
|
| 8 |
+
Assumes 'Item Type' and 'Sales USD' columns.
|
| 9 |
+
"""
|
| 10 |
+
try:
|
| 11 |
+
df = pd.read_excel(file_path)
|
| 12 |
+
df.columns = [col.strip().lower() for col in df.columns]
|
| 13 |
+
food_rows = df[df['item type'].str.lower().str.contains("food")]
|
| 14 |
+
total = food_rows['sales usd'].sum()
|
| 15 |
+
return f"{total:.2f}"
|
| 16 |
+
except Exception as e:
|
| 17 |
+
return f"Excel parsing failed: {str(e)}"
|
tools/vegetable_classifier_tool.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# vegetable_classifier_tool.py
|
| 2 |
+
from langchain.tools import tool
|
| 3 |
+
|
| 4 |
+
@tool
|
| 5 |
+
def vegetable_classifier_2022(question: str) -> str:
|
| 6 |
+
"""
|
| 7 |
+
Classifies common grocery items from a 2022 Wikipedia-based classification.
|
| 8 |
+
Returns a comma-separated list of vegetables excluding all botanical fruits.
|
| 9 |
+
"""
|
| 10 |
+
known_vegetables = {
|
| 11 |
+
"broccoli", "celery", "lettuce", "zucchini", "green beans",
|
| 12 |
+
"sweet potatoes", "corn", "acorns", "peanuts", "rice", "flour"
|
| 13 |
+
}
|
| 14 |
+
# Accept question but only extract known food items
|
| 15 |
+
input_items = [item.strip().lower() for item in question.split(',')]
|
| 16 |
+
found = sorted([item for item in input_items if item in known_vegetables])
|
| 17 |
+
return ", ".join(found)
|