Download evaluate_local.py from GuillaumeEngel/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 2.49 kB
-
https://huggingface.co/spaces/GuillaumeEngel/Final_Assignment_Template/resolve/main/evaluate_local.py
- Command line
-
hf download hf://spaces/GuillaumeEngel/Final_Assignment_Template/evaluate_local.py
-
curl -L -o evaluate_local.py https://huggingface.co/spaces/GuillaumeEngel/Final_Assignment_Template/resolve/main/evaluate_local.py
2.49 kB
| """Run the assignment agent locally without submitting results.""" | |
| import argparse | |
| import textwrap | |
| import requests | |
| from agent import BasicAgent | |
| DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space" | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument( | |
| "--limit", | |
| type=int, | |
| default=None, | |
| help="Evaluate only the first N questions.", | |
| ) | |
| parser.add_argument( | |
| "--start", | |
| type=int, | |
| default=0, | |
| help="Skip the first N questions.", | |
| ) | |
| parser.add_argument( | |
| "--task-id", | |
| action="append", | |
| dest="task_ids", | |
| help="Evaluate only these task ids. Repeatable.", | |
| ) | |
| parser.add_argument( | |
| "--model", | |
| default=None, | |
| help="Model id to use, e.g. anthropic/claude-opus-4-1. Defaults to the configured model.", | |
| ) | |
| args = parser.parse_args() | |
| response = requests.get(f"{DEFAULT_API_URL}/questions", timeout=15) | |
| response.raise_for_status() | |
| questions = response.json() | |
| if args.task_ids: | |
| questions = [q for q in questions if q.get("task_id") in set(args.task_ids)] | |
| else: | |
| questions = questions[args.start:] | |
| if args.limit is not None: | |
| questions = questions[:args.limit] | |
| print("\n" + "=" * 72) | |
| print(f"LOCAL EVALUATION | {len(questions)} question(s)") | |
| print("Nothing will be submitted.") | |
| print("=" * 72) | |
| agent = BasicAgent(verbose=True, model_id=args.model) | |
| for index, item in enumerate(questions, start=1): | |
| task_id = item.get("task_id") | |
| question = item.get("question") | |
| if not task_id or question is None: | |
| print(f"\n--- Question {index} | SKIPPED ---") | |
| print(f"Malformed question: {item}") | |
| continue | |
| print(f"\n--- Question {index} | {task_id} | TRACE ---") | |
| print("Question:") | |
| print(textwrap.indent(question, " ")) | |
| print("Loop:") | |
| try: | |
| answer = agent(question, task_id=task_id, file_name=item.get("file_name")) | |
| except Exception as error: | |
| print(f"\n--- Question {index} | {task_id} | ERROR ---") | |
| print(f"{error}") | |
| continue | |
| print(f"\n--- Question {index} | {task_id} ---") | |
| print("Answer:") | |
| print(textwrap.indent(answer, " ")) | |
| print("\n" + "=" * 72) | |
| print("LOCAL EVALUATION COMPLETE") | |
| print("=" * 72) | |
| if __name__ == "__main__": | |
| main() | |