Update app.py
Browse files
app.py
CHANGED
|
@@ -12,11 +12,12 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 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-
|
| 20 |
# Initialize the search tool
|
| 21 |
search_tool = DuckDuckGoSearchTool()
|
| 22 |
# Initialize Agent
|
|
@@ -30,7 +31,7 @@ class BasicAgent:
|
|
| 30 |
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 31 |
return fixed_answer
|
| 32 |
|
| 33 |
-
def run_and_submit_all(
|
| 34 |
"""
|
| 35 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 36 |
and displays the results.
|
|
@@ -51,7 +52,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 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,25 +160,27 @@ with gr.Blocks() as demo:
|
|
| 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.
|
|
|
|
| 163 |
---
|
| 164 |
**Disclaimers:**
|
| 165 |
-
Once clicking on the "submit button, it can take quite some time (
|
| 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
|
| 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 |
|
|
|
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 14 |
class BasicAgent:
|
| 15 |
+
def __init__(self, openai_key):
|
| 16 |
+
self.openai_key = openai_key
|
| 17 |
print("BasicAgent initialized.")
|
| 18 |
# Initialize the model
|
| 19 |
#model = HfApiModel()
|
| 20 |
+
model = OpenAIServerModel(model_id="gpt-4.1", api_key=self.openai_key)
|
| 21 |
# Initialize the search tool
|
| 22 |
search_tool = DuckDuckGoSearchTool()
|
| 23 |
# Initialize Agent
|
|
|
|
| 31 |
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 32 |
return fixed_answer
|
| 33 |
|
| 34 |
+
def run_and_submit_all(profile: gr.OAuthProfile | None, openai_key: str):
|
| 35 |
"""
|
| 36 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 37 |
and displays the results.
|
|
|
|
| 52 |
|
| 53 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 54 |
try:
|
| 55 |
+
agent = BasicAgent(openai_key)
|
| 56 |
except Exception as e:
|
| 57 |
print(f"Error instantiating agent: {e}")
|
| 58 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 160 |
**Instructions:**
|
| 161 |
1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
|
| 162 |
2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
|
| 163 |
+
3. Enter your OpenAI key below (if required by your agent).
|
| 164 |
+
4. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
|
| 165 |
---
|
| 166 |
**Disclaimers:**
|
| 167 |
+
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).
|
| 168 |
+
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.
|
|
|
|
| 169 |
"""
|
| 170 |
)
|
| 171 |
|
| 172 |
gr.LoginButton()
|
| 173 |
|
| 174 |
+
openai_key_box = gr.Textbox(label="OpenAI API Key", type="password", placeholder="sk-...", lines=1)
|
| 175 |
+
|
| 176 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
| 177 |
|
| 178 |
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
|
|
|
| 179 |
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
| 180 |
|
| 181 |
run_button.click(
|
| 182 |
fn=run_and_submit_all,
|
| 183 |
+
inputs=[openai_key_box],
|
| 184 |
outputs=[status_output, results_table]
|
| 185 |
)
|
| 186 |
|