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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -1
app.py CHANGED
@@ -20,6 +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
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
24
 
25
  if profile:
@@ -57,7 +58,54 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
57
  answers_payload = []
58
  files_base = os.path.join(data_dir, "2023", "test")
59
  subset = dataset.select(range(1, 5))
60
- for item in subset:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  print(f"ITEMS {item}")
62
  task_id = item.get("task_id")
63
  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:
 
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:
64
+ username= f"{profile.username}"
65
+ print(f"User logged in: {username}")
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}")