chainforecast / README.md
Lamaq's picture
Initial deployment setup
05eb72b
metadata
title: ChainForecast CRM
emoji: πŸ”—
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit

πŸ”— ChainForecast CRM

AI-Powered Sales Forecasting + Customer Segmentation with Blockchain Logging

This Space provides a unified API for:

  • Sales Forecasting using Random Forest ML models
  • Customer Segmentation (RFM Analysis + K-Means Clustering)
  • Blockchain Logging - All forecasts are immutably logged on a private Ethereum testnet (Ganache)

πŸš€ Features

  • CSV File Upload β†’ Automatic column detection (dates, sales, customer IDs)
  • 28-Day Sales Forecast with historical trend analysis
  • Customer Segmentation into VIP, Regular, and At-Risk groups
  • AI-Generated Recommendations (powered by Groq/LangChain)
  • Blockchain Audit Trail - Every forecast is recorded on-chain with a transaction hash

πŸ“‘ API Endpoints

POST /analyze

Upload a CSV file to run the full forecasting + CRM pipeline.

Parameters:

  • file (required): CSV file
  • date_col (optional): Name of date column
  • sales_col (optional): Name of sales/revenue column
  • id_col (optional): Name of customer ID column
  • category_col (optional): Name of product category column

Response:

{
  "meta": {...},
  "forecast": {
    "status": "success",
    "metrics": {...},
    "blockchain_status": "logged",
    "transaction_hash": "0xabc..."
  },
  "segmentation": {...}
}

POST /log-forecast

Manually log a forecast to the blockchain (accepts structured JSON payload).

GET /latest-on-chain

Retrieve the most recent forecast logged on the blockchain.


βš™οΈ Configuration

This Space requires the following environment variables (set in Settings β†’ Repository Secrets):

Variable Description Example
BLOCKCHAIN_URL URL of the Ganache blockchain node http://34.70.216.31:8545
GROQ_API_KEY (Optional) API key for Groq LLM recommendations gsk_...

πŸ› οΈ Architecture

User β†’ FastAPI (Hugging Face Space)
          ↓
    [Forecast Engine] β†’ Random Forest ML
    [CRM Engine] β†’ RFM + Clustering + AI Recs
          ↓
    [Blockchain Service] β†’ Ganache (GCP VM)
          ↓
    Smart Contract (Solidity) stores:
      - Domain/Dataset Name
      - Predicted Value (in cents)
      - Merkle Root (data hash)
      - Timestamp

πŸ“¦ Local Development

# Install dependencies
pip install -r requirements.txt

# Set environment variables
export BLOCKCHAIN_URL="http://34.70.216.31:8545"
export GROQ_API_KEY="your_key_here"

# Deploy the smart contract (one-time setup)
python app/blockchain/deploy.py

# Run the API
uvicorn app.api.main:app --reload

πŸ“„ License

MIT


Built with: FastAPI β€’ Scikit-Learn β€’ Web3.py β€’ Solidity β€’ LangChain β€’ Groq