Spaces:
Sleeping
Sleeping
File size: 3,696 Bytes
251fdfe cf6bf05 251fdfe cf6bf05 251fdfe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
---
title: Tech Stack Advisor
emoji: π§
colorFrom: indigo
colorTo: pink
sdk: docker
app_file: app.py
pinned: false
license: apache-2.0
duplicable: true
---
# π§ Tech Stack Advisor β ML App (with Docker & Hugging Face Deployment)
**Tech Stack Advisor** is a hands-on machine learning project designed to teach you how to build, containerize, and deploy an ML-powered web application using Docker and Hugging Face Spaces.
> π― This project is part of the **"Artificial Intelligence and Machine Learning (AI/ML) with Docker"** course from **School of DevOps**.
---
## π What You'll Learn
- Build and train a simple ML model using `scikit-learn`
- Create a UI using `Gradio`
- Containerize your app using a Dockerfile
- Push your Docker image to Docker Hub
- Deploy the Dockerized app on Hugging Face Spaces (free tier)
---
## π Project Structure
```
tech-stack-advisor/
βββ app.py # Gradio web app
βββ train.py # Script to train and save ML model
βββ requirements.txt # Python dependencies
βββ Dockerfile # Docker build file (added during the lab)
βββ model.pkl # Trained ML model (generated after training)
βββ encoders.pkl # Encoders for categorical inputs (generated after training)
βββ LICENSE # Apache 2.0 license
βββ README.md # This guide
````
---
## π§ Step 1: Setup and Train Your ML Model
1. **Clone the repository**
```bash
git clone https://github.com/<your-username>/tech-stack-advisor.git
cd tech-stack-advisor
````
2. **Install dependencies**
(Optional: Use a virtual environment)
```bash
pip install -r requirements.txt
```
3. **Train the model**
```bash
python train.py
```
This creates:
* `model.pkl`: the trained ML model
* `encoders.pkl`: label encoders for input/output features
---
## π₯οΈ Step 2: Run the App Locally (Without Docker)
```bash
python app.py
```
Visit the app in your browser at:
```
http://localhost:7860
```
---
## π³ Step 3: Add Docker Support
Create a file named `Dockerfile` in the root of the project:
```dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 7860
CMD ["python", "app.py"]
```
---
## π§ Step 4: Build and Run the Docker Container
1. **Build the image**
```bash
docker build -t tech-stack-advisor .
```
2. **Run the container**
```bash
docker run -p 7860:7860 tech-stack-advisor
```
Visit: `http://localhost:7860`
---
## βοΈ Step 5: Publish to Docker Hub
1. **Login to Docker Hub**
```bash
docker login
```
2. **Tag the image**
```bash
docker tag tech-stack-advisor <your-dockerhub-username>/tech-stack-advisor:latest
```
3. **Push it**
```bash
docker push <your-dockerhub-username>/tech-stack-advisor:latest
```
---
## π Step 6: Deploy to Hugging Face Spaces
1. Go to [huggingface.co/spaces](https://huggingface.co/spaces)
2. Click **Create New Space**
3. Select:
* **SDK**: Docker
* **Repository**: Link to your GitHub repo with the Dockerfile
4. Hugging Face will auto-build and deploy your container.
---
## π§ͺ Test Your Skills
* Can you swap the model in `train.py` for a `LogisticRegression` model?
* Can you add logging to show which inputs were passed?
* Try changing the Gradio layout or theme!
---
## π§Ύ License
This project is licensed under the **Apache License 2.0**.
See the [LICENSE](./LICENSE) file for details.
---
## π Credits
Created by \[Gourav Shah](https://www.linkedin.com/in/gouravshah) as part of the **AI/ML with Docker** course at **School of DevOps**.
---
> π Happy shipping, DevOps and MLOps builders!
|