Spaces:
Sleeping
Sleeping
| 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:** | |
| ```json | |
| { | |
| "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 | |
| ```bash | |
| # 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 | |