NgBaoAnn commited on
Commit
218ac3d
·
1 Parent(s): f324d5f

fix: bundle questions.json in repo to bypass 429 rate limit on scoring server

Browse files
Files changed (2) hide show
  1. app.py +41 -26
  2. questions.json +122 -0
app.py CHANGED
@@ -629,43 +629,58 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
629
  space_id = os.getenv("SPACE_ID", "ngbaoan/Final_Assignment_AI_agents_course")
630
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
631
 
632
- # 1 — Fetch questions (retry up to 10× with backoff for 429)
 
 
633
  import time
634
- yield "📡 Fetching GAIA questions… (server may be busy, will retry automatically)", None
635
  questions_data = None
636
  last_error = None
637
- for attempt in range(1, 11):
 
 
 
638
  try:
639
- resp = requests.get(QUESTIONS_URL, timeout=30)
640
- if resp.status_code == 429:
641
- wait_sec = min(15 * attempt, 60) # 15s, 30s, 45s, 60s max
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
642
  if attempt == 10:
643
- last_error = "Server still rate-limiting after 10 attempts (429)."
644
  break
645
- yield (
646
- f" Server busy (429). Waiting {wait_sec}s… "
647
- f"(attempt {attempt}/10 — this is normal, please wait)",
648
- None,
649
- )
650
  time.sleep(wait_sec)
651
- continue
652
- resp.raise_for_status()
653
- questions_data = resp.json()
654
- break
655
- except Exception as exc:
656
- last_error = str(exc)
657
- if attempt == 10:
658
- break
659
- wait_sec = min(15 * attempt, 60)
660
- yield f"⚠️ Attempt {attempt}/10 failed: {exc}. Retrying in {wait_sec}s…", None
661
- time.sleep(wait_sec)
662
 
663
  if not questions_data:
664
  yield (
665
- f"❌ Could not fetch questions from the scoring server.\n"
666
  f"Reason: {last_error}\n\n"
667
- f"💡 This is a server-side rate limit NOT a bug in your code.\n"
668
- f"Please wait a few minutes and click Run again.",
669
  None,
670
  )
671
  return
 
629
  space_id = os.getenv("SPACE_ID", "ngbaoan/Final_Assignment_AI_agents_course")
630
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
631
 
632
+ # 1 — Fetch questions
633
+ # Strategy: load bundled questions.json first (avoids 429 rate limits on shared server).
634
+ # Fallback to API if the file is missing.
635
  import time
636
+ yield "📡 Loading GAIA questions…", None
637
  questions_data = None
638
  last_error = None
639
+
640
+ # Try local file first
641
+ local_path = os.path.join(os.path.dirname(__file__), "questions.json")
642
+ if os.path.exists(local_path):
643
  try:
644
+ with open(local_path, "r", encoding="utf-8") as f:
645
+ questions_data = json.load(f)
646
+ yield f"✅ Loaded {len(questions_data)} questions from local cache.", None
647
+ except Exception as exc:
648
+ yield f"⚠️ Local file error: {exc}. Trying API…", None
649
+
650
+ # Fallback: fetch from API with retry (429 backoff)
651
+ if not questions_data:
652
+ yield "📡 Fetching questions from scoring server…", None
653
+ for attempt in range(1, 11):
654
+ try:
655
+ resp = requests.get(QUESTIONS_URL, timeout=30)
656
+ if resp.status_code == 429:
657
+ wait_sec = min(15 * attempt, 60)
658
+ if attempt == 10:
659
+ last_error = "Server still rate-limiting after 10 attempts (429)."
660
+ break
661
+ yield (
662
+ f"⏳ Server busy (429). Waiting {wait_sec}s… "
663
+ f"(attempt {attempt}/10 — this is normal, please wait)",
664
+ None,
665
+ )
666
+ time.sleep(wait_sec)
667
+ continue
668
+ resp.raise_for_status()
669
+ questions_data = resp.json()
670
+ break
671
+ except Exception as exc:
672
+ last_error = str(exc)
673
  if attempt == 10:
 
674
  break
675
+ wait_sec = min(15 * attempt, 60)
676
+ yield f"⚠️ Attempt {attempt}/10 failed: {exc}. Retrying in {wait_sec}s…", None
 
 
 
677
  time.sleep(wait_sec)
 
 
 
 
 
 
 
 
 
 
 
678
 
679
  if not questions_data:
680
  yield (
681
+ f"❌ Could not load questions.\n"
682
  f"Reason: {last_error}\n\n"
683
+ f"💡 This is a server-side rate limit. Please wait a few minutes and try again.",
 
684
  None,
685
  )
686
  return
questions.json ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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ō 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
+ ]