Spaces:
Sleeping
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](https://git-lfs.com/) | |
| * **Hugging Face CLI**: Install with `pip install huggingface_hub` | |
| ## Steps | |
| 1. **Log in to Hugging Face CLI** | |
| Open your terminal and log in to your Hugging Face account: | |
| ```bash | |
| huggingface-cli login | |
| ``` | |
| Follow the prompts to enter your Hugging Face token. | |
| 2. **Create a New Space on Hugging Face Hub** | |
| Go to [Hugging Face Spaces](https://huggingface.co/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". | |
| 3. **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: | |
| ```bash | |
| 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 main | |
| ``` | |
| Hugging Face Spaces will automatically detect your `Dockerfile` and `README.md` (in the `deployment` directory), 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. | |