Views
No views yet
TradeNest AI
│
├── api/
│ └── routes.py # API endpoints
├── core/
├── models/
├── preprocessing/
├── schemas/
│ ├── request_schemas.py # Request validation
│ └── response_schemas.py # Response models
├── services/
│ ├── prediction_service.py # ML predictions
│ ├── explanation_service.py # Business explanations
│ ├── visualization_service.py # Chart orchestration
│ └── web_data_service.py # Optional web/data enrichment
├── visualizations/
│ ├── line_charts.py # Line chart generation
│ ├── bar_charts.py # Bar chart generation
│ └── pie_charts.py # Pie chart generation
├── storage/
├── utils/
└── main.py # FastAPI applicationAgg backend for server environments1# Install dependencies
2pip install -r requirements.txt1# Start the server
2python main.py
3
4# Or using uvicorn directly
5uvicorn main:app --host 0.0.0.0 --port 80001# Run both backend and beautiful frontend
2python run_platform.pyhttp://localhost:8000http://localhost:7860http://localhost:8000/docshttp://localhost:8000/docshttp://localhost:8000/redoc/api/predict/demand1{
2 "historical_values": [100, 120, 110, 130, 125],
3 "historical_dates": ["2024-01", "2024-02", "2024-03", "2024-04", "2024-05"],
4 "periods_ahead": 4,
5 "method": "moving_average"
6}1{
2 "insight_summary": "Strong growth expected: 15.2% increase in average demand",
3 "explanation": "The line chart shows...",
4 "predictions": {
5 "values": [135.5, 138.2, 140.9, 143.6],
6 "range": "135.50 - 143.60"
7 },
8 "confidence_level": "High",
9 "visuals": {
10 "line_chart": "base64_encoded_image...",
11 "pie_chart": "base64_encoded_image..."
12 }
13}/api/predict/price1{
2 "prices": [10.0, 12.0, 11.0, 13.0, 12.5],
3 "volumes": [1000, 800, 900, 700, 850],
4 "target": "revenue"
5}1{
2 "insight_summary": "Optimal price identified: $12.00 for maximum revenue",
3 "explanation": "The line chart displays the relationship...",
4 "predictions": {
5 "optimal_price": 12.0,
6 "expected_volume": 800,
7 "expected_revenue": 9600.0,
8 "price_elasticity": 0.75,
9 "recommendation": "Set price at $12.00 for maximum revenue"
10 },
11 "confidence_level": "Medium",
12 "visuals": {
13 "line_chart": "base64_encoded_image...",
14 "pie_chart": "base64_encoded_image..."
15 }
16}/api/analyze/trend1{
2 "values": [5000, 5500, 5200, 6000, 5800, 6200],
3 "periods": ["Q1", "Q2", "Q3", "Q4", "Q5", "Q6"]
4}1{
2 "insight_summary": "Strong upward trend: 12.5% growth detected in sales performance",
3 "explanation": "The trend chart provides a clear visual representation...",
4 "predictions": {
5 "trend_direction": "increasing",
6 "growth_rate": 24.0,
7 "trend_percentage": 12.5,
8 "average": 5616.67,
9 "volatility": 0.08,
10 "range": "5000.00 - 6200.00"
11 },
12 "confidence_level": "High",
13 "visuals": {
14 "line_chart": "base64_encoded_image...",
15 "pie_chart": "base64_encoded_image..."
16 }
17}/api/country/info1{
2 "country_code": "TZ"
3}/api/country/search1{
2 "name": "Tanzania"
3}/api/trade/data1{
2 "reporter_code": "842",
3 "partner_code": "156",
4 "year": "2023",
5 "commodity_code": "TOTAL",
6 "trade_flow": "export"
7}/api/imf/indicator1{
2 "country_code": "US",
3 "indicator": "NGDP_RPCH",
4 "dataset": "IFS",
5 "start_year": "2020",
6 "end_year": "2024"
7}/api/forecast/business1{
2 "business_type": "retail",
3 "country_code": "US",
4 "historical_revenue": [100000, 120000, 115000, 130000, 140000, 135000],
5 "forecast_horizon_months": 12,
6 "include_external_factors": true
7}1{
2 "business_type": "retail",
3 "country_code": "US",
4 "country_name": "United States",
5 "forecast_horizon_months": 12,
6 "forecast": {
7 "values": [145000, 150000, 155000, ...],
8 "growth_rates": [5.2, 3.4, 3.3, ...],
9 "cumulative_growth": 25.8
10 },
11 "insights": [
12 "🚀 Strong growth expected: Average monthly growth of 4.2%",
13 "🌍 Favorable macroeconomic environment: Country GDP growing at 2.1%"
14 ],
15 "risk_assessment": [
16 "Moderate inflation creating cost pressures"
17 ],
18 "opportunities": [
19 "E-commerce adoption still growing in emerging markets"
20 ]
21}1{
2 "insight_summary": "Short business conclusion",
3 "explanation": "Clear explanation referencing visible charts",
4 "predictions": {
5 "values": [...],
6 "range": "numeric range"
7 },
8 "confidence_level": "High | Medium | Low",
9 "visuals": {
10 "line_chart": "base64_encoded_image",
11 "pie_chart": "base64_encoded_image"
12 }
13}"The line chart shows consistent week-over-week growth, while the pie chart confirms that 60% of sales come from peak weeks."
line_charts.py, bar_charts.py, or pie_charts.py)VisualizationService1import requests
2import json
3import base64
4from PIL import Image
5from io import BytesIO
6
7# Make request
8response = requests.post(
9 "http://localhost:8000/api/predict/demand",
10 json={
11 "historical_values": [100, 120, 110, 130, 125],
12 "periods_ahead": 4
13 }
14)
15
16data = response.json()
17
18# Decode and save charts
19line_chart = base64.b64decode(data['visuals']['line_chart'])
20pie_chart = base64.b64decode(data['visuals']['pie_chart'])
21
22# Save images
23with open('line_chart.png', 'wb') as f:
24 f.write(line_chart)
25
26with open('pie_chart.png', 'wb') as f:
27 f.write(pie_chart)
28
29print(data['insight_summary'])
30print(data['explanation'])1curl -X POST "http://localhost:8000/api/predict/demand" \
2 -H "Content-Type: application/json" \
3 -d '{
4 "historical_values": [100, 120, 110, 130, 125],
5 "periods_ahead": 4
6 }'Input Data
↓
Validation (Pydantic)
↓
Prediction Service
↓
Visualization Service
↓
Chart Generation (Matplotlib)
↓
Base64 Encoding
↓
Explanation Service
↓
JSON Response (with visuals)fastapi: Web frameworkuvicorn: ASGI serverpydantic: Data validationmatplotlib: Visualizationnumpy: Numerical operationsgradio: Beautiful web interfacerequests: API clientpandas: Data manipulation