We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
st.metric doesn't like numpy.int64
### Summary

I summed a column in a dataframe and passed it to `st.metric` and it threw an error because it wanted a regular int.

Should it just do the right thing?

Also: The error about being an invalid type is showing the value of the variable instead of the type that it doesn't like.

### Steps to reproduce

Code snippet:

![Screen Shot 2021-08-19 at 2 44 20 PM](https://user-images.githubusercontent.com/27847/130126932-3303d636-38f8-417d-bfa5-af2ca578a179.png)

```
   st.write(type(companies['num_developers'].sum()))
    st.markdown(f'Total developers %d' % companies['num_developers'].sum())
    st.metric('Total developers', companies['num_developers'].sum())
```

**Expected behavior:**

Expected it to just work!

**Actual behavior:**

Showed the error in the screenshot above.

### Is this a regression?

That is, did this use to work the way you expected in the past?
no

### Debug info

- Streamlit version: streamlit-nightly from today


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lib/streamlit/elements/metric.py`
Content:
```
1 # Copyright 2018-2021 Streamlit Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 from textwrap import dedent
16 from typing import cast, Optional
17 
18 import attr
19 
20 import streamlit
21 from streamlit.errors import StreamlitAPIException
22 from streamlit.proto.Metric_pb2 import Metric as MetricProto
23 from .utils import clean_text
24 
25 
26 @attr.s(auto_attribs=True, slots=True)
27 class MetricColorAndDirection:
28     color: Optional[int]
29     direction: Optional[int]
30 
31 
32 class MetricMixin:
33     def metric(self, label, value, delta=None, delta_color="normal"):
34         """Display a metric in big bold font, with an optional indicator of how the metric changed.
35 
36         Tip: If you want to display a large number, it may be a good idea to
37         shorten it using packages like `millify <https://github.com/azaitsev/millify>`_
38         or `numerize <https://github.com/davidsa03/numerize>`_. E.g. ``1234`` can be
39         displayed as ``1.2k`` using ``st.metric("Short number", millify(1234))``.
40 
41         Parameters
42         ----------
43         label : str
44             The header or Title for the metric
45         value : int, float, str, or None
46              Value of the metric. None is rendered as a long dash.
47         delta : int, float, str, or None
48             Indicator of how the metric changed, rendered with an arrow below
49             the metric. If delta is negative (int/float) or starts with a minus
50             sign (str), the arrow points down and the text is red; else the
51             arrow points up and the text is green. If None (default), no delta
52             indicator is shown.
53         delta_color : str
54              If "normal" (default), the delta indicator is shown as described
55              above. If "inverse", it is red when positive and green when
56              negative. This is useful when a negative change is considered
57              good, e.g. if cost decreased. If "off", delta is  shown in gray
58              regardless of its value.
59 
60         Example
61         -------
62         >>> st.metric(label="Temperature", value="70 °F", delta="1.2 °F")
63 
64         .. output::
65             https://static.streamlit.io/0.86.0-mT2t/index.html?id=1TxwRhgBgFg62p2AXqJdM
66             height: 175px
67 
68         ``st.metric`` looks especially nice in combination with ``st.columns``:
69 
70         >>> col1, col2, col3 = st.columns(3)
71         >>> col1.metric("Temperature", "70 °F", "1.2 °F")
72         >>> col2.metric("Wind", "9 mph", "-8%")
73         >>> col3.metric("Humidity", "86%", "4%")
74 
75         .. output::
76             https://static.streamlit.io/0.86.0-mT2t/index.html?id=4K9bKXhiPAxBNhktd8cxbg
77             height: 175px
78 
79         The delta indicator color can also be inverted or turned off:
80 
81         >>> st.metric(label="Gas price", value=4, delta=-0.5,
82         ...     delta_color="inverse")
83         >>>
84         >>> st.metric(label="Active developers", value=123, delta=123,
85         ...     delta_color="off")
86 
87         .. output::
88             https://static.streamlit.io/0.86.0-mT2t/index.html?id=UTtQvbBQFaPtCmPcQ23wpP
89             height: 275px
90 
91         """
92         metric_proto = MetricProto()
93         metric_proto.body = self.parse_value(value)
94         metric_proto.label = self.parse_label(label)
95         metric_proto.delta = self.parse_delta(delta)
96 
97         color_and_direction = self.determine_delta_color_and_direction(
98             clean_text(delta_color), delta
99         )
100         metric_proto.color = color_and_direction.color
101         metric_proto.direction = color_and_direction.direction
102 
103         return str(self.dg._enqueue("metric", metric_proto))
104 
105     def parse_label(self, label):
106         if not isinstance(label, str):
107             raise TypeError(
108                 f"'{str(label)}' is not an accepted type. label only accepts: str"
109             )
110         return label
111 
112     def parse_value(self, value):
113         if value is None:
114             return "—"
115         if isinstance(value, float) or isinstance(value, int) or isinstance(value, str):
116             return str(value)
117         else:
118             raise TypeError(
119                 f"'{str(value)}' is not an accepted type. value only accepts: "
120                 "int, float, str, or None"
121             )
122 
123     def parse_delta(self, delta):
124         if delta is None or delta == "":
125             return ""
126         if isinstance(delta, str):
127             return dedent(delta)
128         elif isinstance(delta, int) or isinstance(delta, float):
129             return str(delta)
130         else:
131             raise TypeError(
132                 f"'{str(delta)}' is not an accepted type. delta only accepts:"
133                 " int, float, str, or None"
134             )
135 
136     def determine_delta_color_and_direction(self, delta_color, delta):
137         cd = MetricColorAndDirection(color=None, direction=None)
138 
139         if delta is None or delta == "":
140             cd.color = MetricProto.MetricColor.GRAY
141             cd.direction = MetricProto.MetricDirection.NONE
142             return cd
143 
144         if self.is_negative(delta):
145             if delta_color == "normal":
146                 cd.color = MetricProto.MetricColor.RED
147             elif delta_color == "inverse":
148                 cd.color = MetricProto.MetricColor.GREEN
149             elif delta_color == "off":
150                 cd.color = MetricProto.MetricColor.GRAY
151             cd.direction = MetricProto.MetricDirection.DOWN
152         else:
153             if delta_color == "normal":
154                 cd.color = MetricProto.MetricColor.GREEN
155             elif delta_color == "inverse":
156                 cd.color = MetricProto.MetricColor.RED
157             elif delta_color == "off":
158                 cd.color = MetricProto.MetricColor.GRAY
159             cd.direction = MetricProto.MetricDirection.UP
160 
161         if cd.color is None or cd.direction is None:
162             raise StreamlitAPIException(
163                 f"'{str(delta_color)}' is not an accepted value. delta_color only accepts: "
164                 "'normal', 'inverse', or 'off'"
165             )
166         return cd
167 
168     def is_negative(self, delta):
169         return dedent(str(delta)).startswith("-")
170 
171     @property
172     def dg(self) -> "streamlit.delta_generator.DeltaGenerator":
173         return cast("streamlit.delta_generator.DeltaGenerator", self)
174
```
--- 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/lib/streamlit/elements/metric.py b/lib/streamlit/elements/metric.py
--- a/lib/streamlit/elements/metric.py
+++ b/lib/streamlit/elements/metric.py
@@ -13,13 +13,13 @@
 # limitations under the License.
 
 from textwrap import dedent
-from typing import cast, Optional
+from typing import Optional, cast
 
 import attr
-
 import streamlit
 from streamlit.errors import StreamlitAPIException
 from streamlit.proto.Metric_pb2 import Metric as MetricProto
+
 from .utils import clean_text
 
 
@@ -105,7 +105,8 @@
     def parse_label(self, label):
         if not isinstance(label, str):
             raise TypeError(
-                f"'{str(label)}' is not an accepted type. label only accepts: str"
+                f"'{str(label)}' is of type {str(type(label))}, which is not an accepted type."
+                " label only accepts: str. Please convert the label to an accepted type."
             )
         return label
 
@@ -114,11 +115,20 @@
             return "—"
         if isinstance(value, float) or isinstance(value, int) or isinstance(value, str):
             return str(value)
-        else:
-            raise TypeError(
-                f"'{str(value)}' is not an accepted type. value only accepts: "
-                "int, float, str, or None"
-            )
+        elif hasattr(value, "item"):
+            # Add support for numpy values (e.g. int16, float64, etc.)
+            try:
+                # Item could also be just a variable, so we use try, except
+                if isinstance(value.item(), float) or isinstance(value.item(), int):
+                    return str(value.item())
+            except Exception:
+                pass
+
+        raise TypeError(
+            f"'{str(value)}' is of type {str(type(value))}, which is not an accepted type."
+            " value only accepts: int, float, str, or None."
+            " Please convert the value to an accepted type."
+        )
 
     def parse_delta(self, delta):
         if delta is None or delta == "":
@@ -129,8 +139,9 @@
             return str(delta)
         else:
             raise TypeError(
-                f"'{str(delta)}' is not an accepted type. delta only accepts:"
-                " int, float, str, or None"
+                f"'{str(delta)}' is of type {str(type(delta))}, which is not an accepted type."
+                " delta only accepts: int, float, str, or None."
+                " Please convert the value to an accepted type."
             )
 
     def determine_delta_color_and_direction(self, delta_color, delta):

{"golden_diff": "diff --git a/lib/streamlit/elements/metric.py b/lib/streamlit/elements/metric.py\n--- a/lib/streamlit/elements/metric.py\n+++ b/lib/streamlit/elements/metric.py\n@@ -13,13 +13,13 @@\n # limitations under the License.\n \n from textwrap import dedent\n-from typing import cast, Optional\n+from typing import Optional, cast\n \n import attr\n-\n import streamlit\n from streamlit.errors import StreamlitAPIException\n from streamlit.proto.Metric_pb2 import Metric as MetricProto\n+\n from .utils import clean_text\n \n \n@@ -105,7 +105,8 @@\n     def parse_label(self, label):\n         if not isinstance(label, str):\n             raise TypeError(\n-                f\"'{str(label)}' is not an accepted type. label only accepts: str\"\n+                f\"'{str(label)}' is of type {str(type(label))}, which is not an accepted type.\"\n+                \" label only accepts: str. Please convert the label to an accepted type.\"\n             )\n         return label\n \n@@ -114,11 +115,20 @@\n             return \"\u2014\"\n         if isinstance(value, float) or isinstance(value, int) or isinstance(value, str):\n             return str(value)\n-        else:\n-            raise TypeError(\n-                f\"'{str(value)}' is not an accepted type. value only accepts: \"\n-                \"int, float, str, or None\"\n-            )\n+        elif hasattr(value, \"item\"):\n+            # Add support for numpy values (e.g. int16, float64, etc.)\n+            try:\n+                # Item could also be just a variable, so we use try, except\n+                if isinstance(value.item(), float) or isinstance(value.item(), int):\n+                    return str(value.item())\n+            except Exception:\n+                pass\n+\n+        raise TypeError(\n+            f\"'{str(value)}' is of type {str(type(value))}, which is not an accepted type.\"\n+            \" value only accepts: int, float, str, or None.\"\n+            \" Please convert the value to an accepted type.\"\n+        )\n \n     def parse_delta(self, delta):\n         if delta is None or delta == \"\":\n@@ -129,8 +139,9 @@\n             return str(delta)\n         else:\n             raise TypeError(\n-                f\"'{str(delta)}' is not an accepted type. delta only accepts:\"\n-                \" int, float, str, or None\"\n+                f\"'{str(delta)}' is of type {str(type(delta))}, which is not an accepted type.\"\n+                \" delta only accepts: int, float, str, or None.\"\n+                \" Please convert the value to an accepted type.\"\n             )\n \n     def determine_delta_color_and_direction(self, delta_color, delta):\n", "issue": "st.metric doesn't like numpy.int64\n### Summary\r\n\r\nI summed a column in a dataframe and passed it to `st.metric` and it threw an error because it wanted a regular int.\r\n\r\nShould it just do the right thing?\r\n\r\nAlso: The error about being an invalid type is showing the value of the variable instead of the type that it doesn't like.\r\n\r\n### Steps to reproduce\r\n\r\nCode snippet:\r\n\r\n![Screen Shot 2021-08-19 at 2 44 20 PM](https://user-images.githubusercontent.com/27847/130126932-3303d636-38f8-417d-bfa5-af2ca578a179.png)\r\n\r\n```\r\n   st.write(type(companies['num_developers'].sum()))\r\n    st.markdown(f'Total developers %d' % companies['num_developers'].sum())\r\n    st.metric('Total developers', companies['num_developers'].sum())\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nExpected it to just work!\r\n\r\n**Actual behavior:**\r\n\r\nShowed the error in the screenshot above.\r\n\r\n### Is this a regression?\r\n\r\nThat is, did this use to work the way you expected in the past?\r\nno\r\n\r\n### Debug info\r\n\r\n- Streamlit version: streamlit-nightly from today\r\n\n", "before_files": [{"content": "# Copyright 2018-2021 Streamlit Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom textwrap import dedent\nfrom typing import cast, Optional\n\nimport attr\n\nimport streamlit\nfrom streamlit.errors import StreamlitAPIException\nfrom streamlit.proto.Metric_pb2 import Metric as MetricProto\nfrom .utils import clean_text\n\n\n@attr.s(auto_attribs=True, slots=True)\nclass MetricColorAndDirection:\n    color: Optional[int]\n    direction: Optional[int]\n\n\nclass MetricMixin:\n    def metric(self, label, value, delta=None, delta_color=\"normal\"):\n        \"\"\"Display a metric in big bold font, with an optional indicator of how the metric changed.\n\n        Tip: If you want to display a large number, it may be a good idea to\n        shorten it using packages like `millify <https://github.com/azaitsev/millify>`_\n        or `numerize <https://github.com/davidsa03/numerize>`_. E.g. ``1234`` can be\n        displayed as ``1.2k`` using ``st.metric(\"Short number\", millify(1234))``.\n\n        Parameters\n        ----------\n        label : str\n            The header or Title for the metric\n        value : int, float, str, or None\n             Value of the metric. None is rendered as a long dash.\n        delta : int, float, str, or None\n            Indicator of how the metric changed, rendered with an arrow below\n            the metric. If delta is negative (int/float) or starts with a minus\n            sign (str), the arrow points down and the text is red; else the\n            arrow points up and the text is green. If None (default), no delta\n            indicator is shown.\n        delta_color : str\n             If \"normal\" (default), the delta indicator is shown as described\n             above. If \"inverse\", it is red when positive and green when\n             negative. This is useful when a negative change is considered\n             good, e.g. if cost decreased. If \"off\", delta is  shown in gray\n             regardless of its value.\n\n        Example\n        -------\n        >>> st.metric(label=\"Temperature\", value=\"70 \u00b0F\", delta=\"1.2 \u00b0F\")\n\n        .. output::\n            https://static.streamlit.io/0.86.0-mT2t/index.html?id=1TxwRhgBgFg62p2AXqJdM\n            height: 175px\n\n        ``st.metric`` looks especially nice in combination with ``st.columns``:\n\n        >>> col1, col2, col3 = st.columns(3)\n        >>> col1.metric(\"Temperature\", \"70 \u00b0F\", \"1.2 \u00b0F\")\n        >>> col2.metric(\"Wind\", \"9 mph\", \"-8%\")\n        >>> col3.metric(\"Humidity\", \"86%\", \"4%\")\n\n        .. output::\n            https://static.streamlit.io/0.86.0-mT2t/index.html?id=4K9bKXhiPAxBNhktd8cxbg\n            height: 175px\n\n        The delta indicator color can also be inverted or turned off:\n\n        >>> st.metric(label=\"Gas price\", value=4, delta=-0.5,\n        ...     delta_color=\"inverse\")\n        >>>\n        >>> st.metric(label=\"Active developers\", value=123, delta=123,\n        ...     delta_color=\"off\")\n\n        .. output::\n            https://static.streamlit.io/0.86.0-mT2t/index.html?id=UTtQvbBQFaPtCmPcQ23wpP\n            height: 275px\n\n        \"\"\"\n        metric_proto = MetricProto()\n        metric_proto.body = self.parse_value(value)\n        metric_proto.label = self.parse_label(label)\n        metric_proto.delta = self.parse_delta(delta)\n\n        color_and_direction = self.determine_delta_color_and_direction(\n            clean_text(delta_color), delta\n        )\n        metric_proto.color = color_and_direction.color\n        metric_proto.direction = color_and_direction.direction\n\n        return str(self.dg._enqueue(\"metric\", metric_proto))\n\n    def parse_label(self, label):\n        if not isinstance(label, str):\n            raise TypeError(\n                f\"'{str(label)}' is not an accepted type. label only accepts: str\"\n            )\n        return label\n\n    def parse_value(self, value):\n        if value is None:\n            return \"\u2014\"\n        if isinstance(value, float) or isinstance(value, int) or isinstance(value, str):\n            return str(value)\n        else:\n            raise TypeError(\n                f\"'{str(value)}' is not an accepted type. value only accepts: \"\n                \"int, float, str, or None\"\n            )\n\n    def parse_delta(self, delta):\n        if delta is None or delta == \"\":\n            return \"\"\n        if isinstance(delta, str):\n            return dedent(delta)\n        elif isinstance(delta, int) or isinstance(delta, float):\n            return str(delta)\n        else:\n            raise TypeError(\n                f\"'{str(delta)}' is not an accepted type. delta only accepts:\"\n                \" int, float, str, or None\"\n            )\n\n    def determine_delta_color_and_direction(self, delta_color, delta):\n        cd = MetricColorAndDirection(color=None, direction=None)\n\n        if delta is None or delta == \"\":\n            cd.color = MetricProto.MetricColor.GRAY\n            cd.direction = MetricProto.MetricDirection.NONE\n            return cd\n\n        if self.is_negative(delta):\n            if delta_color == \"normal\":\n                cd.color = MetricProto.MetricColor.RED\n            elif delta_color == \"inverse\":\n                cd.color = MetricProto.MetricColor.GREEN\n            elif delta_color == \"off\":\n                cd.color = MetricProto.MetricColor.GRAY\n            cd.direction = MetricProto.MetricDirection.DOWN\n        else:\n            if delta_color == \"normal\":\n                cd.color = MetricProto.MetricColor.GREEN\n            elif delta_color == \"inverse\":\n                cd.color = MetricProto.MetricColor.RED\n            elif delta_color == \"off\":\n                cd.color = MetricProto.MetricColor.GRAY\n            cd.direction = MetricProto.MetricDirection.UP\n\n        if cd.color is None or cd.direction is None:\n            raise StreamlitAPIException(\n                f\"'{str(delta_color)}' is not an accepted value. delta_color only accepts: \"\n                \"'normal', 'inverse', or 'off'\"\n            )\n        return cd\n\n    def is_negative(self, delta):\n        return dedent(str(delta)).startswith(\"-\")\n\n    @property\n    def dg(self) -> \"streamlit.delta_generator.DeltaGenerator\":\n        return cast(\"streamlit.delta_generator.DeltaGenerator\", self)\n", "path": "lib/streamlit/elements/metric.py"}], "after_files": [{"content": "# Copyright 2018-2021 Streamlit Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom textwrap import dedent\nfrom typing import Optional, cast\n\nimport attr\nimport streamlit\nfrom streamlit.errors import StreamlitAPIException\nfrom streamlit.proto.Metric_pb2 import Metric as MetricProto\n\nfrom .utils import clean_text\n\n\n@attr.s(auto_attribs=True, slots=True)\nclass MetricColorAndDirection:\n    color: Optional[int]\n    direction: Optional[int]\n\n\nclass MetricMixin:\n    def metric(self, label, value, delta=None, delta_color=\"normal\"):\n        \"\"\"Display a metric in big bold font, with an optional indicator of how the metric changed.\n\n        Tip: If you want to display a large number, it may be a good idea to\n        shorten it using packages like `millify <https://github.com/azaitsev/millify>`_\n        or `numerize <https://github.com/davidsa03/numerize>`_. E.g. ``1234`` can be\n        displayed as ``1.2k`` using ``st.metric(\"Short number\", millify(1234))``.\n\n        Parameters\n        ----------\n        label : str\n            The header or Title for the metric\n        value : int, float, str, or None\n             Value of the metric. None is rendered as a long dash.\n        delta : int, float, str, or None\n            Indicator of how the metric changed, rendered with an arrow below\n            the metric. If delta is negative (int/float) or starts with a minus\n            sign (str), the arrow points down and the text is red; else the\n            arrow points up and the text is green. If None (default), no delta\n            indicator is shown.\n        delta_color : str\n             If \"normal\" (default), the delta indicator is shown as described\n             above. If \"inverse\", it is red when positive and green when\n             negative. This is useful when a negative change is considered\n             good, e.g. if cost decreased. If \"off\", delta is  shown in gray\n             regardless of its value.\n\n        Example\n        -------\n        >>> st.metric(label=\"Temperature\", value=\"70 \u00b0F\", delta=\"1.2 \u00b0F\")\n\n        .. output::\n            https://static.streamlit.io/0.86.0-mT2t/index.html?id=1TxwRhgBgFg62p2AXqJdM\n            height: 175px\n\n        ``st.metric`` looks especially nice in combination with ``st.columns``:\n\n        >>> col1, col2, col3 = st.columns(3)\n        >>> col1.metric(\"Temperature\", \"70 \u00b0F\", \"1.2 \u00b0F\")\n        >>> col2.metric(\"Wind\", \"9 mph\", \"-8%\")\n        >>> col3.metric(\"Humidity\", \"86%\", \"4%\")\n\n        .. output::\n            https://static.streamlit.io/0.86.0-mT2t/index.html?id=4K9bKXhiPAxBNhktd8cxbg\n            height: 175px\n\n        The delta indicator color can also be inverted or turned off:\n\n        >>> st.metric(label=\"Gas price\", value=4, delta=-0.5,\n        ...     delta_color=\"inverse\")\n        >>>\n        >>> st.metric(label=\"Active developers\", value=123, delta=123,\n        ...     delta_color=\"off\")\n\n        .. output::\n            https://static.streamlit.io/0.86.0-mT2t/index.html?id=UTtQvbBQFaPtCmPcQ23wpP\n            height: 275px\n\n        \"\"\"\n        metric_proto = MetricProto()\n        metric_proto.body = self.parse_value(value)\n        metric_proto.label = self.parse_label(label)\n        metric_proto.delta = self.parse_delta(delta)\n\n        color_and_direction = self.determine_delta_color_and_direction(\n            clean_text(delta_color), delta\n        )\n        metric_proto.color = color_and_direction.color\n        metric_proto.direction = color_and_direction.direction\n\n        return str(self.dg._enqueue(\"metric\", metric_proto))\n\n    def parse_label(self, label):\n        if not isinstance(label, str):\n            raise TypeError(\n                f\"'{str(label)}' is of type {str(type(label))}, which is not an accepted type.\"\n                \" label only accepts: str. Please convert the label to an accepted type.\"\n            )\n        return label\n\n    def parse_value(self, value):\n        if value is None:\n            return \"\u2014\"\n        if isinstance(value, float) or isinstance(value, int) or isinstance(value, str):\n            return str(value)\n        elif hasattr(value, \"item\"):\n            # Add support for numpy values (e.g. int16, float64, etc.)\n            try:\n                # Item could also be just a variable, so we use try, except\n                if isinstance(value.item(), float) or isinstance(value.item(), int):\n                    return str(value.item())\n            except Exception:\n                pass\n\n        raise TypeError(\n            f\"'{str(value)}' is of type {str(type(value))}, which is not an accepted type.\"\n            \" value only accepts: int, float, str, or None.\"\n            \" Please convert the value to an accepted type.\"\n        )\n\n    def parse_delta(self, delta):\n        if delta is None or delta == \"\":\n            return \"\"\n        if isinstance(delta, str):\n            return dedent(delta)\n        elif isinstance(delta, int) or isinstance(delta, float):\n            return str(delta)\n        else:\n            raise TypeError(\n                f\"'{str(delta)}' is of type {str(type(delta))}, which is not an accepted type.\"\n                \" delta only accepts: int, float, str, or None.\"\n                \" Please convert the value to an accepted type.\"\n            )\n\n    def determine_delta_color_and_direction(self, delta_color, delta):\n        cd = MetricColorAndDirection(color=None, direction=None)\n\n        if delta is None or delta == \"\":\n            cd.color = MetricProto.MetricColor.GRAY\n            cd.direction = MetricProto.MetricDirection.NONE\n            return cd\n\n        if self.is_negative(delta):\n            if delta_color == \"normal\":\n                cd.color = MetricProto.MetricColor.RED\n            elif delta_color == \"inverse\":\n                cd.color = MetricProto.MetricColor.GREEN\n            elif delta_color == \"off\":\n                cd.color = MetricProto.MetricColor.GRAY\n            cd.direction = MetricProto.MetricDirection.DOWN\n        else:\n            if delta_color == \"normal\":\n                cd.color = MetricProto.MetricColor.GREEN\n            elif delta_color == \"inverse\":\n                cd.color = MetricProto.MetricColor.RED\n            elif delta_color == \"off\":\n                cd.color = MetricProto.MetricColor.GRAY\n            cd.direction = MetricProto.MetricDirection.UP\n\n        if cd.color is None or cd.direction is None:\n            raise StreamlitAPIException(\n                f\"'{str(delta_color)}' is not an accepted value. delta_color only accepts: \"\n                \"'normal', 'inverse', or 'off'\"\n            )\n        return cd\n\n    def is_negative(self, delta):\n        return dedent(str(delta)).startswith(\"-\")\n\n    @property\n    def dg(self) -> \"streamlit.delta_generator.DeltaGenerator\":\n        return cast(\"streamlit.delta_generator.DeltaGenerator\", self)\n", "path": "lib/streamlit/elements/metric.py"}]}