Important
Hey, you probably shouldn't use this. It is just for fun.
❤️ Daniel
An easy-to-use API framework for serving machine learning models via a REST API. Built on the robust foundation of Starlette, Uvicorn, and Asyncio.
- 🚄 Fast and Asynchronous: Leverages the power of Starlette and Uvicorn for high-performance operations.
- 📦 Model Agnostic: Add any model seamlessly with a few lines of code.
- 🔐 Secure: Choose between OAuth or basic authentication for secure endpoint access.
- 🔄 Automatic API Generation: API endpoints are generated based on the type signature of your model's
runfunction. - 🎒 Built-In Tunneling: With
pyngrokintegration, expose your local server to the world without any hassles.
Make sure you have poetry installed. If not, install it using:
pip install poetryThen, clone the repository and install dependencies:
git clone https://github.com/dtkav/gpu-box
cd gpu-box
poetry installYou can store environment variables set in a file called .auth.env.
NGROK_DOMAIN=your.domain.here
NGROK_TOKEN=<your token goes here>
NGROK_AUTH_PAIRS=user:pass,user2:pass2
NGROK_ALLOWED_EMAILS=butts@gmail.com,butts2@gmail.com
NGROK_OAUTH_PROVIDER=google
Use the provided do script to source the environment from this file.
./do python cli.py oauthYou can start the server using:
python cli.py serveTo expose your local server with ngrok, you can either use OAuth or basic authentication:
- OAuth2:
python cli.py oauth --token YOUR_NGROK_TOKEN --oauth-provider=google --allowed-emails=butts@gmail.com- Basic Authentication:
python cli.py password --token YOUR_NGROK_TOKEN --auth-pairs username:passwordAdding new models is a breeze! Here's a simple step-by-step guide:
- Define a new class that inherits from
ModelRoute. - Set the
nameattribute (this becomes the API endpoint). - Implement the
loadmethod to load your model. - Implement the
runmethod. The API for the model is generated based on the type signature of this function.
For instance:
from .base import ModelRoute
from gpu_box.types import JSONType, File
from whispercpp import Whisper
class WhisperCppBase(ModelRoute):
name = "whispercpp-base"
model_size = "base"
def load(self):
return Whisper(self.model_size)
async def run(self, file: File) -> str:
print(f"running model on {file.name} (@{file.path})")
result = self.model.transcribe(file.path)
return "\n\n".join(self.model.extract_text(result))This will create an API endpoint at /whispercpp-base that accepts file uploads and outputs text.