Spaces:
Sleeping
Sleeping
Update app.py
Browse files1232 unmodified lines678910119 unmodified lines2122232425262728293031323311 unmodified lines454647484950515253545556575824 unmodified lines838485868788899091929394959697989910010110210310410510610711 unmodified lines119120121122123124125126127128import osimport gradio as grimport requests2 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")9 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")print("Launching Gradio Interface for Basic Agent Evaluation...")demo.launch(debug=True, share=False)12342 unmodified lines78910111213149 unmodified lines2425262728293011 unmodified lines42434445464748495024 unmodified lines7576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311 unmodified lines125126127128129130131132133134# --- app.py ---import osimport gradio as grimport requests2 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")9 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="file", 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")print("Launching Gradio Interface for Basic Agent Evaluation...")demo.launch(debug=True, share=False)
app.py+37-31