Sborole commited on
Commit
17909da
·
verified ·
1 Parent(s): 2cb002d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -39
app.py CHANGED
@@ -20,7 +20,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
20
  and displays the results.
21
  """
22
  # --- Determine HF Space Runtime URL and Repo URL ---
23
- """
24
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
25
 
26
  if profile:
@@ -57,7 +57,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
57
  results_log = []
58
  answers_payload = []
59
  files_base = os.path.join(data_dir, "2023", "test")
60
- subset = dataset.select(range(1, 5))
61
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
62
 
63
  if profile:
@@ -66,46 +66,10 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
66
  else:
67
  print("User not logged in.")
68
  return "Please Login to Hugging Face with the button.", None
69
- """
70
- space_id = os.getenv("SPACE_ID")
71
- api_url = DEFAULT_API_URL
72
- questions_url = f"{api_url}/questions"
73
- submit_url = f"{api_url}/submit"
74
-
75
- # 1. Instantiate Agent ( modify this part to create your agent)
76
- try:
77
- agent = BasicAgent()
78
- except Exception as e:
79
- print(f"Error instantiating agent: {e}")
80
- return f"Error initializing agent: {e}", None
81
- # In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
82
- agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
83
- print(agent_code)
84
-
85
- # 2. Fetch Questions
86
- print(f"Fetching questions from: {questions_url}")
87
- try:
88
- response = requests.get(questions_url, timeout=15)
89
- response.raise_for_status()
90
- questions_data = response.json()
91
- if not questions_data:
92
- print("Fetched questions list is empty.")
93
- return "Fetched questions list is empty or invalid format.", None
94
- print(f"Fetched {len(questions_data)} questions.")
95
- except requests.exceptions.RequestException as e:
96
- print(f"Error fetching questions: {e}")
97
- return f"Error fetching questions: {e}", None
98
- except requests.exceptions.JSONDecodeError as e:
99
- print(f"Error decoding JSON response from questions endpoint: {e}")
100
- print(f"Response text: {response.text[:500]}")
101
- return f"Error decoding server response for questions: {e}", None
102
- except Exception as e:
103
- print(f"An unexpected error occurred fetching questions: {e}")
104
- return f"An unexpected error occurred fetching questions: {e}", None
105
 
106
  results_log = []
107
  answers_payload = []
108
- for item in questions_data[:20]:
109
  print(f"ITEMS {item}")
110
  task_id = item.get("task_id")
111
  print(f"Task ID is {task_id}")
 
20
  and displays the results.
21
  """
22
  # --- Determine HF Space Runtime URL and Repo URL ---
23
+
24
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
25
 
26
  if profile:
 
57
  results_log = []
58
  answers_payload = []
59
  files_base = os.path.join(data_dir, "2023", "test")
60
+ subset = dataset.select(range(20))
61
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
62
 
63
  if profile:
 
66
  else:
67
  print("User not logged in.")
68
  return "Please Login to Hugging Face with the button.", None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
  results_log = []
71
  answers_payload = []
72
+ for item in subset[:20]:
73
  print(f"ITEMS {item}")
74
  task_id = item.get("task_id")
75
  print(f"Task ID is {task_id}")