altozachmo commited on
Commit
d8ea933
·
1 Parent(s): ae14774

add rate limit protections

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -3,6 +3,8 @@ import gradio as gr
3
  import requests
4
  import pandas as pd
5
  from agents.agent import MyAgent
 
 
6
 
7
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
8
 
@@ -68,7 +70,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
68
  results_log = []
69
  answers_payload = []
70
  print(f"Running agent on {len(questions_data)} questions...")
71
- for item in questions_data:
72
  task_id = item.get("task_id")
73
  question_text = item.get("question")
74
  if not task_id or question_text is None:
@@ -76,6 +78,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
76
  continue
77
  try:
78
  submitted_answer = agent(question_text)
 
79
  answers_payload.append(
80
  {"task_id": task_id, "submitted_answer": submitted_answer}
81
  )
 
3
  import requests
4
  import pandas as pd
5
  from agents.agent import MyAgent
6
+ import time
7
+ from tqdm import tqdm
8
 
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
 
70
  results_log = []
71
  answers_payload = []
72
  print(f"Running agent on {len(questions_data)} questions...")
73
+ for item in tqdm(questions_data, desc="Agent is answering questions...", total=len(questions_data)):
74
  task_id = item.get("task_id")
75
  question_text = item.get("question")
76
  if not task_id or question_text is None:
 
78
  continue
79
  try:
80
  submitted_answer = agent(question_text)
81
+ time.sleep(30) # to avoid rate limiting
82
  answers_payload.append(
83
  {"task_id": task_id, "submitted_answer": submitted_answer}
84
  )