{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84795,"databundleVersionId":10934030,"sourceType":"competition"}],"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false},"papermill":{"default_parameters":{},"duration":22.341371,"end_time":"2024-12-11T03:22:13.479076","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2024-12-11T03:21:51.137705","version":"2.6.0"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import io\nimport os\nimport kaggle_evaluation.konwinski_prize_inference_server\nimport concurrent.futures\nimport time","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.status.busy":"2025-02-13T12:32:27.921883Z","iopub.execute_input":"2025-02-13T12:32:27.922366Z","iopub.status.idle":"2025-02-13T12:32:42.227138Z","shell.execute_reply.started":"2025-02-13T12:32:27.92233Z","shell.execute_reply":"2025-02-13T12:32:42.225888Z"},"papermill":{"duration":14.873526,"end_time":"2024-12-11T03:22:08.818755","exception":false,"start_time":"2024-12-11T03:21:53.945229","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"instance_count = None\n\ndef get_number_of_instances(num_instances: int) -> None:\n    \"\"\" The very first message from the gateway will be the total number of instances to be served.\n    You don't need to edit this function.\n    \"\"\"\n    global instance_count\n    instance_count = num_instances\n\nexecutor = concurrent.futures.ProcessPoolExecutor(max_workers=1)\n\ndef predict(problem_statement: str, repo_archive: io.BytesIO, pip_packages_archive: io.BytesIO, env_setup_cmds_templates: list[str]) -> str:\n    try:\n        fut = executor.submit(predict_)\n        return fut.result(timeout=70)\n    except Exception as e:\n        print(f\"Exception in predict_: {e}\")\n        return \"\"\n\nSLEEP_INTERVAL = 5\n\ndef predict_():\n    i = 0\n    while True:\n        time.sleep(SLEEP_INTERVAL)\n        i += 1\n        print(f\"{i * SLEEP_INTERVAL} seconds passed\")\n    return \"ok\"","metadata":{"execution":{"iopub.status.busy":"2025-02-13T12:32:42.228287Z","iopub.execute_input":"2025-02-13T12:32:42.22916Z","iopub.status.idle":"2025-02-13T12:32:42.236933Z","shell.execute_reply.started":"2025-02-13T12:32:42.229131Z","shell.execute_reply":"2025-02-13T12:32:42.235985Z"},"papermill":{"duration":0.011949,"end_time":"2024-12-11T03:22:08.838279","exception":false,"start_time":"2024-12-11T03:22:08.82633","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Run inference\n\ndef main():\n    inference_server = kaggle_evaluation.konwinski_prize_inference_server.KPrizeInferenceServer(\n        get_number_of_instances,\n        predict\n    )\n\n    if os.getenv('KAGGLE_IS_COMPETITION_RERUN'):\n        inference_server.serve()\n    else:\n        inference_server.run_local_gateway(\n            data_paths=(\n                '/kaggle/input/konwinski-prize/',  # Path to the entire competition dataset\n                '/kaggle/tmp/konwinski-prize/',   # Path to a scratch directory for unpacking data.a_zip.\n            ),\n            use_concurrency=True,  # This can safely be disabled for purposes of local testing if necessary.\n        )\n\nif __name__ == \"__main__\":\n    try:\n        main()\n    except Exception as e:\n        print(f\"Main throw exception: {e}\")\n        if executor:\n            executor.shutdown(wait=False)","metadata":{"execution":{"iopub.status.busy":"2025-02-13T12:32:42.238177Z","iopub.execute_input":"2025-02-13T12:32:42.238477Z","iopub.status.idle":"2025-02-13T12:33:58.511851Z","shell.execute_reply.started":"2025-02-13T12:32:42.238445Z","shell.execute_reply":"2025-02-13T12:33:58.510018Z"},"papermill":{"duration":0.011382,"end_time":"2024-12-11T03:22:08.852112","exception":false,"start_time":"2024-12-11T03:22:08.84073","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null}]}