CoolFace
Apppublic

arasmodirpolimi/tech-stack-advisor-arasmo

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
App README

๐Ÿง  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. 1.Clone the repository
bash
git clone https://github.com/<your-username>/tech-stack-advisor.git
cd tech-stack-advisor
  1. 1.Install dependencies

(Optional: Use a virtual environment)

bash
pip install -r requirements.txt
  1. 1.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. 1.Build the image
bash
docker build -t tech-stack-advisor .
  1. 1.Run the container
bash
docker run -p 7860:7860 tech-stack-advisor

Visit: http://localhost:7860


โ˜๏ธ Step 5: Publish to Docker Hub

  1. 1.Login to Docker Hub
bash
docker login
  1. 1.Tag the image
bash
docker tag tech-stack-advisor <your-dockerhub-username>/tech-stack-advisor:latest
  1. 1.Push it
bash
docker push <your-dockerhub-username>/tech-stack-advisor:latest

๐ŸŒ Step 6: Deploy to Hugging Face Spaces

  1. 1.Go to huggingface.co/spaces
  2. 2.Click Create New Space
  3. 3.Select:
  • โ€”SDK: Docker
  • โ€”Repository: Link to your GitHub repo with the Dockerfile
  • โ€”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 file for details.


๐Ÿ›  Happy shipping, DevOps and MLOps builders!