We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Support reading from BytesIO/StringIO
I'm trying to write a GIF to memory and use panel to read from memory rather than storage.
`ValueError: GIF pane does not support objects of type 'BytesIO'`

```
from io import BytesIO
import imageio

memory = BytesIO()

save_fps = [..]

with imageio.get_writer(memory, mode='I', format='gif', fps=8) as writer:
    for fp in save_fps:
        image = imageio.imread(fp)
        writer.append_data(image)

memory.seek(0)
pn.pane.GIF(memory)
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `panel/pane/image.py`
Content:
```
1 """
2 Contains Image panes including renderers for PNG, SVG, GIF and JPG
3 file types.
4 """
5 from __future__ import absolute_import, division, unicode_literals
6 
7 import base64
8 import os
9 
10 from io import BytesIO
11 from six import string_types
12 
13 import param
14 
15 from .markup import DivPaneBase
16 
17 
18 class ImageBase(DivPaneBase):
19     """
20     Encodes an image as base64 and wraps it in a Bokeh Div model.
21     This is an abstract base class that needs the image type
22     to be specified and specific code for determining the image shape.
23 
24     The imgtype determines the filetype, extension, and MIME type for
25     this image. Each image type (png,jpg,gif) has a base class that
26     supports anything with a `_repr_X_` method (where X is `png`,
27     `gif`, etc.), a local file with the given file extension, or a
28     HTTP(S) url with the given extension.  Subclasses of each type can
29     provide their own way of obtaining or generating a PNG.
30     """
31 
32     embed = param.Boolean(default=True, doc="""
33         Whether to embed the image as base64.""")
34 
35     imgtype = 'None'
36 
37     __abstract = True
38 
39     @classmethod
40     def applies(cls, obj):
41         imgtype = cls.imgtype
42         return (hasattr(obj, '_repr_'+imgtype+'_') or
43                 (isinstance(obj, string_types) and
44                  ((os.path.isfile(obj) and obj.endswith('.'+imgtype)) or
45                   cls._is_url(obj))))
46 
47     @classmethod
48     def _is_url(cls, obj):
49         return (isinstance(obj, string_types) and
50                 (obj.startswith('http://') or obj.startswith('https://'))
51                 and obj.endswith('.'+cls.imgtype))
52 
53     def _img(self):
54         if not isinstance(self.object, string_types):
55             return getattr(self.object, '_repr_'+self.imgtype+'_')()
56         elif os.path.isfile(self.object):
57             with open(self.object, 'rb') as f:
58                 return f.read()
59         else:
60             import requests
61             r = requests.request(url=self.object, method='GET')
62             return r.content
63 
64     def _imgshape(self, data):
65         """Calculate and return image width,height"""
66         raise NotImplementedError
67 
68     def _get_properties(self):
69         p = super(ImageBase, self)._get_properties()
70         if self.object is None:
71             return dict(p, text='<img></img>')
72         data = self._img()
73         if not isinstance(data, bytes):
74             data = base64.b64decode(data)
75         width, height = self._imgshape(data)
76         if self.width is not None:
77             if self.height is None:
78                 height = int((self.width/width)*height)
79             else:
80                 height = self.height
81             width = self.width
82         elif self.height is not None:
83             width = int((self.height/height)*width)
84             height = self.height
85         if not self.embed:
86             src = self.object
87         else:
88             b64 = base64.b64encode(data).decode("utf-8")
89             src = "data:image/"+self.imgtype+";base64,{b64}".format(b64=b64)
90 
91         smode = self.sizing_mode
92         if smode in ['fixed', None]:
93             w, h = '%spx' % width, '%spx' % height
94         elif smode == 'stretch_both':
95             w, h = '100%', '100%'
96         elif smode == 'stretch_height':
97             w, h = '%spx' % width, '100%'
98         elif smode == 'stretch_height':
99             w, h = '100%', '%spx' % height
100         elif smode == 'scale_height':
101             w, h = 'auto', '100%'
102         else:
103             w, h = '100%', 'auto'
104 
105         html = "<img src='{src}' width='{width}' height='{height}'></img>".format(
106             src=src, width=w, height=h)
107 
108         return dict(p, width=width, height=height, text=html)
109 
110 
111 class PNG(ImageBase):
112 
113     imgtype = 'png'
114 
115     @classmethod
116     def _imgshape(cls, data):
117         import struct
118         w, h = struct.unpack('>LL', data[16:24])
119         return int(w), int(h)
120 
121 
122 class GIF(ImageBase):
123 
124     imgtype = 'gif'
125 
126     @classmethod
127     def _imgshape(cls, data):
128         import struct
129         w, h = struct.unpack("<HH", data[6:10])
130         return int(w), int(h)
131 
132 
133 class JPG(ImageBase):
134 
135     imgtype = 'jpg'
136 
137     @classmethod
138     def _imgshape(cls, data):
139         import struct
140         b = BytesIO(data)
141         b.read(2)
142         c = b.read(1)
143         while (c and ord(c) != 0xDA):
144             while (ord(c) != 0xFF): c = b.read(1)
145             while (ord(c) == 0xFF): c = b.read(1)
146             if (ord(c) >= 0xC0 and ord(c) <= 0xC3):
147                 b.read(3)
148                 h, w = struct.unpack(">HH", b.read(4))
149                 break
150             else:
151                 b.read(int(struct.unpack(">H", b.read(2))[0])-2)
152             c = b.read(1)
153         return int(w), int(h)
154 
155 
156 class SVG(ImageBase):
157 
158     imgtype = 'svg'
159 
160     @classmethod
161     def applies(cls, obj):
162         return (super(SVG, cls).applies(obj) or
163                 (isinstance(obj, string_types) and obj.lstrip().startswith('<svg')))
164 
165     def _img(self):
166         if (isinstance(self.object, string_types) and
167             self.object.lstrip().startswith('<svg')):
168             return self.object
169         return super(SVG, self)._img()
170 
171     def _imgshape(self, data):
172         return (self.width, self.height)
173 
174     def _get_properties(self):
175         p = super(ImageBase, self)._get_properties()
176         if self.object is None:
177             return dict(p, text='<img></img>')
178         data = self._img()
179         width, height = self._imgshape(data)
180         if not isinstance(data, bytes):
181             data = data.encode('utf-8')
182         b64 = base64.b64encode(data).decode("utf-8")
183         src = "data:image/svg+xml;base64,{b64}".format(b64=b64)
184         html = "<img src='{src}' width={width} height={height}></img>".format(
185             src=src, width=width, height=height
186         )
187         return dict(p, width=width, height=height, text=html)
188
```
--- 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/panel/pane/image.py b/panel/pane/image.py
--- a/panel/pane/image.py
+++ b/panel/pane/image.py
@@ -39,24 +39,37 @@
     @classmethod
     def applies(cls, obj):
         imgtype = cls.imgtype
-        return (hasattr(obj, '_repr_'+imgtype+'_') or
-                (isinstance(obj, string_types) and
-                 ((os.path.isfile(obj) and obj.endswith('.'+imgtype)) or
-                  cls._is_url(obj))))
+        if hasattr(obj, '_repr_{}_'.format(imgtype)):
+            return True
+        if isinstance(obj, string_types):
+            if os.path.isfile(obj) and obj.endswith('.'+imgtype):
+                return True
+            if cls._is_url(obj):
+                return True
+        if hasattr(obj, 'read'):  # Check for file like object
+            return True
+        return False
 
     @classmethod
     def _is_url(cls, obj):
-        return (isinstance(obj, string_types) and
-                (obj.startswith('http://') or obj.startswith('https://'))
-                and obj.endswith('.'+cls.imgtype))
+        if isinstance(obj, string_types):
+            lower_string = obj.lower()
+            return (
+                lower_string.startswith('http://')
+                or lower_string.startswith('https://')
+            ) and lower_string.endswith('.'+cls.imgtype)
+        return False
 
     def _img(self):
-        if not isinstance(self.object, string_types):
-            return getattr(self.object, '_repr_'+self.imgtype+'_')()
-        elif os.path.isfile(self.object):
-            with open(self.object, 'rb') as f:
-                return f.read()
-        else:
+        if hasattr(self.object, '_repr_{}_'.format(self.imgtype)):
+            return getattr(self.object, '_repr_' + self.imgtype + '_')()
+        if isinstance(self.object, string_types):
+            if os.path.isfile(self.object):
+                with open(self.object, 'rb') as f:
+                    return f.read()
+        if hasattr(self.object, 'read'):
+            return self.object.read()
+        if self._is_url(self.object):
             import requests
             r = requests.request(url=self.object, method='GET')
             return r.content

{"golden_diff": "diff --git a/panel/pane/image.py b/panel/pane/image.py\n--- a/panel/pane/image.py\n+++ b/panel/pane/image.py\n@@ -39,24 +39,37 @@\n     @classmethod\n     def applies(cls, obj):\n         imgtype = cls.imgtype\n-        return (hasattr(obj, '_repr_'+imgtype+'_') or\n-                (isinstance(obj, string_types) and\n-                 ((os.path.isfile(obj) and obj.endswith('.'+imgtype)) or\n-                  cls._is_url(obj))))\n+        if hasattr(obj, '_repr_{}_'.format(imgtype)):\n+            return True\n+        if isinstance(obj, string_types):\n+            if os.path.isfile(obj) and obj.endswith('.'+imgtype):\n+                return True\n+            if cls._is_url(obj):\n+                return True\n+        if hasattr(obj, 'read'):  # Check for file like object\n+            return True\n+        return False\n \n     @classmethod\n     def _is_url(cls, obj):\n-        return (isinstance(obj, string_types) and\n-                (obj.startswith('http://') or obj.startswith('https://'))\n-                and obj.endswith('.'+cls.imgtype))\n+        if isinstance(obj, string_types):\n+            lower_string = obj.lower()\n+            return (\n+                lower_string.startswith('http://')\n+                or lower_string.startswith('https://')\n+            ) and lower_string.endswith('.'+cls.imgtype)\n+        return False\n \n     def _img(self):\n-        if not isinstance(self.object, string_types):\n-            return getattr(self.object, '_repr_'+self.imgtype+'_')()\n-        elif os.path.isfile(self.object):\n-            with open(self.object, 'rb') as f:\n-                return f.read()\n-        else:\n+        if hasattr(self.object, '_repr_{}_'.format(self.imgtype)):\n+            return getattr(self.object, '_repr_' + self.imgtype + '_')()\n+        if isinstance(self.object, string_types):\n+            if os.path.isfile(self.object):\n+                with open(self.object, 'rb') as f:\n+                    return f.read()\n+        if hasattr(self.object, 'read'):\n+            return self.object.read()\n+        if self._is_url(self.object):\n             import requests\n             r = requests.request(url=self.object, method='GET')\n             return r.content\n", "issue": "Support reading from BytesIO/StringIO\nI'm trying to write a GIF to memory and use panel to read from memory rather than storage.\r\n`ValueError: GIF pane does not support objects of type 'BytesIO'`\r\n\r\n```\r\nfrom io import BytesIO\r\nimport imageio\r\n\r\nmemory = BytesIO()\r\n\r\nsave_fps = [..]\r\n\r\nwith imageio.get_writer(memory, mode='I', format='gif', fps=8) as writer:\r\n    for fp in save_fps:\r\n        image = imageio.imread(fp)\r\n        writer.append_data(image)\r\n\r\nmemory.seek(0)\r\npn.pane.GIF(memory)\r\n```\n", "before_files": [{"content": "\"\"\"\nContains Image panes including renderers for PNG, SVG, GIF and JPG\nfile types.\n\"\"\"\nfrom __future__ import absolute_import, division, unicode_literals\n\nimport base64\nimport os\n\nfrom io import BytesIO\nfrom six import string_types\n\nimport param\n\nfrom .markup import DivPaneBase\n\n\nclass ImageBase(DivPaneBase):\n    \"\"\"\n    Encodes an image as base64 and wraps it in a Bokeh Div model.\n    This is an abstract base class that needs the image type\n    to be specified and specific code for determining the image shape.\n\n    The imgtype determines the filetype, extension, and MIME type for\n    this image. Each image type (png,jpg,gif) has a base class that\n    supports anything with a `_repr_X_` method (where X is `png`,\n    `gif`, etc.), a local file with the given file extension, or a\n    HTTP(S) url with the given extension.  Subclasses of each type can\n    provide their own way of obtaining or generating a PNG.\n    \"\"\"\n\n    embed = param.Boolean(default=True, doc=\"\"\"\n        Whether to embed the image as base64.\"\"\")\n\n    imgtype = 'None'\n\n    __abstract = True\n\n    @classmethod\n    def applies(cls, obj):\n        imgtype = cls.imgtype\n        return (hasattr(obj, '_repr_'+imgtype+'_') or\n                (isinstance(obj, string_types) and\n                 ((os.path.isfile(obj) and obj.endswith('.'+imgtype)) or\n                  cls._is_url(obj))))\n\n    @classmethod\n    def _is_url(cls, obj):\n        return (isinstance(obj, string_types) and\n                (obj.startswith('http://') or obj.startswith('https://'))\n                and obj.endswith('.'+cls.imgtype))\n\n    def _img(self):\n        if not isinstance(self.object, string_types):\n            return getattr(self.object, '_repr_'+self.imgtype+'_')()\n        elif os.path.isfile(self.object):\n            with open(self.object, 'rb') as f:\n                return f.read()\n        else:\n            import requests\n            r = requests.request(url=self.object, method='GET')\n            return r.content\n\n    def _imgshape(self, data):\n        \"\"\"Calculate and return image width,height\"\"\"\n        raise NotImplementedError\n\n    def _get_properties(self):\n        p = super(ImageBase, self)._get_properties()\n        if self.object is None:\n            return dict(p, text='<img></img>')\n        data = self._img()\n        if not isinstance(data, bytes):\n            data = base64.b64decode(data)\n        width, height = self._imgshape(data)\n        if self.width is not None:\n            if self.height is None:\n                height = int((self.width/width)*height)\n            else:\n                height = self.height\n            width = self.width\n        elif self.height is not None:\n            width = int((self.height/height)*width)\n            height = self.height\n        if not self.embed:\n            src = self.object\n        else:\n            b64 = base64.b64encode(data).decode(\"utf-8\")\n            src = \"data:image/\"+self.imgtype+\";base64,{b64}\".format(b64=b64)\n\n        smode = self.sizing_mode\n        if smode in ['fixed', None]:\n            w, h = '%spx' % width, '%spx' % height\n        elif smode == 'stretch_both':\n            w, h = '100%', '100%'\n        elif smode == 'stretch_height':\n            w, h = '%spx' % width, '100%'\n        elif smode == 'stretch_height':\n            w, h = '100%', '%spx' % height\n        elif smode == 'scale_height':\n            w, h = 'auto', '100%'\n        else:\n            w, h = '100%', 'auto'\n\n        html = \"<img src='{src}' width='{width}' height='{height}'></img>\".format(\n            src=src, width=w, height=h)\n\n        return dict(p, width=width, height=height, text=html)\n\n\nclass PNG(ImageBase):\n\n    imgtype = 'png'\n\n    @classmethod\n    def _imgshape(cls, data):\n        import struct\n        w, h = struct.unpack('>LL', data[16:24])\n        return int(w), int(h)\n\n\nclass GIF(ImageBase):\n\n    imgtype = 'gif'\n\n    @classmethod\n    def _imgshape(cls, data):\n        import struct\n        w, h = struct.unpack(\"<HH\", data[6:10])\n        return int(w), int(h)\n\n\nclass JPG(ImageBase):\n\n    imgtype = 'jpg'\n\n    @classmethod\n    def _imgshape(cls, data):\n        import struct\n        b = BytesIO(data)\n        b.read(2)\n        c = b.read(1)\n        while (c and ord(c) != 0xDA):\n            while (ord(c) != 0xFF): c = b.read(1)\n            while (ord(c) == 0xFF): c = b.read(1)\n            if (ord(c) >= 0xC0 and ord(c) <= 0xC3):\n                b.read(3)\n                h, w = struct.unpack(\">HH\", b.read(4))\n                break\n            else:\n                b.read(int(struct.unpack(\">H\", b.read(2))[0])-2)\n            c = b.read(1)\n        return int(w), int(h)\n\n\nclass SVG(ImageBase):\n\n    imgtype = 'svg'\n\n    @classmethod\n    def applies(cls, obj):\n        return (super(SVG, cls).applies(obj) or\n                (isinstance(obj, string_types) and obj.lstrip().startswith('<svg')))\n\n    def _img(self):\n        if (isinstance(self.object, string_types) and\n            self.object.lstrip().startswith('<svg')):\n            return self.object\n        return super(SVG, self)._img()\n\n    def _imgshape(self, data):\n        return (self.width, self.height)\n\n    def _get_properties(self):\n        p = super(ImageBase, self)._get_properties()\n        if self.object is None:\n            return dict(p, text='<img></img>')\n        data = self._img()\n        width, height = self._imgshape(data)\n        if not isinstance(data, bytes):\n            data = data.encode('utf-8')\n        b64 = base64.b64encode(data).decode(\"utf-8\")\n        src = \"data:image/svg+xml;base64,{b64}\".format(b64=b64)\n        html = \"<img src='{src}' width={width} height={height}></img>\".format(\n            src=src, width=width, height=height\n        )\n        return dict(p, width=width, height=height, text=html)\n", "path": "panel/pane/image.py"}], "after_files": [{"content": "\"\"\"\nContains Image panes including renderers for PNG, SVG, GIF and JPG\nfile types.\n\"\"\"\nfrom __future__ import absolute_import, division, unicode_literals\n\nimport base64\nimport os\n\nfrom io import BytesIO\nfrom six import string_types\n\nimport param\n\nfrom .markup import DivPaneBase\n\n\nclass ImageBase(DivPaneBase):\n    \"\"\"\n    Encodes an image as base64 and wraps it in a Bokeh Div model.\n    This is an abstract base class that needs the image type\n    to be specified and specific code for determining the image shape.\n\n    The imgtype determines the filetype, extension, and MIME type for\n    this image. Each image type (png,jpg,gif) has a base class that\n    supports anything with a `_repr_X_` method (where X is `png`,\n    `gif`, etc.), a local file with the given file extension, or a\n    HTTP(S) url with the given extension.  Subclasses of each type can\n    provide their own way of obtaining or generating a PNG.\n    \"\"\"\n\n    embed = param.Boolean(default=True, doc=\"\"\"\n        Whether to embed the image as base64.\"\"\")\n\n    imgtype = 'None'\n\n    __abstract = True\n\n    @classmethod\n    def applies(cls, obj):\n        imgtype = cls.imgtype\n        if hasattr(obj, '_repr_{}_'.format(imgtype)):\n            return True\n        if isinstance(obj, string_types):\n            if os.path.isfile(obj) and obj.endswith('.'+imgtype):\n                return True\n            if cls._is_url(obj):\n                return True\n        if hasattr(obj, 'read'):  # Check for file like object\n            return True\n        return False\n\n    @classmethod\n    def _is_url(cls, obj):\n        if isinstance(obj, string_types):\n            lower_string = obj.lower()\n            return (\n                lower_string.startswith('http://')\n                or lower_string.startswith('https://')\n            ) and lower_string.endswith('.'+cls.imgtype)\n        return False\n\n    def _img(self):\n        if hasattr(self.object, '_repr_{}_'.format(self.imgtype)):\n            return getattr(self.object, '_repr_' + self.imgtype + '_')()\n        if isinstance(self.object, string_types):\n            if os.path.isfile(self.object):\n                with open(self.object, 'rb') as f:\n                    return f.read()\n        if hasattr(self.object, 'read'):\n            return self.object.read()\n        if self._is_url(self.object):\n            import requests\n            r = requests.request(url=self.object, method='GET')\n            return r.content\n\n    def _imgshape(self, data):\n        \"\"\"Calculate and return image width,height\"\"\"\n        raise NotImplementedError\n\n    def _get_properties(self):\n        p = super(ImageBase, self)._get_properties()\n        if self.object is None:\n            return dict(p, text='<img></img>')\n        data = self._img()\n        if not isinstance(data, bytes):\n            data = base64.b64decode(data)\n        width, height = self._imgshape(data)\n        if self.width is not None:\n            if self.height is None:\n                height = int((self.width/width)*height)\n            else:\n                height = self.height\n            width = self.width\n        elif self.height is not None:\n            width = int((self.height/height)*width)\n            height = self.height\n        if not self.embed:\n            src = self.object\n        else:\n            b64 = base64.b64encode(data).decode(\"utf-8\")\n            src = \"data:image/\"+self.imgtype+\";base64,{b64}\".format(b64=b64)\n\n        smode = self.sizing_mode\n        if smode in ['fixed', None]:\n            w, h = '%spx' % width, '%spx' % height\n        elif smode == 'stretch_both':\n            w, h = '100%', '100%'\n        elif smode == 'stretch_height':\n            w, h = '%spx' % width, '100%'\n        elif smode == 'stretch_height':\n            w, h = '100%', '%spx' % height\n        elif smode == 'scale_height':\n            w, h = 'auto', '100%'\n        else:\n            w, h = '100%', 'auto'\n\n        html = \"<img src='{src}' width='{width}' height='{height}'></img>\".format(\n            src=src, width=w, height=h)\n\n        return dict(p, width=width, height=height, text=html)\n\n\nclass PNG(ImageBase):\n\n    imgtype = 'png'\n\n    @classmethod\n    def _imgshape(cls, data):\n        import struct\n        w, h = struct.unpack('>LL', data[16:24])\n        return int(w), int(h)\n\n\nclass GIF(ImageBase):\n\n    imgtype = 'gif'\n\n    @classmethod\n    def _imgshape(cls, data):\n        import struct\n        w, h = struct.unpack(\"<HH\", data[6:10])\n        return int(w), int(h)\n\n\nclass JPG(ImageBase):\n\n    imgtype = 'jpg'\n\n    @classmethod\n    def _imgshape(cls, data):\n        import struct\n        b = BytesIO(data)\n        b.read(2)\n        c = b.read(1)\n        while (c and ord(c) != 0xDA):\n            while (ord(c) != 0xFF): c = b.read(1)\n            while (ord(c) == 0xFF): c = b.read(1)\n            if (ord(c) >= 0xC0 and ord(c) <= 0xC3):\n                b.read(3)\n                h, w = struct.unpack(\">HH\", b.read(4))\n                break\n            else:\n                b.read(int(struct.unpack(\">H\", b.read(2))[0])-2)\n            c = b.read(1)\n        return int(w), int(h)\n\n\nclass SVG(ImageBase):\n\n    imgtype = 'svg'\n\n    @classmethod\n    def applies(cls, obj):\n        return (super(SVG, cls).applies(obj) or\n                (isinstance(obj, string_types) and obj.lstrip().startswith('<svg')))\n\n    def _img(self):\n        if (isinstance(self.object, string_types) and\n            self.object.lstrip().startswith('<svg')):\n            return self.object\n        return super(SVG, self)._img()\n\n    def _imgshape(self, data):\n        return (self.width, self.height)\n\n    def _get_properties(self):\n        p = super(ImageBase, self)._get_properties()\n        if self.object is None:\n            return dict(p, text='<img></img>')\n        data = self._img()\n        width, height = self._imgshape(data)\n        if not isinstance(data, bytes):\n            data = data.encode('utf-8')\n        b64 = base64.b64encode(data).decode(\"utf-8\")\n        src = \"data:image/svg+xml;base64,{b64}\".format(b64=b64)\n        html = \"<img src='{src}' width={width} height={height}></img>\".format(\n            src=src, width=width, height=height\n        )\n        return dict(p, width=width, height=height, text=html)\n", "path": "panel/pane/image.py"}]}