We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add an option to the bug_classifier script to download the model when it doesn't exist


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scripts/bug_classifier.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 import argparse
4 import os
5 
6 import numpy as np
7 
8 from bugbug import bugzilla
9 from bugbug.models import get_model_class
10 
11 MODELS_WITH_TYPE = ("component",)
12 
13 
14 def classify_bugs(model_name, classifier):
15     if classifier != "default":
16         assert (
17             model_name in MODELS_WITH_TYPE
18         ), f"{classifier} is not a valid classifier type for {model_name}"
19 
20         model_file_name = f"{model_name}{classifier}model"
21         model_name = f"{model_name}_{classifier}"
22     else:
23         model_file_name = f"{model_name}model"
24 
25     assert os.path.exists(
26         model_file_name
27     ), f"{model_file_name} does not exist. Train the model with trainer.py first."
28 
29     model_class = get_model_class(model_name)
30     model = model_class.load(model_file_name)
31 
32     for bug in bugzilla.get_bugs():
33         print(
34             f'https://bugzilla.mozilla.org/show_bug.cgi?id={bug["id"]} - {bug["summary"]} '
35         )
36 
37         if model.calculate_importance:
38             probas, importance = model.classify(
39                 bug, probabilities=True, importances=True
40             )
41 
42             feature_names = model.get_human_readable_feature_names()
43 
44             model.print_feature_importances(
45                 importance["importances"], feature_names, class_probabilities=probas
46             )
47         else:
48             probas = model.classify(bug, probabilities=True, importances=False)
49 
50         if np.argmax(probas) == 1:
51             print(f"Positive! {probas}")
52         else:
53             print(f"Negative! {probas}")
54         input()
55 
56 
57 def main():
58     description = "Perform evaluation on bugs using the specified model"
59     parser = argparse.ArgumentParser(description=description)
60 
61     parser.add_argument("model", help="Which model to use for evaluation")
62     parser.add_argument(
63         "--classifier",
64         help="Type of the classifier. Only used for component classification.",
65         choices=["default", "nn"],
66         default="default",
67     )
68 
69     args = parser.parse_args()
70 
71     classify_bugs(args.model, args.classifier)
72
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scripts/bug_classifier.py b/scripts/bug_classifier.py
--- a/scripts/bug_classifier.py
+++ b/scripts/bug_classifier.py
@@ -2,14 +2,20 @@
 
 import argparse
 import os
+from logging import INFO, basicConfig, getLogger
 
 import numpy as np
+import requests
 
 from bugbug import bugzilla
 from bugbug.models import get_model_class
+from bugbug.utils import download_check_etag, zstd_decompress
 
 MODELS_WITH_TYPE = ("component",)
 
+basicConfig(level=INFO)
+logger = getLogger(__name__)
+
 
 def classify_bugs(model_name, classifier):
     if classifier != "default":
@@ -22,9 +28,21 @@
     else:
         model_file_name = f"{model_name}model"
 
-    assert os.path.exists(
-        model_file_name
-    ), f"{model_file_name} does not exist. Train the model with trainer.py first."
+    if not os.path.exists(model_file_name):
+        logger.info(f"{model_file_name} does not exist. Downloading the model....")
+        try:
+            download_check_etag(
+                f"https://index.taskcluster.net/v1/task/project.relman.bugbug.train_{model_name}.latest/artifacts/public/{model_file_name}.zst",
+                f"{model_file_name}.zst",
+            )
+        except requests.HTTPError:
+            logger.error(
+                f"A pre-trained model is not available, you will need to train it yourself using the trainer script"
+            )
+            raise SystemExit(1)
+
+        zstd_decompress(model_file_name)
+        assert os.path.exists(model_file_name), "Decompressed file doesn't exist"
 
     model_class = get_model_class(model_name)
     model = model_class.load(model_file_name)

{"golden_diff": "diff --git a/scripts/bug_classifier.py b/scripts/bug_classifier.py\n--- a/scripts/bug_classifier.py\n+++ b/scripts/bug_classifier.py\n@@ -2,14 +2,20 @@\n \n import argparse\n import os\n+from logging import INFO, basicConfig, getLogger\n \n import numpy as np\n+import requests\n \n from bugbug import bugzilla\n from bugbug.models import get_model_class\n+from bugbug.utils import download_check_etag, zstd_decompress\n \n MODELS_WITH_TYPE = (\"component\",)\n \n+basicConfig(level=INFO)\n+logger = getLogger(__name__)\n+\n \n def classify_bugs(model_name, classifier):\n     if classifier != \"default\":\n@@ -22,9 +28,21 @@\n     else:\n         model_file_name = f\"{model_name}model\"\n \n-    assert os.path.exists(\n-        model_file_name\n-    ), f\"{model_file_name} does not exist. Train the model with trainer.py first.\"\n+    if not os.path.exists(model_file_name):\n+        logger.info(f\"{model_file_name} does not exist. Downloading the model....\")\n+        try:\n+            download_check_etag(\n+                f\"https://index.taskcluster.net/v1/task/project.relman.bugbug.train_{model_name}.latest/artifacts/public/{model_file_name}.zst\",\n+                f\"{model_file_name}.zst\",\n+            )\n+        except requests.HTTPError:\n+            logger.error(\n+                f\"A pre-trained model is not available, you will need to train it yourself using the trainer script\"\n+            )\n+            raise SystemExit(1)\n+\n+        zstd_decompress(model_file_name)\n+        assert os.path.exists(model_file_name), \"Decompressed file doesn't exist\"\n \n     model_class = get_model_class(model_name)\n     model = model_class.load(model_file_name)\n", "issue": "Add an option to the bug_classifier script to download the model when it doesn't exist\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport argparse\nimport os\n\nimport numpy as np\n\nfrom bugbug import bugzilla\nfrom bugbug.models import get_model_class\n\nMODELS_WITH_TYPE = (\"component\",)\n\n\ndef classify_bugs(model_name, classifier):\n    if classifier != \"default\":\n        assert (\n            model_name in MODELS_WITH_TYPE\n        ), f\"{classifier} is not a valid classifier type for {model_name}\"\n\n        model_file_name = f\"{model_name}{classifier}model\"\n        model_name = f\"{model_name}_{classifier}\"\n    else:\n        model_file_name = f\"{model_name}model\"\n\n    assert os.path.exists(\n        model_file_name\n    ), f\"{model_file_name} does not exist. Train the model with trainer.py first.\"\n\n    model_class = get_model_class(model_name)\n    model = model_class.load(model_file_name)\n\n    for bug in bugzilla.get_bugs():\n        print(\n            f'https://bugzilla.mozilla.org/show_bug.cgi?id={bug[\"id\"]} - {bug[\"summary\"]} '\n        )\n\n        if model.calculate_importance:\n            probas, importance = model.classify(\n                bug, probabilities=True, importances=True\n            )\n\n            feature_names = model.get_human_readable_feature_names()\n\n            model.print_feature_importances(\n                importance[\"importances\"], feature_names, class_probabilities=probas\n            )\n        else:\n            probas = model.classify(bug, probabilities=True, importances=False)\n\n        if np.argmax(probas) == 1:\n            print(f\"Positive! {probas}\")\n        else:\n            print(f\"Negative! {probas}\")\n        input()\n\n\ndef main():\n    description = \"Perform evaluation on bugs using the specified model\"\n    parser = argparse.ArgumentParser(description=description)\n\n    parser.add_argument(\"model\", help=\"Which model to use for evaluation\")\n    parser.add_argument(\n        \"--classifier\",\n        help=\"Type of the classifier. Only used for component classification.\",\n        choices=[\"default\", \"nn\"],\n        default=\"default\",\n    )\n\n    args = parser.parse_args()\n\n    classify_bugs(args.model, args.classifier)\n", "path": "scripts/bug_classifier.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport argparse\nimport os\nfrom logging import INFO, basicConfig, getLogger\n\nimport numpy as np\nimport requests\n\nfrom bugbug import bugzilla\nfrom bugbug.models import get_model_class\nfrom bugbug.utils import download_check_etag, zstd_decompress\n\nMODELS_WITH_TYPE = (\"component\",)\n\nbasicConfig(level=INFO)\nlogger = getLogger(__name__)\n\n\ndef classify_bugs(model_name, classifier):\n    if classifier != \"default\":\n        assert (\n            model_name in MODELS_WITH_TYPE\n        ), f\"{classifier} is not a valid classifier type for {model_name}\"\n\n        model_file_name = f\"{model_name}{classifier}model\"\n        model_name = f\"{model_name}_{classifier}\"\n    else:\n        model_file_name = f\"{model_name}model\"\n\n    if not os.path.exists(model_file_name):\n        logger.info(f\"{model_file_name} does not exist. Downloading the model....\")\n        try:\n            download_check_etag(\n                f\"https://index.taskcluster.net/v1/task/project.relman.bugbug.train_{model_name}.latest/artifacts/public/{model_file_name}.zst\",\n                f\"{model_file_name}.zst\",\n            )\n        except requests.HTTPError:\n            logger.error(\n                f\"A pre-trained model is not available, you will need to train it yourself using the trainer script\"\n            )\n            raise SystemExit(1)\n\n        zstd_decompress(model_file_name)\n        assert os.path.exists(model_file_name), \"Decompressed file doesn't exist\"\n\n    model_class = get_model_class(model_name)\n    model = model_class.load(model_file_name)\n\n    for bug in bugzilla.get_bugs():\n        print(\n            f'https://bugzilla.mozilla.org/show_bug.cgi?id={bug[\"id\"]} - {bug[\"summary\"]} '\n        )\n\n        if model.calculate_importance:\n            probas, importance = model.classify(\n                bug, probabilities=True, importances=True\n            )\n\n            feature_names = model.get_human_readable_feature_names()\n\n            model.print_feature_importances(\n                importance[\"importances\"], feature_names, class_probabilities=probas\n            )\n        else:\n            probas = model.classify(bug, probabilities=True, importances=False)\n\n        if np.argmax(probas) == 1:\n            print(f\"Positive! {probas}\")\n        else:\n            print(f\"Negative! {probas}\")\n        input()\n\n\ndef main():\n    description = \"Perform evaluation on bugs using the specified model\"\n    parser = argparse.ArgumentParser(description=description)\n\n    parser.add_argument(\"model\", help=\"Which model to use for evaluation\")\n    parser.add_argument(\n        \"--classifier\",\n        help=\"Type of the classifier. Only used for component classification.\",\n        choices=[\"default\", \"nn\"],\n        default=\"default\",\n    )\n\n    args = parser.parse_args()\n\n    classify_bugs(args.model, args.classifier)\n", "path": "scripts/bug_classifier.py"}]}