abi / screenshot-to-code

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
https://screenshottocode.com
MIT License
59.58k stars 7.33k forks source link

`ERROR: Exception in ASGI application` when using `Screen Recording to prototype` #278

Open yumlii33 opened 7 months ago

yumlii33 commented 7 months ago

When I use other functions, everything is normal. But when I uploaded the screen recording, the error was as follows:

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 250, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/fastapi/applications.py", line 276, in __call__
    await super().__call__(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/starlette/middleware/errors.py", line 149, in __call__
    await self.app(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/starlette/middleware/cors.py", line 75, in __call__
    await self.app(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 341, in handle
    await self.app(scope, receive, send)
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 82, in app
    await func(session)
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/fastapi/routing.py", line 289, in app
    await dependant.call(**values)
  File "/root/Workspace/screenshot-to-code/backend/routes/generate_code.py", line 64, in stream_code
    params: Dict[str, str] = await websocket.receive_json()
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/starlette/websockets.py", line 133, in receive_json
    self._raise_on_disconnect(message)
  File "/root/.cache/pypoetry/virtualenvs/backend-1Rb1d6GZ-py3.10/lib/python3.10/site-packages/starlette/websockets.py", line 105, in _raise_on_disconnect
    raise WebSocketDisconnect(message["code"])
starlette.websockets.WebSocketDisconnect: CloseCode.ABNORMAL_CLOSURE
INFO:     connection closed
abi commented 7 months ago

How long is your video?

nellojh commented 7 months ago

Same ASGI error, but it was happened when use a screenshot. My error is as follows:

Traceback (most recent call last):
  File "/home/ljh/.cache/pypoetry/virtualenvs/backend-86_ny3-v-py3.10/lib/python3.10/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 250, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)
  File "/home/ljh/.cache/pypoetry/virtualenvs/backend-86_ny3-v-py3.10/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
  File "/home/ljh/.cache/pypoetry/virtualenvs/backend-86_ny3-v-py3.10/lib/python3.10/site-packages/fastapi/applications.py", line 276, in __call__
    await super().__call__(scope, receive, send)
  File "/home/ljh/.cache/pypoetry/virtualenvs/backend-86_ny3-v-py3.10/lib/python3.10/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/ljh/.cache/pypoetry/virtualenvs/backend-86_ny3-v-py3.10/lib/python3.10/site-packages/starlette/middleware/errors.py", line 149, in __call__
    await self.app(scope, receive, send)
  File "/home/ljh/.cache/pypoetry/virtualenvs/backend-86_ny3-v-py3.10/lib/python3.10/site-packages/starlette/middleware/cors.py", line 75, in __call__
    await self.app(scope, receive, send)
  File "/home/ljh/.cache/pypoetry/virtualenvs/backend-86_ny3-v-py3.10/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/home/ljh/.cache/pypoetry/virtualenvs/backend-86_ny3-v-py3.10/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/home/ljh/.cache/pypoetry/virtualenvs/backend-86_ny3-v-py3.10/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/home/ljh/.cache/pypoetry/virtualenvs/backend-86_ny3-v-py3.10/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/home/ljh/.cache/pypoetry/virtualenvs/backend-86_ny3-v-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/home/ljh/.cache/pypoetry/virtualenvs/backend-86_ny3-v-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 341, in handle
    await self.app(scope, receive, send)
  File "/home/ljh/.cache/pypoetry/virtualenvs/backend-86_ny3-v-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 82, in app
    await func(session)
  File "/home/ljh/.cache/pypoetry/virtualenvs/backend-86_ny3-v-py3.10/lib/python3.10/site-packages/fastapi/routing.py", line 289, in app
    await dependant.call(**values)
  File "/home/ljh/Softwares/screenshot-to-code/backend/routes/generate_code.py", line 260, in stream_code
    completion = await stream_openai_response(
  File "/home/ljh/Softwares/screenshot-to-code/backend/llm.py", line 54, in stream_openai_response
    content = chunk.choices[0].delta.content or ""
IndexError: list index out of range
abi commented 7 months ago

@nelloloujh are you getting that error when you do video or just a screenshot?

nellojh commented 7 months ago

@abi Just use a screenshot.

abi commented 7 months ago

Hard to debug with just that information. This error

"content = chunk.choices[0].delta.content or "" IndexError: list index out of range"

usually indicates the Open AI has not given a response. Are you using a screenshot that might trigger moderation blocking?

Does this error happen no matter what the screenshot is? Can you try a simple screenshot like one of google.com?

sh731928441 commented 7 months ago

@abi Could it be caused by the OpenAI Key being unavailable?

abi commented 7 months ago

@sh731928441 im not sure. Please open a separate ticket and share your logs.

eefeng commented 6 months ago

same issue

darshansharma commented 6 months ago

I got the same error, I had valid key with credits inside it but I keep getting the same error: Exception in AGSI. I tried using to run via Docker too but on docker got the same error.

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Users/darshan/Library/Caches/pypoetry/virtualenvs/backend-z9_R7sxo-py3.11/lib/python3.11/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 250, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/darshan/Library/Caches/pypoetry/virtualenvs/backend-z9_R7sxo-py3.11/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/darshan/Library/Caches/pypoetry/virtualenvs/backend-z9_R7sxo-py3.11/lib/python3.11/site-packages/fastapi/applications.py", line 276, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/darshan/Library/Caches/pypoetry/virtualenvs/backend-z9_R7sxo-py3.11/lib/python3.11/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/darshan/Library/Caches/pypoetry/virtualenvs/backend-z9_R7sxo-py3.11/lib/python3.11/site-packages/starlette/middleware/errors.py", line 149, in __call__
    await self.app(scope, receive, send)
  File "/Users/darshan/Library/Caches/pypoetry/virtualenvs/backend-z9_R7sxo-py3.11/lib/python3.11/site-packages/starlette/middleware/cors.py", line 75, in __call__
    await self.app(scope, receive, send)
  File "/Users/darshan/Library/Caches/pypoetry/virtualenvs/backend-z9_R7sxo-py3.11/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/Users/darshan/Library/Caches/pypoetry/virtualenvs/backend-z9_R7sxo-py3.11/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/Users/darshan/Library/Caches/pypoetry/virtualenvs/backend-z9_R7sxo-py3.11/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/Users/darshan/Library/Caches/pypoetry/virtualenvs/backend-z9_R7sxo-py3.11/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/Users/darshan/Library/Caches/pypoetry/virtualenvs/backend-z9_R7sxo-py3.11/lib/python3.11/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/Users/darshan/Library/Caches/pypoetry/virtualenvs/backend-z9_R7sxo-py3.11/lib/python3.11/site-packages/starlette/routing.py", line 341, in handle
    await self.app(scope, receive, send)
  File "/Users/darshan/Library/Caches/pypoetry/virtualenvs/backend-z9_R7sxo-py3.11/lib/python3.11/site-packages/starlette/routing.py", line 82, in app
    await func(session)
  File "/Users/darshan/Library/Caches/pypoetry/virtualenvs/backend-z9_R7sxo-py3.11/lib/python3.11/site-packages/fastapi/routing.py", line 289, in app
    await dependant.call(**values)
MuazAshraf commented 6 months ago

I am slecting calude sonnet model for rescord screen and got the same error ERROR: Exception in ASGI application Traceback (most recent call last): File "D:\mojosolo_projects\screenshottocode.venv\Lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 285, in ffmpeg_parse_infos line = [l for l in lines if keyword in l][index]


IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 250, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 84, in __call__   
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\fastapi\applications.py", line 276, in __call__
    await super().__call__(scope, receive, send)
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\starlette\applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\starlette\middleware\errors.py", line 149, in __call__       
    await self.app(scope, receive, send)
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\starlette\middleware\cors.py", line 75, in __call__
    await self.app(scope, receive, send)
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\starlette\middleware\exceptions.py", line 79, in __call__    
    raise exc
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__    
    await self.app(scope, receive, sender)
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in __call__  
    raise e
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in __call__  
    await self.app(scope, receive, send)
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\starlette\routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\starlette\routing.py", line 341, in handle
    await self.app(scope, receive, send)
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\starlette\routing.py", line 82, in app
    await func(session)
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\fastapi\routing.py", line 289, in app
    await dependant.call(**values)
  File "D:\mojosolo_projects\screenshottocode\screenshot-to-code\backend\routes\generate_code.py", line 210, in stream_code        
    prompt_messages = await assemble_claude_prompt_video(video_data_url)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\mojosolo_projects\screenshottocode\screenshot-to-code\backend\video\utils.py", line 21, in assemble_claude_prompt_video 
    images = split_video_into_screenshots(video_data_url)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\mojosolo_projects\screenshottocode\screenshot-to-code\backend\video\utils.py", line 79, in split_video_into_screenshots 
    clip = VideoFileClip(temp_video_file.name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\moviepy\video\io\VideoFileClip.py", line 88, in __init__     
    self.reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt,
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 35, in __init__     
    infos = ffmpeg_parse_infos(filename, print_infos, check_duration,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\mojosolo_projects\screenshottocode\.venv\Lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 289, in ffmpeg_parse_infos
    raise IOError(("MoviePy error: failed to read the duration of file %s.\n"
OSError: MoviePy error: failed to read the duration of file C:\Users\MUAZ\AppData\Local\Temp\tmpr286buta.webm.
Here are the file infos returned by ffmpeg:

ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20200122
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
C:\Users\MUAZ\AppData\Local\Temp\tmpr286buta.webm: Permission denied
Web3Worlds commented 3 months ago

Same issue

Web3Worlds commented 3 months ago

This problem is due to the fact that ffmpeg cannot determine the length of the video. You can try to change the way of video length detection and try a different codec