Spaces:
Sleeping
Deploying to Hugging Face Spaces
This guide outlines the steps to deploy your FastAPI application to Hugging Face Spaces.
Prerequisites
Before you begin, ensure you have the following installed:
- Git LFS: Install Git LFS
- Hugging Face CLI: Install with
pip install huggingface_hub
Steps
Log in to Hugging Face CLI
Open your terminal and log in to your Hugging Face account:
huggingface-cli loginFollow the prompts to enter your Hugging Face token.
Create a New Space on Hugging Face Hub
Go to Hugging Face Spaces and click on "Create new Space".
- Choose a name for your Space (e.g.,
your-username/stock-predictor-api). - Select "Public" or "Private" as desired.
- For the SDK, select "Docker".
- Click "Create Space".
- Choose a name for your Space (e.g.,
Push Your Code to the Hugging Face Space
Navigate to your project's root directory in the terminal. Initialize a Git repository (if you haven't already), add the Hugging Face Space as a remote, and push your code:
cd /home/aman/code/ml_fr/ml_stocks git init git remote add origin https://huggingface.co/spaces/your-username/stock-predictor-api # Replace with your Space URL git add . git commit -m "Initial commit for Hugging Face deployment" git push origin mainHugging Face Spaces will automatically detect your
DockerfileandREADME.md(in thedeploymentdirectory), build the Docker image, and run your FastAPI application. Your application will then be accessible via the Space's URL.
Accessing Your API
Once deployed, your API will be accessible at the URL provided by Hugging Face Spaces. You can find this URL on your Space's page.