File size: 5,733 Bytes
fc8c40e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# SAP Finance Dashboard with RPT-1-OSS Model

A comprehensive financial dashboard application built with Gradio that integrates the SAP-RPT-1-OSS model for predictive analysis on SAP finance datasets. Features include synthetic data generation, interactive visualizations, OData connectivity, AI-powered insights, and a playground for training custom models.

## Features

- **Multiple Synthetic SAP Finance Datasets**: General Ledger accounts, Financial Statements (P&L, Balance Sheet), and Sales Orders
- **Data Upload**: Upload custom CSV, Parquet, or JSON datasets for analysis
- **Interactive Visualizations**: Financial charts and graphs using Plotly
- **SAP-RPT-1-OSS Model Integration**: AI-powered predictions and analysis
- **Live OData Connection**: Connect to SAP systems to fetch real-time sales order data
- **Playground Tab**: Upload datasets, configure model parameters, train, and download predictions
- **Modern UI**: Built with Gradio, a Python-based web framework

## Installation

### Prerequisites

- Python 3.11 or higher
- Hugging Face account (for model access)
- SAP OData credentials (optional, for live data connection)

### Setup Steps

1. **Clone the repository**:
   ```bash
   git clone <repository-url>
   cd SAP-RPT-1-OSS-App
   ```

2. **Create a virtual environment**:
   ```bash
   python -m venv venv
   source venv/bin/activate  # On Windows: venv\Scripts\activate
   ```

3. **Install dependencies**:
   ```bash
   pip install -r requirements.txt
   ```

4. **Install SAP-RPT-OSS package**:
   ```bash
   pip install git+https://github.com/SAP-samples/sap-rpt-1-oss
   ```

5. **Set up environment variables**:
   - Copy `.env.example` to `.env`
   - Fill in your SAP OData credentials
   - Add your Hugging Face token for model access

6. **Authenticate with Hugging Face**:
   ```bash
   pip install huggingface_hub
   huggingface-cli login
   ```
   Or set the `HUGGINGFACE_TOKEN` in your `.env` file.

7. **Generate synthetic data** (optional, if not already generated):
   ```bash
   python -c "from utils.data_generator import generate_all_datasets; generate_all_datasets()"
   ```

## Usage

### Running the Application

Start the Gradio application:

```bash
python app_gradio.py
```

The application will be available at `http://localhost:7862` (default Gradio port).

### Application Tabs

1. **Dashboard**: Overview with key financial metrics and visualizations
2. **Data Explorer**: Browse and filter datasets (GL, Financial Statements, Sales Orders)
3. **Upload**: Upload custom CSV datasets for analysis
4. **Predictions**: Use SAP-RPT-1-OSS model for predictions and analysis with pre-configured scenarios
5. **OData**: Connect to SAP OData services and fetch live data
6. **Playground**: Upload datasets, configure model parameters (task type, target column, test split, context size, bagging, GPU), train models, and download predictions

## SAP OData Connection Setup

1. Set the following environment variables in your `.env` file:
   - `SAP_USERNAME`: Your SAP username
   - `SAP_PASSWORD`: Your SAP password
   - `SAP_SERVER`: SAP server URL (default: `https://sapes5.sapdevcenter.com/`)
   - `SAP_CLIENT`: SAP client number (default: `002`)

2. The OData connector uses the base URL:
   `https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC`

3. Available endpoints:
   - Sales Orders: `SalesOrderSet`
   - Products: `ProductSet`
   - Line Items: `SalesOrderLineItemSet`
   - Business Partners: `BusinessPartnerSet`

## Model Configuration

The SAP-RPT-1-OSS model supports both classification and regression tasks. For best performance:

- **Recommended**: GPU with at least 80 GB memory, context size 8192, bagging factor 8
- **Lightweight**: CPU with context size 2048, bagging factor 1

The application automatically detects available resources and adjusts settings accordingly.

## Deployment

### GitHub Pages

Since Gradio requires a Python backend, GitHub Pages deployment requires alternative approaches:

1. **GitHub Actions**: Set up a workflow to run the Gradio app as a service
2. **Alternative Hosting**: Deploy to platforms that support Python web apps:
   - Hugging Face Spaces (recommended for Gradio apps)
   - Streamlit Cloud
   - Heroku
   - Railway
   - Render

### Deploy to Hugging Face Spaces

The easiest way to deploy this Gradio app is using Hugging Face Spaces:

1. Create a new Space on [Hugging Face Spaces](https://huggingface.co/spaces)
2. Select "Gradio" as the SDK
3. Push this repository to your Space
4. Add your `HUGGINGFACE_TOKEN` as a secret in Space settings
5. The app will automatically deploy

See `.github/workflows/deploy.yml` for deployment configuration examples.

## Project Structure

```
SAP-RPT-1-OSS-App/
β”œβ”€β”€ app_gradio.py         # Main Gradio application
β”œβ”€β”€ models/
β”‚   └── rpt_model.py      # SAP-RPT-1-OSS model wrapper
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ synthetic_gl_accounts.csv
β”‚   β”œβ”€β”€ synthetic_financial_statements.csv
β”‚   └── synthetic_sales_orders.csv
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ data_generator.py # Generate synthetic SAP finance data
β”‚   β”œβ”€β”€ visualizations.py # Chart generation functions
β”‚   β”œβ”€β”€ odata_connector.py # OData connection utilities
β”‚   └── playground.py     # Playground utilities for model training
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
└── .env.example
```

## License

This project is licensed under the Apache Software License, version 2.0.

## Support

For issues or questions, please create an issue in this repository.

## Acknowledgments

- SAP-RPT-1-OSS model: [Hugging Face](https://huggingface.co/SAP/sap-rpt-1-oss)
- Gradio framework: [Gradio Documentation](https://www.gradio.app/docs/)