Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ import pandas as pd
|
|
| 7 |
from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 8 |
from huggingface_hub import InferenceClient
|
| 9 |
import json
|
|
|
|
| 10 |
|
| 11 |
api_url = "https://agents-course-unit4-scoring.hf.space"
|
| 12 |
questions_url = f"{api_url}/questions"
|
|
@@ -65,6 +66,22 @@ def load_questions_from_file(filepath="questions.json"):
|
|
| 65 |
else:
|
| 66 |
print("No data found.")
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
run_and_submit_one()
|
| 69 |
|
| 70 |
|
|
|
|
| 7 |
from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 8 |
from huggingface_hub import InferenceClient
|
| 9 |
import json
|
| 10 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 11 |
|
| 12 |
api_url = "https://agents-course-unit4-scoring.hf.space"
|
| 13 |
questions_url = f"{api_url}/questions"
|
|
|
|
| 66 |
else:
|
| 67 |
print("No data found.")
|
| 68 |
|
| 69 |
+
# 3. Run your Agent
|
| 70 |
+
results_log = []
|
| 71 |
+
answers_payload = []
|
| 72 |
+
|
| 73 |
+
try:
|
| 74 |
+
submitted_answer = agent(question_text)
|
| 75 |
+
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
| 76 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
| 77 |
+
except Exception as e:
|
| 78 |
+
print(f"Error running agent on task {task_id}: {e}")
|
| 79 |
+
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
|
| 80 |
+
|
| 81 |
+
if not answers_payload:
|
| 82 |
+
print("Agent did not produce any answers to submit.")
|
| 83 |
+
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 84 |
+
|
| 85 |
run_and_submit_one()
|
| 86 |
|
| 87 |
|