asaporta commited on
Commit
0a90052
·
verified ·
1 Parent(s): 2906b2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -16
app.py CHANGED
@@ -11,16 +11,12 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
 
12
  # --- Basic Agent Definition ---
13
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
14
-
15
- openai_key = os.getenv("OPENAI_API_KEY")
16
-
17
  class BasicAgent:
18
- def __init__(self, openai_key):
19
- self.openai_key = openai_key
20
  print("BasicAgent initialized.")
21
  # Initialize the model
22
  #model = HfApiModel()
23
- model = OpenAIServerModel(model_id="gpt-4.1", api_key=self.openai_key)
24
  # Initialize the search tool
25
  search_tool = DuckDuckGoSearchTool()
26
  # Initialize Agent
@@ -34,7 +30,7 @@ class BasicAgent:
34
  print(f"Agent returning fixed answer: {fixed_answer}")
35
  return fixed_answer
36
 
37
- def run_and_submit_all(profile: gr.OAuthProfile | None, openai_key: str):
38
  """
39
  Fetches all questions, runs the BasicAgent on them, submits all answers,
40
  and displays the results.
@@ -55,7 +51,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None, openai_key: str):
55
 
56
  # 1. Instantiate Agent ( modify this part to create your agent)
57
  try:
58
- agent = BasicAgent(openai_key)
59
  except Exception as e:
60
  print(f"Error instantiating agent: {e}")
61
  return f"Error initializing agent: {e}", None
@@ -163,27 +159,25 @@ with gr.Blocks() as demo:
163
  **Instructions:**
164
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
165
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
166
- 3. Enter your OpenAI key below (if required by your agent).
167
- 4. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
168
  ---
169
  **Disclaimers:**
170
- Once clicking on the "submit" button, it can take quite some time (this is the time for the agent to go through all the questions).
171
- This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance, for the delay process of the submit button, a solution could be to cache the answers and submit in a separate action or even to answer the questions in async.
 
172
  """
173
  )
174
 
175
  gr.LoginButton()
176
 
177
- openai_key_box = gr.Textbox(label="OpenAI API Key", type="password", placeholder="sk-...", lines=1)
178
-
179
  run_button = gr.Button("Run Evaluation & Submit All Answers")
180
 
181
  status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
 
182
  results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
183
 
184
  run_button.click(
185
  fn=run_and_submit_all,
186
- inputs=[openai_key_box],
187
  outputs=[status_output, results_table]
188
  )
189
 
@@ -209,4 +203,4 @@ if __name__ == "__main__":
209
  print("-"*(60 + len(" App Starting ")) + "\n")
210
 
211
  print("Launching Gradio Interface for Basic Agent Evaluation...")
212
- demo.launch(debug=True, share=False)
 
11
 
12
  # --- Basic Agent Definition ---
13
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
 
 
14
  class BasicAgent:
15
+ def __init__(self):
 
16
  print("BasicAgent initialized.")
17
  # Initialize the model
18
  #model = HfApiModel()
19
+ model = OpenAIServerModel(model_id="gpt-4o")
20
  # Initialize the search tool
21
  search_tool = DuckDuckGoSearchTool()
22
  # Initialize Agent
 
30
  print(f"Agent returning fixed answer: {fixed_answer}")
31
  return fixed_answer
32
 
33
+ def run_and_submit_all( profile: gr.OAuthProfile | None):
34
  """
35
  Fetches all questions, runs the BasicAgent on them, submits all answers,
36
  and displays the results.
 
51
 
52
  # 1. Instantiate Agent ( modify this part to create your agent)
53
  try:
54
+ agent = BasicAgent()
55
  except Exception as e:
56
  print(f"Error instantiating agent: {e}")
57
  return f"Error initializing agent: {e}", None
 
159
  **Instructions:**
160
  1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
161
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
162
+ 3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
 
163
  ---
164
  **Disclaimers:**
165
+ Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
166
+ This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
167
+ Please note that this version requires an OpenAI Key to run.
168
  """
169
  )
170
 
171
  gr.LoginButton()
172
 
 
 
173
  run_button = gr.Button("Run Evaluation & Submit All Answers")
174
 
175
  status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
176
+ # Removed max_rows=10 from DataFrame constructor
177
  results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
178
 
179
  run_button.click(
180
  fn=run_and_submit_all,
 
181
  outputs=[status_output, results_table]
182
  )
183
 
 
203
  print("-"*(60 + len(" App Starting ")) + "\n")
204
 
205
  print("Launching Gradio Interface for Basic Agent Evaluation...")
206
+ demo.launch(debug=True, share=False)