-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Closed
Labels
Description
First Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn't find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google "How to X in FastAPI" and didn't find any information.
- I already read and followed all the tutorial in the docs and didn't find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
from fastpi import FastAPI, Body
from spacy.cli.train import train
app = FastAPI()
@app.post("/training")
def root(key = Body(embed = True)):
train("scratch_config.cfg", output_path="this_day", overrides={"paths.train": "train.spacy", "paths.dev": "valid.spacy"}) # this is the function used for training a spacy modelDescription
Command to start the server:
uvicorn spacy_train:app --workers 4
Actual behaviour:
[2022-09-23 15:21:22 +0530] [24893] [ERROR] Exception in ASGI application
Traceback (most recent call last):
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 404, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
return await self.app(scope, receive, send)
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/fastapi/applications.py", line 269, in __call__
await super().__call__(scope, receive, send)
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/starlette/applications.py", line 124, in __call__
await self.middleware_stack(scope, receive, send)
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/starlette/middleware/errors.py", line 184, in __call__
raise exc
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/starlette/middleware/errors.py", line 162, in __call__
await self.app(scope, receive, _send)
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/starlette/exceptions.py", line 93, in __call__
raise exc
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
await self.app(scope, receive, sender)
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
raise e
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
await self.app(scope, receive, send)
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/starlette/routing.py", line 670, in __call__
await route.handle(scope, receive, send)
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/starlette/routing.py", line 266, in handle
await self.app(scope, receive, send)
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/starlette/routing.py", line 65, in app
response = await func(request)
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/fastapi/routing.py", line 231, in app
raw_response = await run_endpoint_function(
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/fastapi/routing.py", line 162, in run_endpoint_function
return await run_in_threadpool(dependant.call, **values)
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/starlette/concurrency.py", line 41, in run_in_threadpool
return await anyio.to_thread.run_sync(func, *args)
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/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/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
return await future
File "/home/local/ZOHOCORP/ravi-9151/anaconda3/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 867, in run
result = context.run(func, *args)
File "/home/local/ZOHOCORP/ravi-9151/Downloads/custom_ner/streamlit_pipeline/fast_api.py", line 119, in root
train("scratch_config.cfg")
TypeError: 'list' object is not callable
Expected Behaviour:
_ Created output directory: this_day
_ Saving to output directory: this_day
_ Using CPU
=========================== Initializing pipeline ===========================
_ Initialized pipeline
============================= Training pipeline =============================
_ Pipeline: ['tok2vec', 'textcat']
_ Initial learn rate: 0.001
E # LOSS TOK2VEC LOSS TEXTCAT CATS_SCORE ENTS_F ENTS_P ENTS_R TAG_ACC POS_ACC MORPH_ACC LEMMA_ACC DEP_UAS DEP_LAS SENTS_F SCORE
--- ------ ------------ ------------ ---------- ------ ------ ------ ------- ------- --------- --------- ------- ------- ------- ------
0 0 0.00 0.25 50.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.25
69 200 0.00 7.03 50.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.25
169 400 0.00 0.09 50.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.25
269 600 0.00 0.03 50.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.25
382 800 0.00 0.02 50.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.25
582 1000 0.00 0.01 50.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.25
782 1200 0.00 0.01 50.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.25
982 1400 0.00 0.00 50.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.25
1182 1600 0.00 0.00 50.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.25
_ Saved pipeline to output directory
this_day/model-last
Operating System
Linux
Operating System Details
Ubuntu 20.04.1 LTS
FastAPI Version
0.82.0
Python Version
3.8.3
Additional Context
train("scratch_config.cfg", output_path="this_day", overrides={"paths.train": "train.spacy", "paths.dev": "valid.spacy"})
The above call works properly when i add it in a python file and execute it using the command python spacy_train.py