Skip to content

Latest commit

ย 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿท VinoLens

An AI-powered wine intelligence platform that uses machine learning to analyze wine chemistry, predict quality, discover wine profiles, and explain predictions with Google Gemini.

VinoLens is a full-stack machine learning project built around the Wine Quality dataset. It combines classical machine learning with a modern web application and generative AI.

The goal isn't simply to predict a wine's quality score โ€” VinoLens aims to help users understand why a wine receives its prediction and discover patterns across different wine profiles.


โœจ Features

๐Ÿท Wine Quality Prediction

Enter the physicochemical properties of a wine and receive a predicted quality score.

  • Linear Regression / other ML models
  • Model evaluation and comparison
  • Quality prediction from wine chemistry
  • Feature analysis

๐Ÿ“Š Wine Explorer

Explore the dataset interactively.

  • Visualize relationships between wine properties
  • Filter wines by characteristics
  • Explore quality distributions
  • Compare different wine profiles

๐Ÿง  Wine Profile Discovery

Use unsupervised learning to discover naturally occurring groups of wines.

Using clustering algorithms such as K-Means, VinoLens can identify wine profiles based on their chemical characteristics without using the quality label.

๐Ÿ” Model Insights

Understand what influences predictions.

  • Feature importance
  • Feature correlations
  • Prediction analysis
  • Model performance metrics

๐Ÿค– Gemini AI Sommelier

Google Gemini provides a natural-language explanation of the ML model's prediction.

Instead of simply showing:

Predicted Quality: 7.2

VinoLens can explain:

The wine's relatively high alcohol and sulphate levels contribute positively to the predicted quality, while volatile acidity has a negative influence.

The ML model makes the prediction. Gemini explains it.


๐Ÿ—๏ธ Architecture

                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                         โ”‚     Next.js     โ”‚
                         โ”‚    Frontend     โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚
                              HTTP / REST
                                  โ”‚
                                  โ–ผ
                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                         โ”‚     FastAPI     โ”‚
                         โ”‚     Backend     โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚             โ”‚             โ”‚
                    โ–ผ             โ–ผ             โ–ผ
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚ ML Model โ”‚ โ”‚ K-Means  โ”‚ โ”‚  Gemini  โ”‚
              โ”‚Regressionโ”‚ โ”‚Clusteringโ”‚ โ”‚   AI     โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                    โ”‚             โ”‚             โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                  โ”‚
                                  โ–ผ
                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                         โ”‚ Wine Quality    โ”‚
                         โ”‚ Dataset         โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿงฐ Tech Stack

Machine Learning

  • Python
  • Pandas
  • NumPy
  • Scikit-learn
  • Matplotlib
  • Jupyter Notebook

Backend

  • Python
  • FastAPI
  • Pydantic
  • Uvicorn

Frontend

  • Next.js
  • React
  • TypeScript
  • Tailwind CSS

AI

  • Google Gemini API

Development / Deployment

  • Git
  • GitHub
  • Docker
  • Docker Compose

๐Ÿ“ Project Structure

vinolens/
โ”‚
โ”œโ”€โ”€ frontend/                          # Next.js 14+ (Deployed to Vercel)
โ”‚   โ”œโ”€โ”€ app/                           # App Router (pages & layouts)
โ”‚   โ”œโ”€โ”€ components/                    # UI & chart components
โ”‚   โ”‚   โ”œโ”€โ”€ ui/                        # Reusable primitives (buttons, inputs)
โ”‚   โ”‚   โ”œโ”€โ”€ wine-form.tsx              # Input chemical properties
โ”‚   โ”‚   โ””โ”€โ”€ prediction-card.tsx        # Prediction & Gemini explanation display
โ”‚   โ”œโ”€โ”€ lib/                           # API client (fetch to FastAPI backend)
โ”‚   โ”œโ”€โ”€ public/                        # Static assets (images, icons)
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”œโ”€โ”€ tailwind.config.ts
โ”‚   โ””โ”€โ”€ tsconfig.json
โ”‚
โ”œโ”€โ”€ backend/                           # FastAPI Application (Deployed to Render / Fly.io / Docker)
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ main.py                    # App factory, CORS, middleware, router mount
โ”‚   โ”‚   โ”œโ”€โ”€ config.py                  # Pydantic BaseSettings (GEMINI_API_KEY, MODEL_PATH)
โ”‚   โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ deps.py                # Shared dependencies (model loader, auth)
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ v1/
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ router.py          # API v1 aggregator
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ endpoints/
โ”‚   โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ predict.py     # POST /predict (Quality score & feature impact)
โ”‚   โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ cluster.py     # POST /cluster (Wine profile discovery)
โ”‚   โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ wines.py       # GET /wines (Dataset exploration & stats)
โ”‚   โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ explain.py     # POST /explain (Gemini sommelier reasoning)
โ”‚   โ”‚   โ”œโ”€โ”€ schemas/                   # Pydantic v2 schemas
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ wine.py                # WineFeaturesInput, WineStats
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ prediction.py          # PredictionResponse, ExplanationResponse
โ”‚   โ”‚   โ”œโ”€โ”€ services/                  # Core business logic
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ predictor.py           # Loads sklearn pipeline and computes inference
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ clusterer.py           # Unsupervised K-Means clustering service
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ gemini_sommelier.py    # Google Gemini API prompt & explanation engine
โ”‚   โ”‚   โ””โ”€โ”€ models/                    # Production model artifacts loaded by FastAPI
โ”‚   โ”‚       โ”œโ”€โ”€ quality_regressor.joblib
โ”‚   โ”‚       โ””โ”€โ”€ wine_clusters.joblib
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ Dockerfile                     # Lightweight FastAPI container for deployment
โ”‚   โ””โ”€โ”€ .dockerignore
โ”‚
โ”œโ”€โ”€ ml/                                # Offline ML Training & Research
โ”‚   โ”œโ”€โ”€ notebooks/                     # Exploratory & Prototyping
โ”‚   โ”‚   โ”œโ”€โ”€ 01_eda.ipynb               # Feature distributions & correlations
โ”‚   โ”‚   โ”œโ”€โ”€ 02_regression.ipynb        # Quality prediction experiments
โ”‚   โ”‚   โ””โ”€โ”€ 03_clustering.ipynb        # K-Means & PCA profiling
โ”‚   โ”œโ”€โ”€ src/                           # Reproducible pipeline code
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ data.py                    # Data loaders & validation
โ”‚   โ”‚   โ”œโ”€โ”€ features.py                # Scaling, transforms & feature engineering
โ”‚   โ”‚   โ”œโ”€โ”€ train_regression.py        # Model training script -> saves to backend/app/models/
โ”‚   โ”‚   โ”œโ”€โ”€ train_clustering.py        # Clustering script -> saves to backend/app/models/
โ”‚   โ”‚   โ””โ”€โ”€ evaluate.py                # MSE, RMSE, R2, Silhouette scores
โ”‚   โ””โ”€โ”€ configs/
โ”‚       โ””โ”€โ”€ hyperparameters.yaml       # Configurable training params
โ”‚
โ”œโ”€โ”€ data/                              # Data storage (gitignored except raw sample)
โ”‚   โ”œโ”€โ”€ raw/                           # Immutable raw data (WineQT.csv)
โ”‚   โ””โ”€โ”€ processed/                     # Cleaned / split / scaled datasets
โ”‚
โ”œโ”€โ”€ tests/                             # Automated Test Suite
โ”‚   โ”œโ”€โ”€ backend/
โ”‚   โ”‚   โ”œโ”€โ”€ test_api.py                # FastAPI TestClient endpoint tests
โ”‚   โ”‚   โ””โ”€โ”€ test_predictor.py          # Inference & Gemini mock tests
โ”‚   โ””โ”€โ”€ ml/
โ”‚       โ””โ”€โ”€ test_data_pipeline.py      # Data leakage & shape tests
โ”‚
โ”œโ”€โ”€ .github/                           # CI/CD Workflows
โ”‚   โ””โ”€โ”€ workflows/
โ”‚       โ”œโ”€โ”€ test.yml                   # Linting & unit tests on PR
โ”‚       โ””โ”€โ”€ deploy.yml                 # Automated deployment
โ”‚
โ”œโ”€โ”€ .env.example                       # Documented environment variables
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ docker-compose.yml                 # Orchestrates Frontend + Backend locally
โ”œโ”€โ”€ pyproject.toml                     # Single unified dependency management with uv
โ””โ”€โ”€ README.md

๐Ÿ“Š Dataset

VinoLens uses the Wine Quality dataset containing physicochemical measurements of wine along with a quality score.

Input Features

The model can use features such as:

Feature Description
fixed acidity Fixed acids in the wine
volatile acidity Volatile acidity
citric acid Citric acid concentration
residual sugar Remaining sugar
chlorides Salt concentration
free sulfur dioxide Free sulfur dioxide
total sulfur dioxide Total sulfur dioxide
density Density of the wine
pH Acidity level
sulphates Sulphate concentration
alcohol Alcohol percentage

Target

quality

The quality score is an integer rating assigned to each wine.


๐Ÿค– Machine Learning

VinoLens explores the dataset through multiple machine learning approaches.

Supervised Learning

The initial model treats wine quality as a regression problem:

Wine Chemistry
      โ”‚
      โ–ผ
Machine Learning Model
      โ”‚
      โ–ผ
Predicted Quality

Example:

Input โ†’ Wine chemical properties

Output โ†’ 7.2 / 10

Future versions can also treat the problem as classification:

quality >= 7 โ†’ Good
quality < 7  โ†’ Not Good

๐Ÿ”ฌ Unsupervised Learning

VinoLens also explores the dataset without using the quality label.

K-Means clustering can identify groups of wines with similar chemical characteristics.

Wine Data
    โ”‚
    โ–ผ
K-Means
    โ”‚
    โ”œโ”€โ”€ Cluster 1
    โ”œโ”€โ”€ Cluster 2
    โ””โ”€โ”€ Cluster 3

This allows VinoLens to answer questions such as:

"What types of wines naturally occur in this dataset?"


๐Ÿง  Gemini Integration

Google Gemini is used as an explanation layer, rather than replacing the machine learning model.

Wine Features
      โ”‚
      โ–ผ
ML Model
      โ”‚
      โ”œโ”€โ”€ Prediction
      โ”œโ”€โ”€ Feature influence
      โ””โ”€โ”€ Cluster
             โ”‚
             โ–ผ
          Gemini
             โ”‚
             โ–ผ
     Human-readable explanation

This separation keeps the ML prediction deterministic and allows Gemini to focus on communicating the results.


๐Ÿš€ Development Roadmap

Phase 1 โ€” Data Exploration

  • Obtain Wine Quality dataset
  • Load dataset with Pandas
  • Explore statistics
  • Check missing values
  • Visualize distributions
  • Analyze feature correlations

Phase 2 โ€” First ML Model

  • Prepare features and target
  • Train/test split
  • Implement linear regression
  • Evaluate MSE
  • Evaluate RMSE
  • Evaluate Rยฒ
  • Experiment with different features

Phase 3 โ€” Advanced ML

  • Try additional regression models
  • Compare model performance
  • Implement classification
  • Implement K-Means clustering
  • Investigate feature importance
  • Improve preprocessing

Phase 4 โ€” FastAPI

  • Create FastAPI application
  • Create /predict endpoint
  • Create /clusters endpoint
  • Create /statistics endpoint
  • Load trained ML models
  • Add request validation

Phase 5 โ€” Next.js

  • Build landing page
  • Create wine analysis form
  • Build prediction dashboard
  • Add interactive charts
  • Build wine explorer
  • Add clustering visualization
  • Add responsive design

Phase 6 โ€” Gemini

  • Integrate Gemini API
  • Generate prediction explanations
  • Explain influential features
  • Generate wine profile summaries

Phase 7 โ€” Production

  • Dockerize application
  • Add environment configuration
  • Add automated tests
  • Deploy frontend
  • Deploy backend
  • Document API
  • Add CI/CD

๐ŸŽฏ Example User Flow

1. User opens VinoLens
             โ†“
2. Selects "Analyze Wine"
             โ†“
3. Enters wine chemistry
             โ†“
4. FastAPI receives request
             โ†“
5. ML model generates prediction
             โ†“
6. Model determines wine profile
             โ†“
7. Gemini explains the result
             โ†“
8. User sees:
   
   Quality: 7.2 / 10
   Profile: High-Alcohol Balanced
   
   + Positive factors
   - Negative factors
   ๐Ÿ’ก AI explanation

๐Ÿ”ฎ Future Ideas

Potential future improvements include:

  • Wine recommendation system
  • Similar-wine search
  • "Find wines similar to this one"
  • User accounts and saved analyses
  • Prediction history
  • Wine comparison
  • Interactive what-if analysis
  • SHAP-based model explanations
  • Experiment tracking
  • Model versioning
  • Additional wine datasets
  • Red vs. white wine analysis
  • Personalized wine recommendations

โš ๏ธ Disclaimer

VinoLens is an educational machine learning project.

The predictions represent patterns learned from the dataset and should not be interpreted as professional wine certification, laboratory analysis, or expert sommelier judgment.


๐Ÿ“š Learning Goals

This project is designed to demonstrate practical understanding of:

  • Supervised learning
  • Regression
  • Classification
  • Unsupervised learning
  • Clustering
  • Feature engineering
  • Model evaluation
  • Data visualization
  • REST APIs
  • Full-stack development
  • Generative AI integration
  • ML model deployment

๐Ÿ‘จโ€๐Ÿ’ป Project Status

๐Ÿšง Currently in development

The project is being developed incrementally alongside the study of machine learning concepts.

Current focus

Data exploration โ†’ Linear Regression โ†’ Model Evaluation


๐Ÿ“„ License

This project is intended for educational and portfolio purposes.

About

๐Ÿท An AI-powered wine intelligence platform that predicts wine quality using machine learning, discovers wine profiles via clustering, and explains chemical influences with Google Gemini. Built with Next.js, FastAPI, and Scikit-Learn.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages