File size: 10,953 Bytes
25c1123
5269c7e
 
25c1123
 
 
 
 
 
 
 
eb85a42
5269c7e
eb85a42
5269c7e
 
 
eb85a42
 
 
 
 
 
5269c7e
 
 
 
 
 
 
 
 
eb85a42
5269c7e
eb85a42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5269c7e
 
 
eb85a42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5269c7e
 
eb85a42
5269c7e
 
eb85a42
 
 
5269c7e
 
 
eb85a42
 
 
 
 
 
 
 
 
 
 
 
 
 
5269c7e
eb85a42
 
 
5269c7e
eb85a42
 
 
 
 
 
 
 
5269c7e
 
eb85a42
 
 
 
5269c7e
 
eb85a42
5269c7e
 
eb85a42
 
 
 
5269c7e
 
eb85a42
5269c7e
 
eb85a42
 
 
 
5269c7e
 
 
 
eb85a42
5269c7e
eb85a42
 
 
 
 
 
 
 
5269c7e
 
eb85a42
5269c7e
eb85a42
 
5269c7e
 
eb85a42
5269c7e
eb85a42
 
5269c7e
 
eb85a42
 
 
 
 
 
 
 
5269c7e
 
 
eb85a42
 
 
 
5269c7e
eb85a42
5269c7e
eb85a42
 
 
 
5269c7e
eb85a42
5269c7e
eb85a42
 
 
5269c7e
eb85a42
5269c7e
eb85a42
 
 
 
5269c7e
eb85a42
5269c7e
 
 
eb85a42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5269c7e
 
 
eb85a42
 
 
 
 
 
5269c7e
 
 
 
 
eb85a42
5269c7e
eb85a42
 
 
 
5269c7e
eb85a42
5269c7e
eb85a42
 
5269c7e
eb85a42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5269c7e
 
 
eb85a42
 
 
 
5269c7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eb85a42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5269c7e
 
 
eb85a42
 
 
5269c7e
eb85a42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5269c7e
eb85a42
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
---
title: AI Data Analysis with SmoLagent
emoji: πŸ€–
colorFrom: purple
colorTo: green
sdk: gradio
sdk_version: 5.37.0
app_file: app.py
pinned: false
---

# Singtel Use Case 1: OutSystems Log Analysis with SmoLagent AI

An intelligent data analysis application specifically designed for analyzing OutSystems application logs using SmoLagent AI framework. This project focuses on extracting insights from 6 months of OutSystems log data to identify patterns, errors, and optimization opportunities.

## Features

πŸ€– **AI-Powered Log Analysis**: Uses SmoLagent CodeAgent with DuckDuckGo search for intelligent log analysis  
πŸ“Š **Interactive Visualizations**: Correlation heatmaps, distribution plots, and error pattern analysis  
πŸ“ˆ **OutSystems-Specific Analytics**: Log level analysis, error module tracking, and performance insights  
🌐 **Multiple Interfaces**: Command-line, interactive menu, and web-based Gradio interface  
πŸ”§ **Flexible AI Models**: OpenAI, Ollama (local), and HuggingFace Transformers support  
🚨 **Error Pattern Detection**: Automated identification of error trends and module issues

## Quick Start

1. **Install Dependencies**

   ```bash
   pip install -r requirements.txt
   ```

2. **Configure Your AI Model** (Choose one option)

   **Option A: Free Local AI (Ollama)**

   ```bash
   # Install Ollama from https://ollama.ai/
   ollama pull llama2
   ollama serve
   python setup_ollama.py  # Test setup
   ```

   **Option B: OpenAI API**

   ```bash
   set OPENAI_API_KEY=your_api_key_here
   ```

   **Option C: Use without AI (basic analysis only)**

   ```bash
   # No setup needed - basic data analysis works without AI
   ```

3. **Run the Application**

   **Main Interactive Analysis:**

   ```bash
   python upload.py
   # Choose mode 2 for enhanced AI features
   ```

   **Quick Demo:**

   ```bash
   python quick_ai_demo.py
   ```

   **Web Interface:**

   ```bash
   python app.py
   # Open browser to displayed URL
   ```

4. **Load Your OutSystems Data**
   - Update file path in `upload.py` or `config.py`
   - Default: `outsystems_sample_logs_6months.csv`

## Files Overview

### Main Scripts

- **`upload.py`** - Main data analysis script with interactive menu and AI integration
- **`app.py`** - Gradio web interface for browser-based analysis
- **`fixed_upload.py`** - Streamlined working version with automatic model fallbacks

### Setup & Testing Scripts

- **`setup_ollama.py`** - Ollama local AI setup helper
- **`setup_free_ai.py`** - Free AI models configuration
- **`test_smolagent.py`** - SmoLagent functionality testing
- **`quick_ai_demo.py`** - Quick demo without large downloads

### Configuration

- **`config.py`** - Model and data source configuration
- **`requirements.txt`** - Python dependencies
- **`ENHANCEMENT_GUIDE.md`** - Enhancement documentation

### Analysis Examples

- **`analyze.py`** - Programmatic analysis examples
- **`demo_enhanced.py`** - Enhanced features demonstration

## Model Configuration Options

### 1. Ollama (Recommended - Free & Local)

```python
from smolagents import CodeAgent, DuckDuckGoSearchTool, OllamaModel

model = OllamaModel(model_id="llama2", base_url="http://localhost:11434")
agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
```

### 2. OpenAI Models

```python
from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIModel

model = OpenAIModel(model_id="gpt-3.5-turbo")
agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
```

### 3. HuggingFace Transformers

```python
from smolagents import CodeAgent, DuckDuckGoSearchTool, TransformersModel

model = TransformersModel(model_id="microsoft/DialoGPT-small")
agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
```

## Usage Examples

### 1. Interactive Analysis (Recommended)

```bash
python upload.py
# Choose mode 2 for enhanced AI features
# Navigate through interactive menu:
# 1. Load and explore data
# 2. Create visualizations
# 3. Analyze data quality
# 4. AI-powered analysis
```

### 2. Quick Demo

```bash
python quick_ai_demo.py  # Basic analysis without heavy downloads
```

### 3. Web Interface

```bash
python app.py           # Start Gradio web interface
```

### 4. Automated Setup Testing

```bash
python test_smolagent.py    # Test SmoLagent setup
python setup_free_ai.py    # Configure free AI models
```

## OutSystems Log Analysis Features

### 1. Data Overview Tab

- **Dataset Structure**: 5000+ log entries with 9 columns
- **Column Analysis**: Timestamp, LogLevel, Module, User, Message, RequestUrl, SessionId, ErrorId, StackTrace
- **Missing Value Detection**: Identifies incomplete error records (ErrorId/StackTrace gaps)
- **Memory Usage**: Optimized for large log files

### 2. Log-Specific Analytics

- **Error Rate Analysis**: Info vs Error log distribution
- **Module Error Tracking**: Top error-generating modules identification
- **Session Analysis**: User session patterns and error correlation
- **Timestamp Patterns**: Time-based error trends and peak periods

### 3. Visualizations

- **Error Distribution Plots**: Visual error patterns across modules
- **Correlation Analysis**: Relationships between log parameters
- **Time Series Analysis**: Error trends over 6-month period

### 4. AI-Powered OutSystems Insights

- **Error Pattern Recognition**: AI identifies recurring error types
- **Module Risk Assessment**: Predicts which modules need attention
- **Performance Optimization**: Suggests improvements based on log patterns
- **Anomaly Detection**: Unusual log patterns and potential issues

## Example AI Queries for OutSystems Logs

Ask SmoLagent questions like:

**Error Analysis:**

- "What are the most common error types in these OutSystems logs?"
- "Which modules generate the most errors?"
- "Find patterns in error messages"
- "Identify critical errors that need immediate attention"

**Performance Insights:**

- "Analyze user session patterns for performance issues"
- "Find modules with the highest error rates"
- "Detect unusual activity patterns"
- "Suggest modules that need code review"

**Trend Analysis:**

- "Show error trends over the 6-month period"
- "Find seasonal patterns in system usage"
- "Identify peak error periods"
- "Correlate errors with specific time periods"

**Data Quality:**

- "Check for incomplete error records"
- "Find missing StackTrace patterns"
- "Validate log data completeness"
- "Suggest data quality improvements"

## Data Requirements

- **Format**: CSV format with OutSystems log structure
- **Expected Columns**: Timestamp, LogLevel, Module, User, Message, RequestUrl, SessionId, ErrorId, StackTrace
- **Default File**: `outsystems_sample_logs_6months.csv` (6 months of sample data)
- **File Location**: Update path in `upload.py` line 11 or `config.py`
- **Size**: Optimized for datasets with 5000+ log entries
- **Encoding**: UTF-8 encoding recommended

## Troubleshooting

### Common Issues:

1. **"Module not found: smolagents"**

   ```bash
   pip install 'smolagents[transformers]'
   pip install duckduckgo-search>=3.8.0
   ```

2. **"CodeAgent requires model parameter"**

   - Run `python fixed_upload.py` for automatic model fallbacks
   - Or configure Ollama: `python setup_ollama.py`

3. **Model Download Taking Too Long**

   ```bash
   python quick_ai_demo.py  # Use without heavy downloads
   ```

4. **OutSystems CSV File Not Found**

   - Update file path in `upload.py` line 11
   - Ensure CSV file exists at specified location
   - Check file permissions

5. **Ollama Connection Error**
   ```bash
   ollama serve  # Start Ollama server
   ollama pull llama2  # Download model
   ```

### Getting Help:

- **Quick Test**: Run `python test_smolagent.py`
- **Setup Issues**: Run `python setup_free_ai.py`
- **Basic Analysis**: Use Mode 1 in `upload.py` (works without AI)
- **Check Logs**: Console output shows detailed error messages

## Advanced Usage

### Custom Analysis Functions

You can extend the application by adding custom analysis functions:

```python
def custom_analysis(df):
    # Your custom analysis logic here
    return results
```

### Adding New Visualizations

Add new plotting functions to create additional visualizations:

```python
def create_custom_plot(df):
    # Your plotting logic here
    return plot_image
```

## Dependencies

**Core AI Framework:**

- `smolagents>=0.3.0` - AI agent framework with CodeAgent
- `duckduckgo-search>=3.8.0` - Web search capabilities

**Data Analysis Stack:**

- `pandas>=2.0.0` - Data manipulation and analysis
- `numpy>=1.24.0` - Numerical computing
- `scikit-learn>=1.3.0` - Machine learning tools

**Visualization:**

- `matplotlib>=3.7.0` - Basic plotting
- `seaborn>=0.12.0` - Statistical visualizations
- `plotly>=5.15.0` - Interactive visualizations

**AI Models:**

- `transformers>=4.30.0` - HuggingFace transformers
- `torch>=2.0.0` - PyTorch for model inference
- `huggingface_hub>=0.16.0` - Model hub access

**Web Interface:**

- `gradio>=5.37.0` - Web UI framework
- `Pillow>=10.0.0` - Image processing

**HTTP & Utilities:**

- `requests>=2.31.0` - HTTP requests

## Project Structure

```
Singtel_Use_Case1/
β”œβ”€β”€ πŸ“ Main Scripts
β”‚   β”œβ”€β”€ upload.py              # Primary interactive analysis tool
β”‚   β”œβ”€β”€ app.py                 # Gradio web interface
β”‚   └── fixed_upload.py        # Streamlined working version
β”‚
β”œβ”€β”€ πŸ“ Setup & Testing
β”‚   β”œβ”€β”€ setup_ollama.py        # Ollama configuration helper
β”‚   β”œβ”€β”€ setup_free_ai.py       # Free AI models setup
β”‚   β”œβ”€β”€ test_smolagent.py      # SmoLagent testing
β”‚   └── quick_ai_demo.py       # Quick demo script
β”‚
β”œβ”€β”€ πŸ“ Configuration
β”‚   β”œβ”€β”€ config.py              # Model and data configuration
β”‚   β”œβ”€β”€ requirements.txt       # Python dependencies
β”‚   └── ENHANCEMENT_GUIDE.md   # Development guide
β”‚
β”œβ”€β”€ πŸ“ Analysis Examples
β”‚   β”œβ”€β”€ analyze.py             # Programmatic analysis
β”‚   └── demo_enhanced.py       # Feature demonstrations
β”‚
└── πŸ“ Data (Expected)
    └── outsystems_sample_logs_6months.csv
```

## License

This project is developed for Singtel Use Case 1 analysis and is available under the MIT License.

---

## Quick Commands Reference

```bash
# πŸš€ Quick Start
python upload.py              # Main interactive tool
python quick_ai_demo.py       # Fast demo without downloads
python app.py                 # Web interface

# πŸ”§ Setup & Testing
python setup_ollama.py        # Configure local AI
python test_smolagent.py      # Test AI setup
python setup_free_ai.py       # Free models setup

# πŸ“Š Analysis Options
# Mode 1: Basic data exploration (no AI required)
# Mode 2: Full AI-powered analysis with interactive menu
```

**For Singtel Use Case 1**: This tool specifically analyzes OutSystems log data to identify error patterns, module performance, and system optimization opportunities using AI-powered insights.