AliHaider1 commited on
Commit
e11d7c6
·
verified ·
1 Parent(s): 81917a3

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -3,7 +3,13 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
 
 
6
 
 
 
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -28,11 +34,12 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
28
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
29
 
30
  if profile:
31
- username= f"{profile.username}"
32
  print(f"User logged in: {username}")
33
  else:
34
- print("User not logged in.")
35
- return "Please Login to Hugging Face with the button.", None
 
36
 
37
  api_url = DEFAULT_API_URL
38
  questions_url = f"{api_url}/questions"
@@ -40,7 +47,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
40
 
41
  # 1. Instantiate Agent ( modify this part to create your agent)
42
  try:
43
- agent = BasicAgent()
44
  except Exception as e:
45
  print(f"Error instantiating agent: {e}")
46
  return f"Error initializing agent: {e}", None
@@ -80,12 +87,14 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
80
  print(f"Skipping item with missing task_id or question: {item}")
81
  continue
82
  try:
83
- submitted_answer = agent(question_text)
 
84
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
85
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
86
  except Exception as e:
87
  print(f"Error running agent on task {task_id}: {e}")
88
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
 
89
 
90
  if not answers_payload:
91
  print("Agent did not produce any answers to submit.")
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from agent import GaiaAgent
7
+ import time
8
+ import spaces
9
 
10
+ @spaces.GPU
11
+ def _zero_gpu_placeholder():
12
+ pass
13
  # (Keep Constants as is)
14
  # --- Constants ---
15
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
34
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
35
 
36
  if profile:
37
+ username = f"{profile.username}"
38
  print(f"User logged in: {username}")
39
  else:
40
+ # Local fallback so you can run without HF Spaces OAuth
41
+ username = os.getenv("HF_USERNAME", "your_hf_username")
42
+ print(f"Running locally as: {username}")
43
 
44
  api_url = DEFAULT_API_URL
45
  questions_url = f"{api_url}/questions"
 
47
 
48
  # 1. Instantiate Agent ( modify this part to create your agent)
49
  try:
50
+ agent = GaiaAgent()
51
  except Exception as e:
52
  print(f"Error instantiating agent: {e}")
53
  return f"Error initializing agent: {e}", None
 
87
  print(f"Skipping item with missing task_id or question: {item}")
88
  continue
89
  try:
90
+ submitted_answer = agent(question_text,
91
+ task_id=task_id, file_name=item.get("file_name"))
92
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
93
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
94
  except Exception as e:
95
  print(f"Error running agent on task {task_id}: {e}")
96
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
97
+ time.sleep(5)
98
 
99
  if not answers_payload:
100
  print("Agent did not produce any answers to submit.")