How to use do offscreen rendering in huggingface space?

I am trying to use pyrender to do offscreen rendering with the egl platform. But it seems that the huggingface space doesn’t support that. Any help will be appreciated.

Traceback (most recent call last):
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/gradio/routes.py", line 322, in run_predict
    output = await app.get_blocks().process_api(
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/gradio/blocks.py", line 1015, in process_api
    result = await self.call_function(
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/gradio/blocks.py", line 833, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/anyio/to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "/home/user/app/interface.py", line 179, in pose_generation
    res = _sampling(config, scene)
  File "/home/user/app/interface.py", line 106, in _sampling
    results = visualizer.visualize(model, dataloader)
  File "/home/user/app/scenediffuser/models/visualizer.py", line 468, in visualize
    img = render_prox_scene({'scenes': [scene_mesh], 'bodies': [body_mesh]}, camera_pose, None)
  File "/home/user/app/scenediffuser/utils/visualize.py", line 60, in render_prox_scene
    r = pyrender.OffscreenRenderer(
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/pyrender/offscreen.py", line 31, in __init__
    self._create()
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/pyrender/offscreen.py", line 149, in _create
    self._platform.init_context()
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/pyrender/platforms/egl.py", line 186, in init_context
    self._egl_context = eglCreateContext(
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 402, in __call__
    return self( *args, **named )
  File "/home/user/.pyenv/versions/3.8.9/lib/python3.8/site-packages/OpenGL/error.py", line 228, in glCheckError
    raise GLError(
OpenGL.error.GLError: GLError(
	err = 12297,
	baseOperation = eglCreateContext,
	cArguments = (
		<OpenGL._opaque.EGLDisplay_pointer object at 0x7ff20c16e440>,
		<OpenGL._opaque.EGLConfig_pointer object at 0x7ff20c16e6c0>,
		<OpenGL._opaque.EGLContext_pointer object at 0x7ff20c176cc0>,
		<OpenGL.arrays.lists.c_int_Array_7 object at 0x7ff20c16e140>,
	),
	result = <OpenGL._opaque.EGLContext_pointer object at 0x7ff20c1767c0>
)

"I have the same issue as you. Can you find any solution for it?

Hi you can try xvfb, add it to packages.txt if you’re using a Gradio or Streamlit SDK

xvfb

or if you’re using Docker SDK you need to install via

sudo apt-get install xvfb
xvfb-run --server-args="-screen 0 1024x768x24" python my_script.py

Here is a notebook using this

Thank you. I am currently using Colab and Miniconda environment. I am trying to use your idea, but so far I have not been able to solve the problem.