How can I run two functions within the same FastAPI application, where one function requires transformers==4.32.8 and the other requires transformers==5.32.8?
Loading
How can I run two functions within the same FastAPI application, where one function requires transformers==4.32.8 and the other requires transformers==5.32.8?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naimish MakwanaPosted Oct 15, 2024, 11:59 AM
Running two different versions of the same library within a single FastAPI application can be tricky due to dependency conflicts. However, you can achieve this by using separate virtual environments and subprocesses. Here’s a step-by-step guide:
Create Virtual Environments: Set up two separate virtual environments, each with the required version of the
transformerslibrary.Install Dependencies:
Create Python Scripts: Write separate Python scripts for each function that uses the respective version of the
transformerslibrary.Use Subprocesses in FastAPI: In your FastAPI application, use the
subprocessmodule to call these scripts.Run the FastAPI Application:
This setup allows you to run each function in its own isolated environment, avoiding dependency conflicts. Let me know if you need further assistance!