Spaces:
Sleeping
Sleeping
metadata
title: iris-backend
emoji: πΈ
colorFrom: green
colorTo: blue
sdk: docker
pinned: false
license: mit
πΈ Iris Flower Classifier (Flask API)
A lightweight Flask API hosted on Hugging Face Spaces that predicts the species of an Iris flower using a Scikit-learn Logistic Regression model.
The frontend UI is hosted separately on GitHub Pages:
π Try it here
π How it works
- User enters flower measurements (sepal & petal length/width) on the frontend.
- Frontend sends data as JSON to this backend API (
/predictendpoint). - The Flask app loads a pickled Scikit-learn model and predicts the species.
- Response is returned as JSON and displayed on the frontend.
π§ Tech Stack
- Python 3.9+
- Flask β Web framework
- Flask-CORS β Allow frontend/backend communication
- Scikit-learn β ML model (Logistic Regression)
- Pickle β Model persistence
- Hugging Face Spaces (Docker SDK) β Deployment
π File Structure
βββ app.py # Flask API
βββ model.pkl # Pre-trained ML model
βββ requirements.txt # Python dependencies
βββ Dockerfile # Custom Space runtime
βββ README.md # Project documentation
π‘ API Usage
Endpoint
POST /predict
Request (JSON)
{
"sepal_length": 5.1,
"sepal_width": 3.5,
"petal_length": 1.4,
"petal_width": 0.2
}
Response (JSON)
{
"prediction": "setosa"
}
π οΈ Run Locally
Clone and run with Docker:
git clone https://huggingface.co/spaces/<your-username>/iris-backend
cd iris-backend
docker build -t iris-backend .
docker run -p 7860:7860 iris-backend
Now open http://localhost:7860/predict.
π Frontend
The frontend is hosted on GitHub Pages: π Iris Classifier Frontend
Frontend calls the backend API hosted here on Hugging Face Spaces.
πΈ Demo Screenshot
π License
MIT License β free to use and modify.
