Spaces:
Configuration error
Configuration error
<<<<<<< HEAD # castor-price-api
π¦ Castor Price Forecasting - Complete Package
π― Project Summary
This is a Production-Ready API for Castor Price Forecasting using ARIMA and LSTM models.
π Project Structure
D:\models\arima\
βββ π§ API Files
β βββ api_production.py β Main production API server
β βββ api_server.py (Alternative API)
β βββ test_api_production.py β API test suite
β βββ generate_api_key.py (Key generator)
β βββ api_keys.json π Generated API keys
β
βββ π Data & Models
β βββ daily_oilseeds_full_ml_dataset_2015_01_01_2025_12_02.csv
β βββ forecasting_analysis.py (Forecasting pipeline)
β βββ Castor_Price_Forecast_Chart_Custom_Range.html (Visualization)
β βββ Castor_Price_Forecast_Chart.html
β
βββ π Documentation
β βββ β API_READY_FOR_DEPLOYMENT.md β START HERE
β βββ DEPLOYMENT_GUIDE.md (Deployment instructions)
β βββ API_CREDENTIALS.md (Your credentials)
β βββ API_README.md (API guide)
β βββ README.md (This file)
β
βββ π Virtual Environments
β βββ venv_short/ β Ready to use (shorter path)
β βββ .venv/ (Alternative)
β
βββ π¨ Visualizations
βββ *.html files (Interactive Plotly charts)
π Quick Start (5 Minutes)
Step 1: Start the API Server
cd D:\models\arima
D:\models\arima\venv_short\Scripts\python.exe api_production.py
Server runs on: http://127.0.0.1:5000
Step 2: Your API Key
castor_d167aa169b5e4219a66779e45fbaaefe
Step 3: Test the API
# Health check
curl http://127.0.0.1:5000/api/health
# Get forecast
curl -X POST http://127.0.0.1:5000/api/forecast \
-H "X-API-Key: castor_d167aa169b5e4219a66779e45fbaaefe" \
-H "Content-Type: application/json" \
-d '{"product":"Castor","start_date":"2025-12-01","end_date":"2026-01-31"}'
π File Descriptions
API Files
| File | Purpose | Status |
|---|---|---|
api_production.py |
Production-ready API server | β Active |
api_keys.json |
Stores generated API keys | β Ready |
test_api_production.py |
Comprehensive test suite | β Ready |
Data & Analysis
| File | Purpose |
|---|---|
daily_oilseeds_full_ml_dataset_2015_01_01_2025_12_02.csv |
Historical price data |
forecasting_analysis.py |
ARIMA/LSTM model training |
*.html |
Interactive forecast visualizations |
Documentation
| File | Purpose |
|---|---|
API_READY_FOR_DEPLOYMENT.md |
β START HERE - Complete API reference |
DEPLOYMENT_GUIDE.md |
Docker, Gunicorn, and production setup |
API_CREDENTIALS.md |
Your credentials and test examples |
π API Key
Your Generated Key:
castor_d167aa169b5e4219a66779e45fbaaefe
Use in header:
X-API-Key: castor_d167aa169b5e4219a66779e45fbaaefe
π‘ Available Endpoints
Public Endpoints (No Auth)
GET /- API documentationGET /api/health- Health checkPOST /api/generate-key- Generate new key
Protected Endpoints (Auth Required)
POST /api/forecast- Get both ARIMA and LSTM forecastPOST /api/forecast/arima- Get ARIMA forecast onlyPOST /api/forecast/lstm- Get LSTM forecast only
π» Integration Examples
JavaScript
const response = await fetch('http://127.0.0.1:5000/api/forecast', {
method: 'POST',
headers: {
'X-API-Key': 'castor_d167aa169b5e4219a66779e45fbaaefe',
'Content-Type': 'application/json'
},
body: JSON.stringify({
product: 'Castor',
start_date: '2025-12-01',
end_date: '2026-01-31'
})
});
const forecast = await response.json();
Python
import requests
response = requests.post(
'http://127.0.0.1:5000/api/forecast',
headers={'X-API-Key': 'castor_d167aa169b5e4219a66779e45fbaaefe'},
json={'product': 'Castor', 'start_date': '2025-12-01', 'end_date': '2026-01-31'}
)
forecast = response.json()
π³ Docker Deployment
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY api_production.py .
COPY daily_oilseeds_full_ml_dataset_2015_01_01_2025_12_02.csv .
COPY api_keys.json .
EXPOSE 5000
CMD ["python", "api_production.py"]
Run:
docker build -t castor-api .
docker run -p 5000:5000 castor-api
π Forecast Model Details
| Model | Description | Trend |
|---|---|---|
| ARIMA | AutoRegressive Integrated Moving Average | Flat prediction |
| LSTM | Long Short-Term Memory Neural Network | Captures trends |
| Average | Mean of both models | Balanced forecast |
β Testing
Run the test suite:
python test_api_production.py
Expected output:
β
Health: PASSED
β
Forecast: PASSED
β
ARIMA: PASSED
β
All tests passed!
π‘οΈ Security Features
- β API key authentication
- β CORS support for web apps
- β Request tracking and logging
- β Error handling and validation
- β Rate limiting ready
π Response Format
{
"status": "success",
"product": "Castor",
"last_known_price": 3856.50,
"forecast_period": {
"start": "2025-12-01",
"end": "2026-01-31",
"days": 62
},
"forecast": [
{
"date": "2025-12-01",
"arima_price": 3856.50,
"lstm_price": 3856.54,
"average_price": 3856.52
}
],
"timestamp": "2025-12-04T23:08:39"
}
π Deployment Checklist
- Test API locally with
test_api_production.py - Verify API key generation works
- Check forecast endpoint with sample data
- Review
DEPLOYMENT_GUIDE.mdfor production setup - Choose deployment method (Docker/Gunicorn)
- Set up environment variables
- Configure HTTPS for production
- Set up monitoring and logging
- Share API credentials with app developers
- Document API usage for your team
π Support & Troubleshooting
Server won't start?
# Check Python version
python --version # Should be 3.12+
# Reinstall dependencies
pip install flask flask-cors pandas numpy scikit-learn tensorflow statsmodels
# Check if port 5000 is available
netstat -ano | findstr :5000
API key not working?
# Verify key in api_keys.json
cat api_keys.json
# Generate new key
python -c "..." # See DEPLOYMENT_GUIDE.md
Forecast data not loading?
- Ensure CSV file exists:
daily_oilseeds_full_ml_dataset_2015_01_01_2025_12_02.csv - Check file path in
api_production.py - Verify product name in CSV
π Documentation Links
- Start Here:
API_READY_FOR_DEPLOYMENT.mdβ - Deployment:
DEPLOYMENT_GUIDE.md - Credentials:
API_CREDENTIALS.md - References:
API_README.md
π― Next Steps
- β
Review
API_READY_FOR_DEPLOYMENT.md - β Test with provided examples
- β Deploy using Docker or Gunicorn
- β Share API key with app developers
- β Monitor API usage
π Project Status
β
API Server: READY
β
API Keys: GENERATED
β
Documentation: COMPLETE
β
Test Suite: READY
β
Deployment: READY
STATUS: π READY FOR PRODUCTION DEPLOYMENT
Generated: December 4, 2025 Version: 1.0.0 API Key: castor_d167aa169b5e4219a66779e45fbaaefe Server: http://127.0.0.1:5000 | http://172.16.32.97:5000
251245cf (1st commit)