Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,26 @@ logger = get_logger(__name__)
|
|
| 19 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
| 24 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
@@ -41,9 +61,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 41 |
|
| 42 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 43 |
try:
|
| 44 |
-
agent =
|
| 45 |
-
tools=get_tools()
|
| 46 |
-
)
|
| 47 |
except Exception as e:
|
| 48 |
print(f"Error instantiating agent: {e}")
|
| 49 |
return f"Error initializing agent: {e}", None
|
|
@@ -51,6 +69,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 51 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 52 |
print(agent_code)
|
| 53 |
|
|
|
|
| 54 |
# 2. Fetch Questions
|
| 55 |
print(f"Fetching questions from: {questions_url}")
|
| 56 |
try:
|
|
|
|
| 19 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 20 |
|
| 21 |
|
| 22 |
+
class BasicAgent:
|
| 23 |
+
"""A wrapper that forwards questions to your custom Agent."""
|
| 24 |
+
def __init__(self):
|
| 25 |
+
print("BasicAgent initialized.")
|
| 26 |
+
# Instantiate the Agent here
|
| 27 |
+
self.agent = Agent(
|
| 28 |
+
tools=get_tools(), # Pass whatever tools you want to the agent
|
| 29 |
+
prompt=None # Or a custom prompt, if necessary
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
def __call__(self, question: str, file_path: Optional[str] = None) -> str:
|
| 33 |
+
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 34 |
+
# Forward the question (and file_path if provided) to the Agent instance
|
| 35 |
+
answer = self.agent(question, file_path)
|
| 36 |
+
|
| 37 |
+
# Return the cleaned-up answer from the Agent
|
| 38 |
+
return answer
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 43 |
"""
|
| 44 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 61 |
|
| 62 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 63 |
try:
|
| 64 |
+
agent = BasicAgent()
|
|
|
|
|
|
|
| 65 |
except Exception as e:
|
| 66 |
print(f"Error instantiating agent: {e}")
|
| 67 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 69 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 70 |
print(agent_code)
|
| 71 |
|
| 72 |
+
|
| 73 |
# 2. Fetch Questions
|
| 74 |
print(f"Fetching questions from: {questions_url}")
|
| 75 |
try:
|