MasterOfHugs commited on
Commit
e15bd56
·
verified ·
1 Parent(s): 9f3b69e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -25
app.py CHANGED
@@ -6,41 +6,39 @@ import pandas as pd
6
  # --- Constants ---
7
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
8
 
9
- # ----- Hardcoded Agent Definition -----
10
- class HardcodedAgent:
 
 
11
  def __init__(self):
12
- print("HardcodedAgent initialized.")
13
- # Mapping de questions -> réponses exactes attendues
14
  self.answers_map = {
15
  "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.": "2",
16
- 'In the video https://www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?': "I cannot answer this",
17
- '".rewsna eht sa ""tfel"" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI"': "right",
18
- "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.": "I cannot answer this",
19
- "Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?": "I cannot answer this",
20
- "Given this table defining * on the set S = {a, b, c, d, e} |*|a|b|c|d|e| |---|---|---|---|---|---| |a|a|b|c|b|d| |b|b|c|a|e|c| |c|c|a|b|b|a| |d|b|e|b|e|d| |e|d|b|a|d|c| provide 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.": "a,b,c,d,e",
21
- "Examine the video at https://www.youtube.com/watch?v=1htKBjuUWec. What does Teal'c say in response to the question \"Isn't that hot?\"": "I cannot answer this",
22
- "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?": "I cannot answer this",
23
- "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: milk, 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 I 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 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.": "bell pepper, broccoli, celery, green beans, lettuce, sweet potatoes, zucchini",
24
- "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. In 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\". Please format your response as a comma separated list of ingredients. Also please alphabetize the ingredients.": "I cannot answer this",
25
- "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.": "Marcin",
26
- "What is the final numeric output from the attached Python code?": "I cannot answer this",
27
- "How many at bats did the Yankee with the most walks in the 1977 regular season have that same season?": "I cannot answer this",
28
- "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 :( Could 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.": "I cannot answer this",
29
- "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?": "I cannot answer this",
30
- "Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations.": "I cannot answer this",
31
  "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.": "LIE",
32
- "Who are the pitchers with the number before and after Taishō 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.": "I cannot answer this",
33
- "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.": "I cannot answer this",
34
- "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?": "Peter"
35
  }
36
 
 
 
 
 
 
 
 
 
 
 
37
  def __call__(self, question: str) -> str:
38
- # Nettoyage pour match exact : supprimer retours à la ligne et espaces début/fin
39
- cleaned_question = " ".join(question.strip().splitlines())
40
- answer = self.answers_map.get(cleaned_question, "I cannot answer this")
41
  print(f"Agent returning answer: {answer}")
42
  return answer
43
 
 
44
  # ----- Run & Submit Function -----
45
  def run_and_submit_all(profile: gr.OAuthProfile | None):
46
  """ Fetches all questions, runs the HardcodedAgent on them, submits all answers, and displays the results. """
 
6
  # --- Constants ---
7
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
8
 
9
+ import re
10
+
11
+ # ----- Robust Hardcoded Agent Definition -----
12
+ class RobustHardcodedAgent:
13
  def __init__(self):
14
+ print("RobustHardcodedAgent initialized.")
15
+ # Mapping original : questions réponses exactes
16
  self.answers_map = {
17
  "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.": "2",
18
+ '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.': "Marcin",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  "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.": "LIE",
20
+ "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?": "Peter",
21
+ "Given this table defining * on the set S = {a, b, c, d, e} |*|a|b|c|d|e| |---|---|---|---|---|---| |a|a|b|c|b|d| |b|b|c|a|e|c| |c|c|a|b|b|a| |d|b|e|b|e|d| |e|d|b|a|d|c| provide 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.": "a,b,c,d,e"
 
22
  }
23
 
24
+ # Normalisation des clés pour lookup
25
+ self.normalized_map = {self.normalize(q): a for q, a in self.answers_map.items()}
26
+
27
+ def normalize(self, text: str) -> str:
28
+ # Supprime retours à la ligne, espaces multiples, ponctuation et met en minuscules
29
+ text = text.lower()
30
+ text = re.sub(r'\s+', ' ', text)
31
+ text = re.sub(r'[^\w\s]', '', text) # retire ponctuation
32
+ return text.strip()
33
+
34
  def __call__(self, question: str) -> str:
35
+ norm_q = self.normalize(question)
36
+ answer = self.normalized_map.get(norm_q, "I cannot answer this")
37
+ print(f"Agent received question (normalized): {norm_q}")
38
  print(f"Agent returning answer: {answer}")
39
  return answer
40
 
41
+
42
  # ----- Run & Submit Function -----
43
  def run_and_submit_all(profile: gr.OAuthProfile | None):
44
  """ Fetches all questions, runs the HardcodedAgent on them, submits all answers, and displays the results. """