Spaces:
Build error
Build error
Update app.py
Browse files3 unmodified lines45678910111213141516171819202158 unmodified lines808182838485863 unmodified linesimport inspectimport pandas as pd# (Keep Constants as is)# --- Constants ---DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"# --- Basic Agent Definition ---# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------class BasicAgent:def __init__(self):print("BasicAgent initialized.")def __call__(self, question: str) -> str:print(f"Agent received question (first 50 chars): {question[:50]}...")fixed_answer = "This is a default answer."print(f"Agent returning fixed answer: {fixed_answer}")return fixed_answer58 unmodified linesprint(f"Skipping item with missing task_id or question: {item}")continuetry:submitted_answer = agent(question_text)answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})except Exception as e:3 unmodified lines45678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838458 unmodified lines1431441451461471481493 unmodified linesimport inspectimport pandas as pdfrom smolagents import ToolCallingAgent, HfApiModel, DuckDuckGoSearchTool, PythonInterpreterToolfrom smolagents import OpenAIServerModelfrom agentsTools.toolVisitWebpage import visit_webpagefrom agentsTools.tool_fetch_task_file import fetch_task_filefrom agentsTools.tool_read_excel_as_json import read_excel_as_json# (Keep Constants as is)# --- Constants ---DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"hf_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")def get_gemini_model():return OpenAIServerModel(model_id="gemini-2.5-pro-preview-03-25",api_base="https://generativelanguage.googleapis.com/v1beta/",api_key=os.getenv("GEMINI_API_KEY", "your-gemini-api-key-here"))model = get_gemini_model()# --- Basic Agent Definition ---# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------class BasicAgent:def __init__(self):print("BasicAgent initialized.")def __call__(self, question: str, taskid: str) -> str:print(f"Agent received question (first 50 chars): {question[:50]}...")agent = ToolCallingAgent(tools=[DuckDuckGoSearchTool(),PythonInterpreterTool(),visit_webpage,fetch_task_file,read_excel_as_json,# update_File,],#model=HfApiModel(api_key=hf_token),model=model,max_steps=10)task = f"""You are a general AI assistant.I will ask you a question and you can use 8 steps to answer it.You can use the tools I provided to you to answer the question.Every time you use a tool, the number of steps will decrease by one.If you have a list of possible pages to visit, prefer the wikipedia ones.If a page does not allow visit, skip it.Report your thoughts, and finish your answer with the following template:FINAL ANSWER: [YOUR FINAL ANSWER].YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.The taskid is {taskid} in case you need to get extra files, use taskid and not name of the fileand the question is {question}"""# Let the agent drive the task execution (ReAct loop)# fixed_answer = "This is a default answer."fixed_answer = agent.run(task)print(f"Agent returning fixed answer: {fixed_answer}")return fixed_answer58 unmodified linesprint(f"Skipping item with missing task_id or question: {item}")continuetry:submitted_answer = agent(question_text,task_id)answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})except Exception as e:
app.py+66-3