abi / screenshot-to-code

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

Running backend error #369

Closed skyv195 closed 4 months ago

skyv195 commented 4 months ago

(backend-py3.12) D:\Engines\screenshot-to-code\backend>poetry run uvicorn main:app --reload --port 7001 INFO: Will watch for changes in these directories: ['D:\Engines\screenshot-to-code\backend'] INFO: Uvicorn running on http://127.0.0.1:7001 (Press CTRL+C to quit) INFO: Started reloader process [8652] using StatReload Process SpawnProcess-1: Traceback (most recent call last): File "C:\Users\Andrew\AppData\Local\Programs\Python\Python312\Lib\multiprocessing\process.py", line 314, in _bootstrap self.run() File "C:\Users\Andrew\AppData\Local\Programs\Python\Python312\Lib\multiprocessing\process.py", line 108, in run self._target(*self._args, **self._kwargs) File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\uvicorn_subprocess.py", line 76, in subprocess_started target(sockets=sockets) File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\uvicorn\server.py", line 61, in run return asyncio.run(self.serve(sockets=sockets)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\uvicorn\server.py", line 68, in serve config.load() File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\uvicorn\config.py", line 467, in load self.loaded_app = import_from_string(self.app) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\uvicorn\importer.py", line 21, in import_from_string module = importlib.import_module(module_str) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\Programs\Python\Python312\Lib\importlib__init.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1387, in _gcd_import File "", line 1360, in _find_and_load File "", line 1331, in _find_and_load_unlocked File "", line 935, in _load_unlocked File "", line 995, in exec_module File "", line 488, in _call_with_frames_removed File "D:\Engines\screenshot-to-code\backend\main.py", line 7, in from fastapi import FastAPI File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\fastapi__init.py", line 7, in from .applications import FastAPI as FastAPI File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\fastapi\applications.py", line 16, in from fastapi import routing File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\fastapi\routing.py", line 24, in from fastapi.dependencies.models import Dependant File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\fastapi\dependencies\models.py", line 3, in from fastapi.security.base import SecurityBase File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\fastapi\security\init.py", line 1, in from .api_key import APIKeyCookie as APIKeyCookie File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\fastapi\security\api_key.py", line 3, in from fastapi.openapi.models import APIKey, APIKeyIn File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\fastapi\openapi\models.py", line 103, in class Schema(BaseModel): File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\pydantic\main.py", line 286, in new cls.try_update_forward_refs() File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\pydantic\main.py", line 807, in try_update_forward_refs__ update_model_forward_refs(cls, cls.fields.values(), cls.config__.json_encoders, localns, (NameError,)) File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\pydantic\typing.py", line 554, in update_model_forward_refs update_field_forward_refs(f, globalns=globalns, localns=localns) File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\pydantic\typing.py", line 520, in update_field_forwardrefs field.type = evaluateforwardref(field.type, globalns, localns or None) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\pydantic\typing.py", line 66, in evaluateforwardref return cast(Any, type)._evaluate(globalns, localns, set()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard' INFO: Stopping reloader process [8652]

abi commented 4 months ago

Are you using Docker or not?

abi commented 4 months ago

It's related to the issue fixed here: https://github.com/abi/screenshot-to-code/pull/358/files

skyv195 commented 4 months ago

Hi abi,

I am not using Docker. What do I have to do to fix it?

abi commented 4 months ago

I feel like it's a Python version problem. Can you share which Python version you're running?

Updating your Python might help fix the problem.

abi commented 4 months ago

This is the root cause: https://github.com/pydantic/pydantic/issues/9637

Running poetry add pydantic@1.10.16 is potentially another way to fix this

abi commented 4 months ago

Let me know if these solutions work.

skyv195 commented 4 months ago

Hi abi, I am using the latest Python 3.12. I will try the pydantic route. I will advise. Thank you, abi.

abi commented 4 months ago

@skyv195 were you able to get it working?

skyv195 commented 4 months ago

Hi abi, I was able to run the backend by modifying the pyproject.toml (see modification below) and adding the pydantic version per your suggestion. Running the frontend and tests gave an error saying that the caniuse-lite is outdated. I had updated that but the error persisted. Let me know what you think. Thanks!

================================================================== [tool.poetry.group.dev.dependencies] pytest = "^7.4.3" pyright = "^1.1.352" pydantic = "^1.10.16"

skyv195 commented 4 months ago

Also, the backend console shows the error:

Traceback (most recent call last): File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\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 "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\uvicorn\middleware\proxy_headers.py", line 84, in call return await self.app(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\fastapi\applications.py", line 276, in call await super().call(scope, receive, send) File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\starlette\applications.py", line 122, in call await self.middleware_stack(scope, receive, send) File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\starlette\middleware\errors.py", line 149, in call await self.app(scope, receive, send) File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\starlette\middleware\cors.py", line 75, in call await self.app(scope, receive, send) File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\starlette\middleware\exceptions.py", line 79, in call raise exc File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\starlette\middleware\exceptions.py", line 68, in call await self.app(scope, receive, sender) File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in call raise e File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in call await self.app(scope, receive, send) File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\starlette\routing.py", line 718, in call await route.handle(scope, receive, send) File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\starlette\routing.py", line 341, in handle await self.app(scope, receive, send) File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\starlette\routing.py", line 82, in app await func(session) File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\fastapi\routing.py", line 289, in app await dependant.call(values) File "D:\Engines\screenshot-to-code\backend\routes\generate_code.py", line 268, in stream_code completion = await stream_openai_response( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Engines\screenshot-to-code\backend\llm.py", line 61, in stream_openai_response stream = await client.chat.completions.create(params) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\openai\resources\chat\completions.py", line 1289, in create return await self._post( ^^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\openai_base_client.py", line 1816, in post return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\openai_base_client.py", line 1514, in request return await self._request( ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\openai_base_client.py", line 1572, in _request return await self._retry_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\openai_base_client.py", line 1641, in _retry_request return await self._request( ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\openai_base_client.py", line 1572, in _request return await self._retry_request( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\openai_base_client.py", line 1641, in _retry_request return await self._request( ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Andrew\AppData\Local\pypoetry\Cache\virtualenvs\backend-gOr3DTV2-py3.12\Lib\site-packages\openai_base_client.py", line 1582, in _request raise APIConnectionError(request=request) from err openai.APIConnectionError: Connection error.

skyv195 commented 4 months ago

Hi abi, I was able to make the frontend work by using different API key. I was able to import an existing HTML file and generate changes.

But the browserslist error persist even after updating using npx as recommended. Please advise.

abi commented 4 months ago

I think the browserlist error is fine. Is it causing any bugs or do things work well for you?

skyv195 commented 4 months ago

Limited testing with an existing html file looks good so far. Screenshot method also works in most cases. I'll keep testing and report back. Keep up the good work!

Any support for local models like Ollama?

abi commented 4 months ago

Great, closing this ticket then.

We do plan to support local models, #17