We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
`choices` turn input to enum type
With 'choices' of strings, the input is no long string but changed to enum type. 
Refer to https://github.com/wty-ustc/HairCLIP/pull/16/files#diff-73c1982d8a085dc10fda2ac7b6f202ae3ff9530ee6a15991c5339051eb10a49aR61, where `editing_type` should be string eg. "both" but the value shows `editing_type.both` and type `<enum 'editing_type'>`



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `python/cog/predictor.py`
Content:
```
1 from abc import ABC, abstractmethod
2 from collections.abc import Iterator
3 import enum
4 import importlib
5 import inspect
6 import os.path
7 from pathlib import Path
8 from pydantic import create_model, BaseModel
9 from pydantic.fields import FieldInfo
10 from typing import List
11 
12 # Added in Python 3.8. Can be from typing if we drop support for <3.8.
13 from typing_extensions import get_origin, get_args
14 import yaml
15 
16 from .errors import ConfigDoesNotExist, PredictorNotSet
17 from .types import Input, Path as CogPath, File as CogFile
18 
19 
20 ALLOWED_INPUT_TYPES = [str, int, float, bool, CogFile, CogPath]
21 
22 
23 class BasePredictor(ABC):
24     def setup(self):
25         """
26         An optional method to prepare the model so multiple predictions run efficiently.
27         """
28 
29     @abstractmethod
30     def predict(self, **kwargs):
31         """
32         Run a single prediction on the model
33         """
34 
35 
36 def run_prediction(predictor, inputs, cleanup_functions):
37     """
38     Run the predictor on the inputs, and append resulting paths
39     to cleanup functions for removal.
40     """
41     result = predictor.predict(**inputs)
42     if isinstance(result, Path):
43         cleanup_functions.append(result.unlink)
44     return result
45 
46 
47 def load_predictor():
48     """
49     Reads cog.yaml and constructs an instance of the user-defined Predictor class.
50     """
51 
52     # Assumes the working directory is /src
53     config_path = os.path.abspath("cog.yaml")
54     try:
55         with open(config_path) as fh:
56             config = yaml.safe_load(fh)
57     except FileNotFoundError:
58         raise ConfigDoesNotExist(
59             f"Could not find {config_path}",
60         )
61 
62     if "predict" not in config:
63         raise PredictorNotSet(
64             "Can't run predictions: 'predict' option not found in cog.yaml"
65         )
66 
67     predict_string = config["predict"]
68     module_path, class_name = predict_string.split(":", 1)
69     module_name = os.path.basename(module_path).split(".py", 1)[0]
70     spec = importlib.util.spec_from_file_location(module_name, module_path)
71     module = importlib.util.module_from_spec(spec)
72     spec.loader.exec_module(module)
73     predictor_class = getattr(module, class_name)
74     return predictor_class()
75 
76 
77 # Base class for inputs, constructed dynamically in get_input_type().
78 # (This can't be a docstring or it gets passed through to the schema.)
79 class BaseInput(BaseModel):
80     def cleanup(self):
81         """
82         Cleanup any temporary files created by the input.
83         """
84         for _, value in self:
85             # Note this is pathlib.Path, which cog.Path is a subclass of. A pathlib.Path object shouldn't make its way here,
86             # but both have an unlink() method, so may as well be safe.
87             if isinstance(value, Path):
88                 # This could be missing_ok=True when we drop support for Python 3.7
89                 if value.exists():
90                     value.unlink()
91 
92 
93 def get_input_type(predictor: BasePredictor):
94     """
95     Creates a Pydantic Input model from the arguments of a Predictor's predict() method.
96 
97     class Predictor(BasePredictor):
98         def predict(self, text: str):
99             ...
100 
101     programmatically creates a model like this:
102 
103     class Input(BaseModel):
104         text: str
105     """
106 
107     signature = inspect.signature(predictor.predict)
108     create_model_kwargs = {}
109 
110     order = 0
111 
112     for name, parameter in signature.parameters.items():
113         InputType = parameter.annotation
114 
115         if InputType is inspect.Signature.empty:
116             raise TypeError(
117                 f"No input type provided for parameter `{name}`. Supported input types are: {readable_types_list(ALLOWED_INPUT_TYPES)}."
118             )
119         elif InputType not in ALLOWED_INPUT_TYPES:
120             raise TypeError(
121                 f"Unsupported input type {human_readable_type_name(InputType)} for parameter `{name}`. Supported input types are: {readable_types_list(ALLOWED_INPUT_TYPES)}."
122             )
123 
124         # if no default is specified, create an empty, required input
125         if parameter.default is inspect.Signature.empty:
126             default = Input()
127         else:
128             default = parameter.default
129             # If user hasn't used `Input`, then wrap it in that
130             if not isinstance(default, FieldInfo):
131                 default = Input(default=default)
132 
133         # Fields aren't ordered, so use this pattern to ensure defined order
134         # https://github.com/go-openapi/spec/pull/116
135         default.extra["x-order"] = order
136         order += 1
137 
138         # Choices!
139         if default.extra.get("choices"):
140             choices = default.extra["choices"]
141             # It will be passed automatically as 'enum' in the schema, so remove it as an extra field.
142             del default.extra["choices"]
143             if InputType == str:
144 
145                 class StringEnum(str, enum.Enum):
146                     pass
147 
148                 InputType = StringEnum(name, {value: value for value in choices})
149             elif InputType == int:
150                 InputType = enum.IntEnum(name, {str(value): value for value in choices})
151             else:
152                 raise TypeError(
153                     f"The input {name} uses the option choices. Choices can only be used with str or int types."
154                 )
155 
156         create_model_kwargs[name] = (InputType, default)
157 
158     return create_model("Input", **create_model_kwargs, __base__=BaseInput)
159 
160 
161 def get_output_type(predictor: BasePredictor):
162     """
163     Creates a Pydantic Output model from the return type annotation of a Predictor's predict() method.
164     """
165 
166     signature = inspect.signature(predictor.predict)
167     if signature.return_annotation is inspect.Signature.empty:
168         raise TypeError(
169             """You must set an output type. If your model can return multiple output types, you can explicitly set `Any` as the output type.
170 
171 For example:
172 
173     from typing import Any
174 
175     def predict(
176         self,
177         image: Path = Input(description="Input image"),
178     ) -> Any:
179         ...
180 """
181         )
182     else:
183         OutputType = signature.return_annotation
184 
185     # The type that goes in the response is a list of the yielded type
186     if get_origin(OutputType) is Iterator:
187         OutputType = List[get_args(OutputType)[0]]
188 
189     if not hasattr(OutputType, "__name__") or OutputType.__name__ != "Output":
190         # Wrap the type in a model called "Output" so it is a consistent name in the OpenAPI schema
191         class Output(BaseModel):
192             __root__: OutputType
193 
194         OutputType = Output
195 
196     return OutputType
197 
198 
199 def human_readable_type_name(t):
200     """
201     Generates a useful-for-humans label for a type. For builtin types, it's just the class name (eg "str" or "int"). For other types, it includes the module (eg "pathlib.Path" or "cog.File").
202 
203     The special case for Cog modules is because the type lives in `cog.types` internally, but just `cog` when included as a dependency.
204     """
205     module = t.__module__
206     if module == "builtins":
207         return t.__qualname__
208     elif module.split(".")[0] == "cog":
209         module = "cog"
210     return module + "." + t.__qualname__
211 
212 
213 def readable_types_list(type_list):
214     return ", ".join(human_readable_type_name(t) for t in type_list)
215
```
--- 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/python/cog/predictor.py b/python/cog/predictor.py
--- a/python/cog/predictor.py
+++ b/python/cog/predictor.py
@@ -77,6 +77,11 @@
 # Base class for inputs, constructed dynamically in get_input_type().
 # (This can't be a docstring or it gets passed through to the schema.)
 class BaseInput(BaseModel):
+    class Config:
+        # When using `choices`, the type is converted into an enum to validate
+        # But, after validation, we want to pass the actual value to predict(), not the enum object
+        use_enum_values = True
+
     def cleanup(self):
         """
         Cleanup any temporary files created by the input.

{"golden_diff": "diff --git a/python/cog/predictor.py b/python/cog/predictor.py\n--- a/python/cog/predictor.py\n+++ b/python/cog/predictor.py\n@@ -77,6 +77,11 @@\n # Base class for inputs, constructed dynamically in get_input_type().\n # (This can't be a docstring or it gets passed through to the schema.)\n class BaseInput(BaseModel):\n+    class Config:\n+        # When using `choices`, the type is converted into an enum to validate\n+        # But, after validation, we want to pass the actual value to predict(), not the enum object\n+        use_enum_values = True\n+\n     def cleanup(self):\n         \"\"\"\n         Cleanup any temporary files created by the input.\n", "issue": "`choices` turn input to enum type\nWith 'choices' of strings, the input is no long string but changed to enum type. \r\nRefer to https://github.com/wty-ustc/HairCLIP/pull/16/files#diff-73c1982d8a085dc10fda2ac7b6f202ae3ff9530ee6a15991c5339051eb10a49aR61, where `editing_type` should be string eg. \"both\" but the value shows `editing_type.both` and type `<enum 'editing_type'>`\r\n\r\n\n", "before_files": [{"content": "from abc import ABC, abstractmethod\nfrom collections.abc import Iterator\nimport enum\nimport importlib\nimport inspect\nimport os.path\nfrom pathlib import Path\nfrom pydantic import create_model, BaseModel\nfrom pydantic.fields import FieldInfo\nfrom typing import List\n\n# Added in Python 3.8. Can be from typing if we drop support for <3.8.\nfrom typing_extensions import get_origin, get_args\nimport yaml\n\nfrom .errors import ConfigDoesNotExist, PredictorNotSet\nfrom .types import Input, Path as CogPath, File as CogFile\n\n\nALLOWED_INPUT_TYPES = [str, int, float, bool, CogFile, CogPath]\n\n\nclass BasePredictor(ABC):\n    def setup(self):\n        \"\"\"\n        An optional method to prepare the model so multiple predictions run efficiently.\n        \"\"\"\n\n    @abstractmethod\n    def predict(self, **kwargs):\n        \"\"\"\n        Run a single prediction on the model\n        \"\"\"\n\n\ndef run_prediction(predictor, inputs, cleanup_functions):\n    \"\"\"\n    Run the predictor on the inputs, and append resulting paths\n    to cleanup functions for removal.\n    \"\"\"\n    result = predictor.predict(**inputs)\n    if isinstance(result, Path):\n        cleanup_functions.append(result.unlink)\n    return result\n\n\ndef load_predictor():\n    \"\"\"\n    Reads cog.yaml and constructs an instance of the user-defined Predictor class.\n    \"\"\"\n\n    # Assumes the working directory is /src\n    config_path = os.path.abspath(\"cog.yaml\")\n    try:\n        with open(config_path) as fh:\n            config = yaml.safe_load(fh)\n    except FileNotFoundError:\n        raise ConfigDoesNotExist(\n            f\"Could not find {config_path}\",\n        )\n\n    if \"predict\" not in config:\n        raise PredictorNotSet(\n            \"Can't run predictions: 'predict' option not found in cog.yaml\"\n        )\n\n    predict_string = config[\"predict\"]\n    module_path, class_name = predict_string.split(\":\", 1)\n    module_name = os.path.basename(module_path).split(\".py\", 1)[0]\n    spec = importlib.util.spec_from_file_location(module_name, module_path)\n    module = importlib.util.module_from_spec(spec)\n    spec.loader.exec_module(module)\n    predictor_class = getattr(module, class_name)\n    return predictor_class()\n\n\n# Base class for inputs, constructed dynamically in get_input_type().\n# (This can't be a docstring or it gets passed through to the schema.)\nclass BaseInput(BaseModel):\n    def cleanup(self):\n        \"\"\"\n        Cleanup any temporary files created by the input.\n        \"\"\"\n        for _, value in self:\n            # Note this is pathlib.Path, which cog.Path is a subclass of. A pathlib.Path object shouldn't make its way here,\n            # but both have an unlink() method, so may as well be safe.\n            if isinstance(value, Path):\n                # This could be missing_ok=True when we drop support for Python 3.7\n                if value.exists():\n                    value.unlink()\n\n\ndef get_input_type(predictor: BasePredictor):\n    \"\"\"\n    Creates a Pydantic Input model from the arguments of a Predictor's predict() method.\n\n    class Predictor(BasePredictor):\n        def predict(self, text: str):\n            ...\n\n    programmatically creates a model like this:\n\n    class Input(BaseModel):\n        text: str\n    \"\"\"\n\n    signature = inspect.signature(predictor.predict)\n    create_model_kwargs = {}\n\n    order = 0\n\n    for name, parameter in signature.parameters.items():\n        InputType = parameter.annotation\n\n        if InputType is inspect.Signature.empty:\n            raise TypeError(\n                f\"No input type provided for parameter `{name}`. Supported input types are: {readable_types_list(ALLOWED_INPUT_TYPES)}.\"\n            )\n        elif InputType not in ALLOWED_INPUT_TYPES:\n            raise TypeError(\n                f\"Unsupported input type {human_readable_type_name(InputType)} for parameter `{name}`. Supported input types are: {readable_types_list(ALLOWED_INPUT_TYPES)}.\"\n            )\n\n        # if no default is specified, create an empty, required input\n        if parameter.default is inspect.Signature.empty:\n            default = Input()\n        else:\n            default = parameter.default\n            # If user hasn't used `Input`, then wrap it in that\n            if not isinstance(default, FieldInfo):\n                default = Input(default=default)\n\n        # Fields aren't ordered, so use this pattern to ensure defined order\n        # https://github.com/go-openapi/spec/pull/116\n        default.extra[\"x-order\"] = order\n        order += 1\n\n        # Choices!\n        if default.extra.get(\"choices\"):\n            choices = default.extra[\"choices\"]\n            # It will be passed automatically as 'enum' in the schema, so remove it as an extra field.\n            del default.extra[\"choices\"]\n            if InputType == str:\n\n                class StringEnum(str, enum.Enum):\n                    pass\n\n                InputType = StringEnum(name, {value: value for value in choices})\n            elif InputType == int:\n                InputType = enum.IntEnum(name, {str(value): value for value in choices})\n            else:\n                raise TypeError(\n                    f\"The input {name} uses the option choices. Choices can only be used with str or int types.\"\n                )\n\n        create_model_kwargs[name] = (InputType, default)\n\n    return create_model(\"Input\", **create_model_kwargs, __base__=BaseInput)\n\n\ndef get_output_type(predictor: BasePredictor):\n    \"\"\"\n    Creates a Pydantic Output model from the return type annotation of a Predictor's predict() method.\n    \"\"\"\n\n    signature = inspect.signature(predictor.predict)\n    if signature.return_annotation is inspect.Signature.empty:\n        raise TypeError(\n            \"\"\"You must set an output type. If your model can return multiple output types, you can explicitly set `Any` as the output type.\n\nFor example:\n\n    from typing import Any\n\n    def predict(\n        self,\n        image: Path = Input(description=\"Input image\"),\n    ) -> Any:\n        ...\n\"\"\"\n        )\n    else:\n        OutputType = signature.return_annotation\n\n    # The type that goes in the response is a list of the yielded type\n    if get_origin(OutputType) is Iterator:\n        OutputType = List[get_args(OutputType)[0]]\n\n    if not hasattr(OutputType, \"__name__\") or OutputType.__name__ != \"Output\":\n        # Wrap the type in a model called \"Output\" so it is a consistent name in the OpenAPI schema\n        class Output(BaseModel):\n            __root__: OutputType\n\n        OutputType = Output\n\n    return OutputType\n\n\ndef human_readable_type_name(t):\n    \"\"\"\n    Generates a useful-for-humans label for a type. For builtin types, it's just the class name (eg \"str\" or \"int\"). For other types, it includes the module (eg \"pathlib.Path\" or \"cog.File\").\n\n    The special case for Cog modules is because the type lives in `cog.types` internally, but just `cog` when included as a dependency.\n    \"\"\"\n    module = t.__module__\n    if module == \"builtins\":\n        return t.__qualname__\n    elif module.split(\".\")[0] == \"cog\":\n        module = \"cog\"\n    return module + \".\" + t.__qualname__\n\n\ndef readable_types_list(type_list):\n    return \", \".join(human_readable_type_name(t) for t in type_list)\n", "path": "python/cog/predictor.py"}], "after_files": [{"content": "from abc import ABC, abstractmethod\nfrom collections.abc import Iterator\nimport enum\nimport importlib\nimport inspect\nimport os.path\nfrom pathlib import Path\nfrom pydantic import create_model, BaseModel\nfrom pydantic.fields import FieldInfo\nfrom typing import List\n\n# Added in Python 3.8. Can be from typing if we drop support for <3.8.\nfrom typing_extensions import get_origin, get_args\nimport yaml\n\nfrom .errors import ConfigDoesNotExist, PredictorNotSet\nfrom .types import Input, Path as CogPath, File as CogFile\n\n\nALLOWED_INPUT_TYPES = [str, int, float, bool, CogFile, CogPath]\n\n\nclass BasePredictor(ABC):\n    def setup(self):\n        \"\"\"\n        An optional method to prepare the model so multiple predictions run efficiently.\n        \"\"\"\n\n    @abstractmethod\n    def predict(self, **kwargs):\n        \"\"\"\n        Run a single prediction on the model\n        \"\"\"\n\n\ndef run_prediction(predictor, inputs, cleanup_functions):\n    \"\"\"\n    Run the predictor on the inputs, and append resulting paths\n    to cleanup functions for removal.\n    \"\"\"\n    result = predictor.predict(**inputs)\n    if isinstance(result, Path):\n        cleanup_functions.append(result.unlink)\n    return result\n\n\ndef load_predictor():\n    \"\"\"\n    Reads cog.yaml and constructs an instance of the user-defined Predictor class.\n    \"\"\"\n\n    # Assumes the working directory is /src\n    config_path = os.path.abspath(\"cog.yaml\")\n    try:\n        with open(config_path) as fh:\n            config = yaml.safe_load(fh)\n    except FileNotFoundError:\n        raise ConfigDoesNotExist(\n            f\"Could not find {config_path}\",\n        )\n\n    if \"predict\" not in config:\n        raise PredictorNotSet(\n            \"Can't run predictions: 'predict' option not found in cog.yaml\"\n        )\n\n    predict_string = config[\"predict\"]\n    module_path, class_name = predict_string.split(\":\", 1)\n    module_name = os.path.basename(module_path).split(\".py\", 1)[0]\n    spec = importlib.util.spec_from_file_location(module_name, module_path)\n    module = importlib.util.module_from_spec(spec)\n    spec.loader.exec_module(module)\n    predictor_class = getattr(module, class_name)\n    return predictor_class()\n\n\n# Base class for inputs, constructed dynamically in get_input_type().\n# (This can't be a docstring or it gets passed through to the schema.)\nclass BaseInput(BaseModel):\n    class Config:\n        # When using `choices`, the type is converted into an enum to validate\n        # But, after validation, we want to pass the actual value to predict(), not the enum object\n        use_enum_values = True\n\n    def cleanup(self):\n        \"\"\"\n        Cleanup any temporary files created by the input.\n        \"\"\"\n        for _, value in self:\n            # Note this is pathlib.Path, which cog.Path is a subclass of. A pathlib.Path object shouldn't make its way here,\n            # but both have an unlink() method, so may as well be safe.\n            if isinstance(value, Path):\n                # This could be missing_ok=True when we drop support for Python 3.7\n                if value.exists():\n                    value.unlink()\n\n\ndef get_input_type(predictor: BasePredictor):\n    \"\"\"\n    Creates a Pydantic Input model from the arguments of a Predictor's predict() method.\n\n    class Predictor(BasePredictor):\n        def predict(self, text: str):\n            ...\n\n    programmatically creates a model like this:\n\n    class Input(BaseModel):\n        text: str\n    \"\"\"\n\n    signature = inspect.signature(predictor.predict)\n    create_model_kwargs = {}\n\n    order = 0\n\n    for name, parameter in signature.parameters.items():\n        InputType = parameter.annotation\n\n        if InputType is inspect.Signature.empty:\n            raise TypeError(\n                f\"No input type provided for parameter `{name}`. Supported input types are: {readable_types_list(ALLOWED_INPUT_TYPES)}.\"\n            )\n        elif InputType not in ALLOWED_INPUT_TYPES:\n            raise TypeError(\n                f\"Unsupported input type {human_readable_type_name(InputType)} for parameter `{name}`. Supported input types are: {readable_types_list(ALLOWED_INPUT_TYPES)}.\"\n            )\n\n        # if no default is specified, create an empty, required input\n        if parameter.default is inspect.Signature.empty:\n            default = Input()\n        else:\n            default = parameter.default\n            # If user hasn't used `Input`, then wrap it in that\n            if not isinstance(default, FieldInfo):\n                default = Input(default=default)\n\n        # Fields aren't ordered, so use this pattern to ensure defined order\n        # https://github.com/go-openapi/spec/pull/116\n        default.extra[\"x-order\"] = order\n        order += 1\n\n        # Choices!\n        if default.extra.get(\"choices\"):\n            choices = default.extra[\"choices\"]\n            # It will be passed automatically as 'enum' in the schema, so remove it as an extra field.\n            del default.extra[\"choices\"]\n            if InputType == str:\n\n                class StringEnum(str, enum.Enum):\n                    pass\n\n                InputType = StringEnum(name, {value: value for value in choices})\n            elif InputType == int:\n                InputType = enum.IntEnum(name, {str(value): value for value in choices})\n            else:\n                raise TypeError(\n                    f\"The input {name} uses the option choices. Choices can only be used with str or int types.\"\n                )\n\n        create_model_kwargs[name] = (InputType, default)\n\n    return create_model(\"Input\", **create_model_kwargs, __base__=BaseInput)\n\n\ndef get_output_type(predictor: BasePredictor):\n    \"\"\"\n    Creates a Pydantic Output model from the return type annotation of a Predictor's predict() method.\n    \"\"\"\n\n    signature = inspect.signature(predictor.predict)\n    if signature.return_annotation is inspect.Signature.empty:\n        raise TypeError(\n            \"\"\"You must set an output type. If your model can return multiple output types, you can explicitly set `Any` as the output type.\n\nFor example:\n\n    from typing import Any\n\n    def predict(\n        self,\n        image: Path = Input(description=\"Input image\"),\n    ) -> Any:\n        ...\n\"\"\"\n        )\n    else:\n        OutputType = signature.return_annotation\n\n    # The type that goes in the response is a list of the yielded type\n    if get_origin(OutputType) is Iterator:\n        OutputType = List[get_args(OutputType)[0]]\n\n    if not hasattr(OutputType, \"__name__\") or OutputType.__name__ != \"Output\":\n        # Wrap the type in a model called \"Output\" so it is a consistent name in the OpenAPI schema\n        class Output(BaseModel):\n            __root__: OutputType\n\n        OutputType = Output\n\n    return OutputType\n\n\ndef human_readable_type_name(t):\n    \"\"\"\n    Generates a useful-for-humans label for a type. For builtin types, it's just the class name (eg \"str\" or \"int\"). For other types, it includes the module (eg \"pathlib.Path\" or \"cog.File\").\n\n    The special case for Cog modules is because the type lives in `cog.types` internally, but just `cog` when included as a dependency.\n    \"\"\"\n    module = t.__module__\n    if module == \"builtins\":\n        return t.__qualname__\n    elif module.split(\".\")[0] == \"cog\":\n        module = \"cog\"\n    return module + \".\" + t.__qualname__\n\n\ndef readable_types_list(type_list):\n    return \", \".join(human_readable_type_name(t) for t in type_list)\n", "path": "python/cog/predictor.py"}]}