Gonzalo Lope commited on
Commit
c18be72
·
1 Parent(s): 8a760ab

Achieved 30%

Browse files
.gitignore CHANGED
@@ -1 +1,2 @@
1
- .env
 
 
1
+ .env
2
+ __pycache__
__pycache__/smolagents.cpython-311.pyc DELETED
Binary file (721 Bytes)
 
__pycache__/smolagents_test.cpython-311.pyc DELETED
Binary file (856 Bytes)
 
app.py CHANGED
@@ -5,6 +5,10 @@ import inspect
5
  import pandas as pd
6
  from smolagents_test_new import agent
7
  import json
 
 
 
 
8
 
9
  # (Keep Constants as is)
10
  # --- Constants ---
@@ -30,12 +34,13 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
30
  # --- Determine HF Space Runtime URL and Repo URL ---
31
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
32
 
33
- if profile:
34
- username= f"{profile.username}"
35
- print(f"User logged in: {username}")
36
- else:
37
- print("User not logged in.")
38
- return "Please Login to Hugging Face with the button.", None
 
39
 
40
  api_url = DEFAULT_API_URL
41
  questions_url = f"{api_url}/questions"
@@ -79,16 +84,44 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
79
  # Add question data to a json file
80
  with open("questions_full.json", "w") as f:
81
  json.dump(questions_data, f, indent=4)
82
- # print in a way it can be copied to a file
83
- print(json.dumps(questions_data, indent=4))
84
  for item in questions_data:
85
  task_id = item.get("task_id")
86
  question_text = item.get("question")
 
87
  if not task_id or question_text is None:
88
  print(f"Skipping item with missing task_id or question: {item}")
89
  continue
90
  try:
91
- submitted_answer = agent(question_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
93
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
94
  except Exception as e:
@@ -201,4 +234,4 @@ if __name__ == "__main__":
201
  print("-"*(60 + len(" App Starting ")) + "\n")
202
 
203
  print("Launching Gradio Interface for Basic Agent Evaluation...")
204
- demo.launch(debug=True, share=False)
 
5
  import pandas as pd
6
  from smolagents_test_new import agent
7
  import json
8
+ from PIL import Image
9
+ from io import BytesIO
10
+ import pandas as pd
11
+ import re
12
 
13
  # (Keep Constants as is)
14
  # --- Constants ---
 
34
  # --- Determine HF Space Runtime URL and Repo URL ---
35
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
36
 
37
+ # if profile:
38
+ # username= f"{profile.username}"
39
+ # print(f"User logged in: {username}")
40
+ # else:
41
+ # print("User not logged in.")
42
+ # return "Please Login to Hugging Face with the button.", None
43
+ username = 'glpcc'
44
 
45
  api_url = DEFAULT_API_URL
46
  questions_url = f"{api_url}/questions"
 
84
  # Add question data to a json file
85
  with open("questions_full.json", "w") as f:
86
  json.dump(questions_data, f, indent=4)
 
 
87
  for item in questions_data:
88
  task_id = item.get("task_id")
89
  question_text = item.get("question")
90
+ filename = item.get("file_name", "")
91
  if not task_id or question_text is None:
92
  print(f"Skipping item with missing task_id or question: {item}")
93
  continue
94
  try:
95
+
96
+
97
+ if filename.endswith(('.jpg', '.jpeg', '.png', '.gif')):
98
+ img_req_response = requests.get(api_url + f'/files/{task_id}', timeout=15)
99
+ # Save the image to a file
100
+ temp_filename = f"temp_image.{filename.split('.')[-1]}"
101
+ with open(temp_filename, "wb") as f:
102
+ f.write(img_req_response.content)
103
+ # Open the image using PIL
104
+ imgs = [Image.open(temp_filename)]
105
+ submitted_answer = "No vision model available, but image saved as " + temp_filename + "."
106
+ elif filename.endswith('.py'):
107
+ code_req_response = requests.get(api_url + f'/files/{task_id}', timeout=15)
108
+ code_content = code_req_response.text
109
+ submitted_answer = agent(question_text + '\nSubmited python code:\n' + code_content)
110
+ elif filename.endswith('.mp3'):
111
+ submitted_answer = "File type not supported for direct processing."
112
+ elif filename.endswith('.xlsx'):
113
+ xlsx_req_response = requests.get(api_url + f'/files/{task_id}', timeout=15)
114
+ xlsx_content = xlsx_req_response.content
115
+ # Write excel to a file
116
+ with open("temp.xlsx", "wb") as f:
117
+ f.write(xlsx_content)
118
+ submitted_answer = agent(question_text + '\nSubmited excel file in temp.xlsx, use pandas to read it.')
119
+
120
+ else:
121
+ submitted_answer = agent(question_text)
122
+
123
+ # replace FINAL ANSWER: if it exists
124
+ submitted_answer = re.sub(r'FINAL ANSWER: *', '', submitted_answer, flags=re.IGNORECASE).strip()
125
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
126
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
127
  except Exception as e:
 
234
  print("-"*(60 + len(" App Starting ")) + "\n")
235
 
236
  print("Launching Gradio Interface for Basic Agent Evaluation...")
237
+ demo.launch(debug=True, share=False, server_name='0.0.0.0')
questions.json DELETED
@@ -1,122 +0,0 @@
1
- [
2
- {
3
- "task_id": "8e867cd7-cff9-4e6c-867a-ff5ddc2550be",
4
- "question": "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.",
5
- "Level": "1",
6
- "file_name": ""
7
- },
8
- {
9
- "task_id": "a1e91b78-d3d8-4675-bb8d-62741b4b68a6",
10
- "question": "In the video https://www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?",
11
- "Level": "1",
12
- "file_name": ""
13
- },
14
- {
15
- "task_id": "2d83110e-a098-4ebb-9987-066c06fa42d0",
16
- "question": ".rewsna eht sa \"tfel\" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI",
17
- "Level": "1",
18
- "file_name": ""
19
- },
20
- {
21
- "task_id": "cca530fc-4052-43b2-b130-b30968d8aa44",
22
- "question": "Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.",
23
- "Level": "1",
24
- "file_name": "cca530fc-4052-43b2-b130-b30968d8aa44.png"
25
- },
26
- {
27
- "task_id": "4fc2f1ae-8625-45b5-ab34-ad4433bc21f8",
28
- "question": "Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?",
29
- "Level": "1",
30
- "file_name": ""
31
- },
32
- {
33
- "task_id": "6f37996b-2ac7-44b0-8e68-6d28256631b4",
34
- "question": "Given this table defining * on the set S = {a, b, c, d, e}\n\n|*|a|b|c|d|e|\n|---|---|---|---|---|---|\n|a|a|b|c|b|d|\n|b|b|c|a|e|c|\n|c|c|a|b|b|a|\n|d|b|e|b|e|d|\n|e|d|b|a|d|c|\n\nprovide the subset of S involved in any possible counter-examples that prove * is not commutative. Provide your answer as a comma separated list of the elements in the set in alphabetical order.",
35
- "Level": "1",
36
- "file_name": ""
37
- },
38
- {
39
- "task_id": "9d191bce-651d-4746-be2d-7ef8ecadb9c2",
40
- "question": "Examine the video at https://www.youtube.com/watch?v=1htKBjuUWec.\n\nWhat does Teal'c say in response to the question \"Isn't that hot?\"",
41
- "Level": "1",
42
- "file_name": ""
43
- },
44
- {
45
- "task_id": "cabe07ed-9eca-40ea-8ead-410ef5e83f91",
46
- "question": "What is the surname of the equine veterinarian mentioned in 1.E Exercises from the chemistry materials licensed by Marisa Alviar-Agnew & Henry Agnew under the CK-12 license in LibreText's Introductory Chemistry materials as compiled 08/21/2023?",
47
- "Level": "1",
48
- "file_name": ""
49
- },
50
- {
51
- "task_id": "3cef3a44-215e-4aed-8e3b-b1e3f08063b7",
52
- "question": "I'm making a grocery list for my mom, but she's a professor of botany and she's a real stickler when it comes to categorizing things. I need to add different foods to different categories on the grocery list, but if I make a mistake, she won't buy anything inserted in the wrong category. Here's the list I have so far:\n\nmilk, eggs, flour, whole bean coffee, Oreos, sweet potatoes, fresh basil, plums, green beans, rice, corn, bell pepper, whole allspice, acorns, broccoli, celery, zucchini, lettuce, peanuts\n\nI need to make headings for the fruits and vegetables. Could you please create a list of just the vegetables from my list? If you could do that, then I can figure out how to categorize the rest of the list into the appropriate categories. But remember that my mom is a real stickler, so make sure that no botanical fruits end up on the vegetable list, or she won't get them when she's at the store. Please alphabetize the list of vegetables, and place each item in a comma separated list.",
53
- "Level": "1",
54
- "file_name": ""
55
- },
56
- {
57
- "task_id": "99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3",
58
- "question": "Hi, I'm making a pie but I could use some help with my shopping list. I have everything I need for the crust, but I'm not sure about the filling. I got the recipe from my friend Aditi, but she left it as a voice memo and the speaker on my phone is buzzing so I can't quite make out what she's saying. Could you please listen to the recipe and list all of the ingredients that my friend described? I only want the ingredients for the filling, as I have everything I need to make my favorite pie crust. I've attached the recipe as Strawberry pie.mp3.\n\nIn your response, please only list the ingredients, not any measurements. So if the recipe calls for \"a pinch of salt\" or \"two cups of ripe strawberries\" the ingredients on the list would be \"salt\" and \"ripe strawberries\".\n\nPlease format your response as a comma separated list of ingredients. Also, please alphabetize the ingredients.",
59
- "Level": "1",
60
- "file_name": "99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3"
61
- },
62
- {
63
- "task_id": "305ac316-eef6-4446-960a-92d80d542f82",
64
- "question": "Who did the actor who played Ray in the Polish-language version of Everybody Loves Raymond play in Magda M.? Give only the first name.",
65
- "Level": "1",
66
- "file_name": ""
67
- },
68
- {
69
- "task_id": "f918266a-b3e0-4914-865d-4faa564f1aef",
70
- "question": "What is the final numeric output from the attached Python code?",
71
- "Level": "1",
72
- "file_name": "f918266a-b3e0-4914-865d-4faa564f1aef.py"
73
- },
74
- {
75
- "task_id": "3f57289b-8c60-48be-bd80-01f8099ca449",
76
- "question": "How many at bats did the Yankee with the most walks in the 1977 regular season have that same season?",
77
- "Level": "1",
78
- "file_name": ""
79
- },
80
- {
81
- "task_id": "1f975693-876d-457b-a649-393859e79bf3",
82
- "question": "Hi, I was out sick from my classes on Friday, so I'm trying to figure out what I need to study for my Calculus mid-term next week. My friend from class sent me an audio recording of Professor Willowbrook giving out the recommended reading for the test, but my headphones are broken :(\n\nCould you please listen to the recording for me and tell me the page numbers I'm supposed to go over? I've attached a file called Homework.mp3 that has the recording. Please provide just the page numbers as a comma-delimited list. And please provide the list in ascending order.",
83
- "Level": "1",
84
- "file_name": "1f975693-876d-457b-a649-393859e79bf3.mp3"
85
- },
86
- {
87
- "task_id": "840bfca7-4f7b-481a-8794-c560c340185d",
88
- "question": "On June 6, 2023, an article by Carolyn Collins Petersen was published in Universe Today. This article mentions a team that produced a paper about their observations, linked at the bottom of the article. Find this paper. Under what NASA award number was the work performed by R. G. Arendt supported by?",
89
- "Level": "1",
90
- "file_name": ""
91
- },
92
- {
93
- "task_id": "bda648d7-d618-4883-88f4-3466eabd860e",
94
- "question": "Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations.",
95
- "Level": "1",
96
- "file_name": ""
97
- },
98
- {
99
- "task_id": "cf106601-ab4f-4af9-b045-5295fe67b37d",
100
- "question": "What country had the least number of athletes at the 1928 Summer Olympics? If there's a tie for a number of athletes, return the first in alphabetical order. Give the IOC country code as your answer.",
101
- "Level": "1",
102
- "file_name": ""
103
- },
104
- {
105
- "task_id": "a0c07678-e491-4bbc-8f0b-07405144218f",
106
- "question": "Who are the pitchers with the number before and after Taish\u014d Tamai's number as of July 2023? Give them to me in the form Pitcher Before, Pitcher After, use their last names only, in Roman characters.",
107
- "Level": "1",
108
- "file_name": ""
109
- },
110
- {
111
- "task_id": "7bd855d8-463d-4ed5-93ca-5fe35145f733",
112
- "question": "The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.",
113
- "Level": "1",
114
- "file_name": "7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx"
115
- },
116
- {
117
- "task_id": "5a0c1adf-205e-4841-a666-7c3ef95def9d",
118
- "question": "What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?",
119
- "Level": "1",
120
- "file_name": ""
121
- }
122
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
smolagents_test_new.py CHANGED
@@ -1,9 +1,50 @@
1
  from huggingface_hub import login
2
- from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, WikipediaSearchTool
3
- from smolagents import tool
4
  import os
 
 
 
5
 
6
- hf_token = os.getenv("HF_TOKEN")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
 
9
  @tool
@@ -16,8 +57,50 @@ def reverse_string(input_string: str) -> str:
16
  """
17
  return input_string[::-1]
18
 
19
- agent = CodeAgent(tools=[DuckDuckGoSearchTool(),reverse_string,WikipediaSearchTool()], model=InferenceClientModel(token=hf_token))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  if __name__ == "__main__":
23
- agent.run("Search for the best music recommendations for a party at the Wayne's mansion.")
 
 
1
  from huggingface_hub import login
2
+ from smolagents import OpenAIServerModel, WikipediaSearchTool,VisitWebpageTool, ToolCallingAgent,CodeAgent, WebSearchTool
3
+ from smolagents import tool,load_tool
4
  import os
5
+ import pandas as pd
6
+ import mdpd
7
+ from io import StringIO
8
 
9
+
10
+ inference_model = OpenAIServerModel(
11
+ model_id="meta-llama/Llama-3.1-70B-Instruct",
12
+ api_base="http://localhost:8188/v1",
13
+ api_key="EMPTY"
14
+ )
15
+ @tool
16
+ def youtube_transcript(video_url: str) -> str:
17
+ """This is a tool that retrieves the transcript of a YouTube video.
18
+
19
+ Args:
20
+ video_url (str): The URL of the YouTube video.
21
+
22
+ Returns:
23
+ str: The transcript of the video.
24
+ """
25
+ from youtube_transcript_api import YouTubeTranscriptApi
26
+
27
+ video_id = video_url.split("v=")[-1]
28
+ ytt_api = YouTubeTranscriptApi()
29
+ transcript = ytt_api.fetch(video_id)
30
+ tr = "Transcript:\n"
31
+ tr += "Unknown Speaker: "
32
+ tr += "\nUnknown Speaker: ".join([item['text'] for item in transcript.to_raw_data()])
33
+ return tr
34
+
35
+ @tool
36
+ def parse_md_table(md_table: str) -> pd.DataFrame:
37
+ """This is a tool that parses a markdown table into a pandas DataFrame.
38
+
39
+ Args:
40
+ md_table (str): The markdown table as a string.
41
+
42
+ Returns:
43
+ pd.DataFrame: The parsed DataFrame.
44
+ """
45
+ # Use mdpd to parse the markdown table
46
+ df = mdpd.from_md(md_table)
47
+ return df
48
 
49
 
50
  @tool
 
57
  """
58
  return input_string[::-1]
59
 
60
+ @tool
61
+ def read_excel_file(file_path: str) -> pd.DataFrame:
62
+ """This is a tool that reads an Excel file and returns its content as a pandas DataFrame.
63
+
64
+ Args:
65
+ file_path (str): The path to the Excel file.
66
+
67
+ Returns:
68
+ pd.DataFrame: The content of the Excel file as a DataFrame.
69
+ """
70
+ return pd.read_excel(file_path).to_markdown()
71
+
72
+ @tool
73
+ def sum_numbers(numbers: str) -> int:
74
+ """This is a tool that sums a list of numbers provided as a comma-separated string.
75
+
76
+ Args:
77
+ numbers (str): A comma-separated string of numbers.
78
+
79
+ Returns:
80
+ int: The sum of the numbers.
81
+ """
82
+ number_list = [float(num.strip()) for num in numbers.split(",")]
83
+ result = sum(number_list)
84
+ return f"{result:.2f}" # Return the sum formatted to two decimal places
85
+
86
 
87
+ # agent = ToolCallingAgent(
88
+ # tools=[DuckDuckGoSearchTool(),reverse_string,VisitWebpageTool(),youtube_transcript,WikipediaSearchTool(),sum_numbers,read_excel_file],
89
+ # model=inference_model,
90
+ # planning_interval=3,
91
+ # max_steps=10,
92
+ # instructions="You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. 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. 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. 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.",
93
+ # )
94
+ agent = CodeAgent(
95
+ tools=[WebSearchTool(max_results=5),reverse_string,VisitWebpageTool(),youtube_transcript,parse_md_table,WikipediaSearchTool()],
96
+ model=inference_model,
97
+ planning_interval=2,
98
+ max_steps=10,
99
+ add_base_tools=True,
100
+ instructions="You are a general AI assistant. I will ask you a question. YOU CAN NOT INTERACT WITH WEBSITES JUST READ THEM. A horse doctor is also a synonym of a equine veterinarian. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. 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. 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. 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.",
101
+ additional_authorized_imports=("pandas", "numpy", "io")
102
+ )
103
 
104
  if __name__ == "__main__":
105
+ t = youtube_transcript("https://www.youtube.com/watch?v=1htKBjuUWec")
106
+ print(t)
sys_prompt.txt DELETED
@@ -1,34 +0,0 @@
1
- You are an expert assistant who can solve any task using code blobs. You will be given a task to solve as best you can.
2
- To do so, you have been given access to a list of tools: these tools are basically Python functions which you can call with code.
3
- To solve the task, you must plan forward to proceed in a series of steps, in a cycle of 'Thought:', 'Code:', and 'Observation:' sequences.
4
-
5
- At each step, in the 'Thought:' sequence, you should first explain your reasoning towards solving the task and the tools that you want to use.
6
- Then in the 'Code:' sequence, you should write the code in simple Python. The code sequence must end with '<end_code>' sequence.
7
- During each intermediate step, you can use 'print()' to save whatever important information you will then need.
8
- These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step.
9
- In the end you have to return a final answer using the `final_answer` tool.
10
-
11
- Here are a few examples using notional tools:
12
- ---
13
- {examples}
14
-
15
- Above example were using notional tools that might not exist for you. On top of performing computations in the Python code snippets that you create, you only have access to these tools:
16
-
17
- {{tool_descriptions}}
18
-
19
- {{managed_agents_descriptions}}
20
-
21
- Here are the rules you should always follow to solve your task:
22
- 1. Always provide a 'Thought:' sequence, and a 'Code:\n```py' sequence ending with '```<end_code>' sequence, else you will fail.
23
- 2. Use only variables that you have defined!
24
- 3. Always use the right arguments for the tools. DO NOT pass the arguments as a dict as in 'answer = wiki({'query': "What is the place where James Bond lives?"})', but use the arguments directly as in 'answer = wiki(query="What is the place where James Bond lives?")'.
25
- 4. Take care to not chain too many sequential tool calls in the same code block, especially when the output format is unpredictable. For instance, a call to search has an unpredictable return format, so do not have another tool call that depends on its output in the same block: rather output results with print() to use them in the next block.
26
- 5. Call a tool only when needed, and never re-do a tool call that you previously did with the exact same parameters.
27
- 6. Don't name any new variable with the same name as a tool: for instance don't name a variable 'final_answer'.
28
- 7. Never create any notional variables in our code, as having these in your logs might derail you from the true variables.
29
- 8. You can use imports in your code, but only from the following list of modules: {{authorized_imports}}
30
- 9. The state persists between code executions: so if in one step you've created variables or imported modules, these will all persist.
31
- 10. Don't give up! You're in charge of solving the task, not providing directions to solve it.
32
- 11. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. 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. 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. 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.
33
-
34
- Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000.