Paperspace / FastAPI-Hugging-Face-Template-App

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Run a FastAPI app with a Hugging Face model on Paperspace

Intro

This is a template for users looking to deploy their own FastAPI app with a Hugging Face model on Paperspace.

Project Structure

├── Dockerfile
├── requirements.txt
├── paperspace.yaml
├── app
    ├── main.py

Develop locally

  • Install the Paperspace CLI curl -fsSL https://paperspace.com/install.sh | sh
  • Initialize the app pspace init paperspace-hf -t Paperspace/FastAPI-Hugging-Face-Template-App. This will create an app locally, clone this GitHub repo as your app template, and remotely link your app to Paperspace so you can add secrets and collaborators.
  • Make updates to your application (e.g. application files, Dockerfile, requirements.txt)
  • Change the Hugging Face model used in the app
  • Build a new image by running docker build -t my-image:tag .
  • Push image to the container registry of your choice by running docker push my-image:tag
  • Update the app config at paperspace.yaml with the location of your new image
  • Update the app config with your choice of Hugging Face model. When using integrations, mounts will be located at /opt/integrations/
  • Deploy your application on Paperspace by running pspace up. Ensure you have the Paperspace CLI installed.

How to deploy

  • Install the Paperspace CLI curl -fsSL https://paperspace.com/install.sh | sh
  • Run pspace up to deploy your app on Paperspace. This will send the app config at [paperspace.yaml)(paperspace.yaml) to Paperspace, which will spin up your application.
  • Once the application is in a ready state, you can send a translation request to the endpoint using the application URL: curl -X GET '<application-url>/translate?text_input=Hello+world!'

Simplify your deployment workflow with GitHub Actions

Use the Paperspace Deploy Action to integrate a build/push process into your CI/CD pipeline.

Benefits of Hugging Face integrations

Hugging Face integrations are a simple way to integrate Hugging Face models into your application while improving start time performance for auto-scaling and production level applications.

A Hugging Face integration happens once at the beginning of each new application deployment (i.e. each app config update). A temporary volume is created, the Hugging Face repo is then cloned into that volume, and that volume is then mounted to your container on startup at /opt/integrations/<integration-name>. Any new replicas that are spun up due to auto-scaling will also have the volume mounted to the same path, without having to go through the repo cloning process again, which shortens startup times for each subsequent replica spin up. Learn more about integrations in the Paperspace docs.

Documentation

Learn more about Paperspace apps at our documentation site.

About

License:Apache License 2.0


Languages

Language:Python 88.7%Language:Dockerfile 11.3%