Spaces:
Sleeping
Sleeping
Update app.py
Browse files5 unmodified lines678910111210 unmodified lines2324252627282911 unmodified lines41424344454647484924 unmodified lines747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211 unmodified lines1241251261271281291305 unmodified linesDEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"agent = GaiaAgent()def run_and_submit_all(profile: gr.OAuthProfile | None):space_id = os.getenv("SPACE_ID")10 unmodified linessubmit_url = f"{api_url}/submit"try:agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"response = requests.get(questions_url, timeout=15)response.raise_for_status()questions_data = response.json()11 unmodified linescontinuetry:final_answer, trace = agent(question_text)print(f"\n--- QUESTION ---\nTask ID: {task_id}\nQuestion: {question_text}")print(f"\n--- REASONING TRACE ---\n{trace}")print(f"\n--- FINAL ANSWER (SUBMITTED) ---\n{final_answer}")answers_payload.append({"task_id": task_id,24 unmodified linesf"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"f"Message: {result_data.get('message', 'No message received.')}")return final_status, pd.DataFrame(results_log)except Exception as e:return f"Submission Failed: {e}", pd.DataFrame(results_log)def evaluate(question, files):uploaded_files = {}if files:for file in files:file_path = file.namefile.save(file_path)uploaded_files[file.name] = file_pathprediction, reasoning = agent(question, uploaded_files)return prediction, reasoningwith gr.Blocks() as demo:gr.Markdown("# GAIA Agent Interface")gr.Markdown("Logga in och kör agenten på alla frågor eller testa enskilda.")with gr.Tab("✅ Run Full Evaluation"):gr.LoginButton()run_button = gr.Button("Run Evaluation & Submit All Answers")status_output = gr.Textbox(label="Submission Result")results_table = gr.DataFrame(label="Answers")run_button.click(fn=run_and_submit_all, outputs=[status_output, results_table])with gr.Tab("🔍 Test Manual Question"):question = gr.Textbox(label="Question")files = gr.File(label="Optional files (mp3, wav, xlsx)", file_types=['.mp3', '.wav', '.xlsx'], type="filepath", file_count="multiple")submit = gr.Button("Run Agent")answer = gr.Textbox(label="Answer")reasoning = gr.Textbox(label="Reasoning Trace")submit.click(fn=evaluate, inputs=[question, files], outputs=[answer, reasoning])if __name__ == "__main__":print("\n" + "-"*30 + " App Starting " + "-"*30)11 unmodified linesprint(f" Repo URL: https://huggingface.co/spaces/{space_id_startup}")print(f" Repo Tree URL: https://huggingface.co/spaces/{space_id_startup}/tree/main")else:print("ℹ️ SPACE_ID environment variable not found (running locally?).")print("-"*(60 + len(" App Starting ")) + "\n")5 unmodified lines6789101110 unmodified lines2223242526272829303132333411 unmodified lines464748495051525354555657585924 unmodified lines8485868788899091929394959697989910010110210310410510610710811 unmodified lines1201211221231241251265 unmodified linesDEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"def run_and_submit_all(profile: gr.OAuthProfile | None):space_id = os.getenv("SPACE_ID")10 unmodified linessubmit_url = f"{api_url}/submit"try:agent = GaiaAgent()except Exception as e:return f"Error initializing agent: {e}", Noneagent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"try:response = requests.get(questions_url, timeout=15)response.raise_for_status()questions_data = response.json()11 unmodified linescontinuetry:final_answer, trace = agent(question_text)print("\n--- QUESTION ---")print(f"Task ID: {task_id}")print(f"Question: {question_text}")print("\n--- REASONING TRACE ---")print(trace)print("\n--- FINAL ANSWER (SUBMITTED) ---")print(final_answer)answers_payload.append({"task_id": task_id,24 unmodified linesf"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"f"Message: {result_data.get('message', 'No message received.')}")results_df = pd.DataFrame(results_log)return final_status, results_dfexcept Exception as e:return f"Submission Failed: {e}", pd.DataFrame(results_log)with gr.Blocks() as demo:gr.Markdown("# GAIA Agent Submission Interface")gr.Markdown("""Logga in och kör agenten.\nDu behöver INTE en OpenAI API-nyckel längre. Agenten kör en lokal modell.""")gr.LoginButton()run_button = gr.Button("Run Evaluation & Submit All Answers")status_output = gr.Textbox(label="Submission Result")results_table = gr.DataFrame(label="Answers")run_button.click(fn=run_and_submit_all, outputs=[status_output, results_table])if __name__ == "__main__":print("\n" + "-"*30 + " App Starting " + "-"*30)11 unmodified linesprint(f" Repo URL: https://huggingface.co/spaces/{space_id_startup}")print(f" Repo Tree URL: https://huggingface.co/spaces/{space_id_startup}/tree/main")else:print("ℹ️ SPACE_ID environment variable not found (running locally?). Repo URL cannot be determined.")print("-"*(60 + len(" App Starting ")) + "\n")
app.py+30-34