Spaces:
Sleeping
Sleeping
File size: 4,191 Bytes
05919ff 522e6c3 69e4888 16f1cd8 69e4888 16f1cd8 69e4888 16f1cd8 69e4888 16f1cd8 69e4888 16f1cd8 69e4888 05919ff 522e6c3 16f1cd8 05919ff 69e4888 05919ff 522e6c3 05919ff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
import requests
import config
def getQuestions():
try:
response = requests.get(config.questionsUrl, timeout=15)
response.raise_for_status()
questions_data = response.json()
if not questions_data:
print("Fetched questions list is empty.")
raise Exception("Fetched questions list is empty")
print(f"Fetched {len(questions_data)} questions.")
return questions_data
except Exception as e:
print(f"An unexpected error occurred fetching questions: {e}")
return None
def getQuestionByPos(i):
questions = getQuestions()
return questions[i]
def printQuestions():
for i,question in enumerate(getQuestions()):
print(f"{i+1}. ({question['task_id']}): {question['question']} {'(File: ' + question['file_name'] + ')' if question['file_name'] else ''}\n\n")
def submitAnswers(answers):
submissionData = {
"username": "jproman",
"agent_code": "https://huggingface.co/spaces/jproman/Final_Assignment_Template/tree/main",
"answers": answers
}
response = requests.post(config.submitUrl, json=submissionData, timeout=60)
response.raise_for_status()
resultData = response.json()
finalStatus = (
f"Submission Successful!\n"
f"User: {resultData.get('username')}\n"
f"Overall Score: {resultData.get('score', 'N/A')}% "
f"({resultData.get('correct_count', '?')}/{resultData.get('total_attempted', '?')} correct)\n"
f"Message: {resultData.get('message', 'No message received.')}"
)
return finalStatus
def getTestAnswers():
return [
{"task_id": "8e867cd7-cff9-4e6c-867a-ff5ddc2550be", "submitted_answer": "test answer"},
{"task_id": "a1e91b78-d3d8-4675-bb8d-62741b4b68a6", "submitted_answer": "test answer"},
{"task_id": "2d83110e-a098-4ebb-9987-066c06fa42d0", "submitted_answer": "test answer"},
{"task_id": "cca530fc-4052-43b2-b130-b30968d8aa44", "submitted_answer": "test answer"},
{"task_id": "4fc2f1ae-8625-45b5-ab34-ad4433bc21f8", "submitted_answer": "test answer"},
{"task_id": "6f37996b-2ac7-44b0-8e68-6d28256631b4", "submitted_answer": "test answer"},
{"task_id": "9d191bce-651d-4746-be2d-7ef8ecadb9c2", "submitted_answer": "test answer"},
{"task_id": "cabe07ed-9eca-40ea-8ead-410ef5e83f91", "submitted_answer": "test answer"},
{"task_id": "3cef3a44-215e-4aed-8e3b-b1e3f08063b7", "submitted_answer": "test answer"},
{"task_id": "99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3", "submitted_answer": "test answer"},
{"task_id": "305ac316-eef6-4446-960a-92d80d542f82", "submitted_answer": "test answer"},
{"task_id": "f918266a-b3e0-4914-865d-4faa564f1aef", "submitted_answer": "test answer"},
{"task_id": "3f57289b-8c60-48be-bd80-01f8099ca449", "submitted_answer": "test answer"},
{"task_id": "1f975693-876d-457b-a649-393859e79bf3", "submitted_answer": "test answer"},
{"task_id": "840bfca7-4f7b-481a-8794-c560c340185d", "submitted_answer": "test answer"},
{"task_id": "bda648d7-d618-4883-88f4-3466eabd860e", "submitted_answer": "test answer"},
{"task_id": "cf106601-ab4f-4af9-b045-5295fe67b37d", "submitted_answer": "test answer"},
{"task_id": "a0c07678-e491-4bbc-8f0b-07405144218f", "submitted_answer": "test answer"},
{"task_id": "7bd855d8-463d-4ed5-93ca-5fe35145f733", "submitted_answer": "test answer"},
{"task_id": "5a0c1adf-205e-4841-a666-7c3ef95def9d", "submitted_answer": "test answer"},
]
def submitFirstAnswers(n,agent):
questions = getQuestions()
answers = getTestAnswers()
for i in range(n):
response = agent.invoke(questions[i]['question'])
answers[i]["submitted_answer"] = response
finalStatus = submitAnswers(answers)
print(finalStatus)
if __name__ == "__main__":
# https://huggingface.co/spaces/agents-course/Students_leaderboard
questions = getQuestions()
printQuestions()
#from logger import Logger
#logger = Logger(config.logLevel,config.logFile)
#agent = Agent(logger)
#response = submitAnswers(getTestAnswers())
#print(response)
|