iris-backend / README.md
LovnishVerma's picture
Update README.md
a762a94 verified
---
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](https://huggingface.co/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](https://lovnishverma.github.io/iris-front/)
---
## πŸš€ How it works
1. User enters flower measurements (sepal & petal length/width) on the frontend.
2. Frontend sends data as JSON to this backend API (`/predict` endpoint).
3. The Flask app loads a pickled Scikit-learn model and predicts the species.
4. 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)
```json
{
"sepal_length": 5.1,
"sepal_width": 3.5,
"petal_length": 1.4,
"petal_width": 0.2
}
````
### Response (JSON)
```json
{
"prediction": "setosa"
}
```
---
## πŸ› οΈ Run Locally
Clone and run with Docker:
```bash
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](http://localhost:7860/predict).
---
## 🌐 Frontend
The frontend is hosted on GitHub Pages:
πŸ‘‰ [Iris Classifier Frontend](https://lovnishverma.github.io/iris-front/)
Frontend calls the backend API hosted here on Hugging Face Spaces.
---
## πŸ“Έ Demo Screenshot
![Demo](https://cdn-uploads.huggingface.co/production/uploads/6474405f90330355db146c76/w60iyWrc6vmicBW8e0SEJ.png)
---
## πŸ“œ License
MIT License – free to use and modify.
---