Update app.py
Browse files
app.py
CHANGED
@@ -552,26 +552,47 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
552 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
553 |
print(f"Agent code location: {agent_code}")
|
554 |
|
555 |
-
# 2. Fetch Questions
|
556 |
print(f"Fetching questions from: {questions_url}")
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
575 |
|
576 |
# 3. Run your Agent
|
577 |
results_log = []
|
|
|
552 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
553 |
print(f"Agent code location: {agent_code}")
|
554 |
|
555 |
+
# 2. Fetch Questions with retry logic
|
556 |
print(f"Fetching questions from: {questions_url}")
|
557 |
+
max_retries = 3
|
558 |
+
base_timeout = 30 # Increased from 15 to 30 seconds
|
559 |
+
|
560 |
+
for attempt in range(max_retries):
|
561 |
+
try:
|
562 |
+
response = requests.get(
|
563 |
+
questions_url,
|
564 |
+
timeout=base_timeout * (attempt + 1), # Increase timeout with each retry
|
565 |
+
headers={'User-Agent': 'Mozilla/5.0'} # Add user agent to avoid potential blocking
|
566 |
+
)
|
567 |
+
response.raise_for_status()
|
568 |
+
questions_data = response.json()
|
569 |
+
if not questions_data:
|
570 |
+
print("Fetched questions list is empty.")
|
571 |
+
return "Fetched questions list is empty or invalid format.", None
|
572 |
+
print(f"Fetched {len(questions_data)} questions.")
|
573 |
+
break # Success, exit retry loop
|
574 |
+
except requests.exceptions.Timeout:
|
575 |
+
if attempt < max_retries - 1:
|
576 |
+
print(f"Timeout on attempt {attempt + 1}/{max_retries}. Retrying with longer timeout...")
|
577 |
+
time.sleep(2 * (attempt + 1)) # Exponential backoff
|
578 |
+
continue
|
579 |
+
else:
|
580 |
+
print("All retry attempts timed out.")
|
581 |
+
return "Error: All attempts to fetch questions timed out. Please try again later.", None
|
582 |
+
except requests.exceptions.RequestException as e:
|
583 |
+
print(f"Error fetching questions: {e}")
|
584 |
+
if attempt < max_retries - 1:
|
585 |
+
print(f"Retrying... (attempt {attempt + 1}/{max_retries})")
|
586 |
+
time.sleep(2 * (attempt + 1))
|
587 |
+
continue
|
588 |
+
return f"Error fetching questions after {max_retries} attempts: {e}", None
|
589 |
+
except requests.exceptions.JSONDecodeError as e:
|
590 |
+
print(f"Error decoding JSON response from questions endpoint: {e}")
|
591 |
+
print(f"Response text: {response.text[:500]}")
|
592 |
+
return f"Error decoding server response for questions: {e}", None
|
593 |
+
except Exception as e:
|
594 |
+
print(f"An unexpected error occurred fetching questions: {e}")
|
595 |
+
return f"An unexpected error occurred fetching questions: {e}", None
|
596 |
|
597 |
# 3. Run your Agent
|
598 |
results_log = []
|