cosmoruler commited on
Commit
eb85a42
Β·
1 Parent(s): c69ba8c

tried to put in agent

Browse files
Files changed (1) hide show
  1. README.md +271 -94
README.md CHANGED
@@ -9,17 +9,18 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- # AI Data Analysis with SmoLagent
13
 
14
- An intelligent data analysis application that uses SmoLagent for AI-powered insights on CSV data.
15
 
16
  ## Features
17
 
18
- πŸ€– **AI-Powered Analysis**: Uses SmoLagent for natural language queries about your data
19
- πŸ“Š **Interactive Visualizations**: Correlation heatmaps, distribution plots, and more
20
- πŸ“ˆ **Statistical Analysis**: Comprehensive statistical summaries and insights
21
- 🌐 **Web Interface**: User-friendly Gradio interface for easy interaction
22
- πŸ”§ **Flexible**: Works with various LLM models (OpenAI, local models, etc.)
 
23
 
24
  ## Quick Start
25
 
@@ -29,147 +30,253 @@ An intelligent data analysis application that uses SmoLagent for AI-powered insi
29
  pip install -r requirements.txt
30
  ```
31
 
32
- 2. **Configure Your Model** (Optional for basic features)
33
 
34
- - Edit `config.py` to set up your preferred LLM
35
- - Supported: OpenAI, Ollama, Hugging Face, and more
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  3. **Run the Application**
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  ```bash
40
  python app.py
 
41
  ```
42
 
43
- 4. **Access the Interface**
44
- - Open your browser to the displayed URL (usually http://localhost:7860)
 
45
 
46
  ## Files Overview
47
 
48
- - `app.py` - Main Gradio application with AI analysis features
49
- - `upload.py` - Data loading and exploration script
50
- - `analyze.py` - Example script showing SmoLagent usage
51
- - `config.py` - Configuration file for model setup
52
- - `requirements.txt` - Python dependencies
 
 
 
 
 
 
 
 
 
53
 
54
- ## Model Configuration
 
 
55
 
56
- ### OpenAI Models
 
 
 
 
 
 
 
57
 
58
  ```python
59
- from smolagents.models import OpenAIServerModel
60
- model = OpenAIServerModel(
61
- model_id="gpt-4",
62
- api_key="your-openai-api-key"
63
- )
64
  ```
65
 
66
- ### Local Models (Ollama)
67
 
68
  ```python
69
- from smolagents.models import LiteLLMModel
70
- model = LiteLLMModel(
71
- model_id="ollama/llama2",
72
- api_base="http://localhost:11434"
73
- )
74
  ```
75
 
76
- ### Hugging Face Models
77
 
78
  ```python
79
- from smolagents.models import HfApiModel
80
- model = HfApiModel(
81
- model_id="microsoft/DialoGPT-medium",
82
- token="your-hf-token"
83
- )
84
  ```
85
 
86
  ## Usage Examples
87
 
88
- ### Basic Data Exploration
89
 
90
- ```python
91
- python upload.py # Load and explore your CSV data
 
 
 
 
 
 
92
  ```
93
 
94
- ### Interactive Analysis
95
 
96
- ```python
97
- python app.py # Start the web interface
98
  ```
99
 
100
- ### Programmatic Analysis
101
 
102
- ```python
103
- python analyze.py # Run example analysis scripts
104
  ```
105
 
106
- ## Features Available
 
 
 
 
 
 
 
107
 
108
  ### 1. Data Overview Tab
109
 
110
- - Dataset shape and structure
111
- - Column information and data types
112
- - Missing value analysis
113
- - Memory usage statistics
114
 
115
- ### 2. Basic Statistics Tab
116
 
117
- - Descriptive statistics for all columns
118
- - Summary statistics (mean, median, std, etc.)
119
- - Data distribution insights
 
120
 
121
- ### 3. Visualizations Tab
122
 
123
- - **Correlation Heatmap**: Shows relationships between numerical variables
124
- - **Distribution Plots**: Histograms for all numerical columns
 
125
 
126
- ### 4. AI Analysis Tab
127
 
128
- - Natural language queries about your data
129
- - AI-powered insights and recommendations
130
- - Automated pattern detection
131
- - Outlier identification
132
 
133
- ## Example AI Queries
134
 
135
  Ask SmoLagent questions like:
136
 
137
- - "What are the main trends in this data?"
138
- - "Find any outliers or anomalies"
139
- - "Suggest the best features for prediction"
140
- - "Identify data quality issues"
141
- - "Perform clustering analysis"
142
- - "Find seasonal patterns"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
  ## Data Requirements
145
 
146
- - CSV format
147
- - Update the file path in `config.py` or `upload.py`
148
- - Supports various data types (numerical, categorical, datetime)
 
 
 
149
 
150
  ## Troubleshooting
151
 
152
  ### Common Issues:
153
 
154
- 1. **File Not Found Error**
155
 
156
- - Check the CSV file path in `config.py`
157
- - Ensure the file exists and is accessible
 
 
158
 
159
- 2. **Model Configuration Error**
160
 
161
- - Verify your API keys in `config.py`
162
- - Check model availability and configuration
163
 
164
- 3. **Dependency Issues**
165
- - Run `pip install -r requirements.txt`
166
- - Ensure Python 3.8+ is installed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
  ### Getting Help:
169
 
170
- - Check the console output for detailed error messages
171
- - Verify your model configuration in `config.py`
172
- - Ensure your CSV file is properly formatted
 
173
 
174
  ## Advanced Usage
175
 
@@ -195,18 +302,88 @@ def create_custom_plot(df):
195
 
196
  ## Dependencies
197
 
198
- - smolagents - AI agent framework
199
- - gradio - Web interface
200
- - pandas - Data manipulation
201
- - numpy - Numerical computing
202
- - matplotlib/seaborn - Plotting
203
- - plotly - Interactive visualizations
204
- - scikit-learn - Machine learning tools
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
 
206
  ## License
207
 
208
- This project is open source and available under the MIT License.
 
 
209
 
210
- ## Configuration Reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
 
212
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
9
  pinned: false
10
  ---
11
 
12
+ # Singtel Use Case 1: OutSystems Log Analysis with SmoLagent AI
13
 
14
+ 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.
15
 
16
  ## Features
17
 
18
+ πŸ€– **AI-Powered Log Analysis**: Uses SmoLagent CodeAgent with DuckDuckGo search for intelligent log analysis
19
+ πŸ“Š **Interactive Visualizations**: Correlation heatmaps, distribution plots, and error pattern analysis
20
+ πŸ“ˆ **OutSystems-Specific Analytics**: Log level analysis, error module tracking, and performance insights
21
+ 🌐 **Multiple Interfaces**: Command-line, interactive menu, and web-based Gradio interface
22
+ πŸ”§ **Flexible AI Models**: OpenAI, Ollama (local), and HuggingFace Transformers support
23
+ 🚨 **Error Pattern Detection**: Automated identification of error trends and module issues
24
 
25
  ## Quick Start
26
 
 
30
  pip install -r requirements.txt
31
  ```
32
 
33
+ 2. **Configure Your AI Model** (Choose one option)
34
 
35
+ **Option A: Free Local AI (Ollama)**
36
+
37
+ ```bash
38
+ # Install Ollama from https://ollama.ai/
39
+ ollama pull llama2
40
+ ollama serve
41
+ python setup_ollama.py # Test setup
42
+ ```
43
+
44
+ **Option B: OpenAI API**
45
+
46
+ ```bash
47
+ set OPENAI_API_KEY=your_api_key_here
48
+ ```
49
+
50
+ **Option C: Use without AI (basic analysis only)**
51
+
52
+ ```bash
53
+ # No setup needed - basic data analysis works without AI
54
+ ```
55
 
56
  3. **Run the Application**
57
 
58
+ **Main Interactive Analysis:**
59
+
60
+ ```bash
61
+ python upload.py
62
+ # Choose mode 2 for enhanced AI features
63
+ ```
64
+
65
+ **Quick Demo:**
66
+
67
+ ```bash
68
+ python quick_ai_demo.py
69
+ ```
70
+
71
+ **Web Interface:**
72
+
73
  ```bash
74
  python app.py
75
+ # Open browser to displayed URL
76
  ```
77
 
78
+ 4. **Load Your OutSystems Data**
79
+ - Update file path in `upload.py` or `config.py`
80
+ - Default: `outsystems_sample_logs_6months.csv`
81
 
82
  ## Files Overview
83
 
84
+ ### Main Scripts
85
+
86
+ - **`upload.py`** - Main data analysis script with interactive menu and AI integration
87
+ - **`app.py`** - Gradio web interface for browser-based analysis
88
+ - **`fixed_upload.py`** - Streamlined working version with automatic model fallbacks
89
+
90
+ ### Setup & Testing Scripts
91
+
92
+ - **`setup_ollama.py`** - Ollama local AI setup helper
93
+ - **`setup_free_ai.py`** - Free AI models configuration
94
+ - **`test_smolagent.py`** - SmoLagent functionality testing
95
+ - **`quick_ai_demo.py`** - Quick demo without large downloads
96
+
97
+ ### Configuration
98
 
99
+ - **`config.py`** - Model and data source configuration
100
+ - **`requirements.txt`** - Python dependencies
101
+ - **`ENHANCEMENT_GUIDE.md`** - Enhancement documentation
102
 
103
+ ### Analysis Examples
104
+
105
+ - **`analyze.py`** - Programmatic analysis examples
106
+ - **`demo_enhanced.py`** - Enhanced features demonstration
107
+
108
+ ## Model Configuration Options
109
+
110
+ ### 1. Ollama (Recommended - Free & Local)
111
 
112
  ```python
113
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, OllamaModel
114
+
115
+ model = OllamaModel(model_id="llama2", base_url="http://localhost:11434")
116
+ agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
 
117
  ```
118
 
119
+ ### 2. OpenAI Models
120
 
121
  ```python
122
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIModel
123
+
124
+ model = OpenAIModel(model_id="gpt-3.5-turbo")
125
+ agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
 
126
  ```
127
 
128
+ ### 3. HuggingFace Transformers
129
 
130
  ```python
131
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, TransformersModel
132
+
133
+ model = TransformersModel(model_id="microsoft/DialoGPT-small")
134
+ agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
 
135
  ```
136
 
137
  ## Usage Examples
138
 
139
+ ### 1. Interactive Analysis (Recommended)
140
 
141
+ ```bash
142
+ python upload.py
143
+ # Choose mode 2 for enhanced AI features
144
+ # Navigate through interactive menu:
145
+ # 1. Load and explore data
146
+ # 2. Create visualizations
147
+ # 3. Analyze data quality
148
+ # 4. AI-powered analysis
149
  ```
150
 
151
+ ### 2. Quick Demo
152
 
153
+ ```bash
154
+ python quick_ai_demo.py # Basic analysis without heavy downloads
155
  ```
156
 
157
+ ### 3. Web Interface
158
 
159
+ ```bash
160
+ python app.py # Start Gradio web interface
161
  ```
162
 
163
+ ### 4. Automated Setup Testing
164
+
165
+ ```bash
166
+ python test_smolagent.py # Test SmoLagent setup
167
+ python setup_free_ai.py # Configure free AI models
168
+ ```
169
+
170
+ ## OutSystems Log Analysis Features
171
 
172
  ### 1. Data Overview Tab
173
 
174
+ - **Dataset Structure**: 5000+ log entries with 9 columns
175
+ - **Column Analysis**: Timestamp, LogLevel, Module, User, Message, RequestUrl, SessionId, ErrorId, StackTrace
176
+ - **Missing Value Detection**: Identifies incomplete error records (ErrorId/StackTrace gaps)
177
+ - **Memory Usage**: Optimized for large log files
178
 
179
+ ### 2. Log-Specific Analytics
180
 
181
+ - **Error Rate Analysis**: Info vs Error log distribution
182
+ - **Module Error Tracking**: Top error-generating modules identification
183
+ - **Session Analysis**: User session patterns and error correlation
184
+ - **Timestamp Patterns**: Time-based error trends and peak periods
185
 
186
+ ### 3. Visualizations
187
 
188
+ - **Error Distribution Plots**: Visual error patterns across modules
189
+ - **Correlation Analysis**: Relationships between log parameters
190
+ - **Time Series Analysis**: Error trends over 6-month period
191
 
192
+ ### 4. AI-Powered OutSystems Insights
193
 
194
+ - **Error Pattern Recognition**: AI identifies recurring error types
195
+ - **Module Risk Assessment**: Predicts which modules need attention
196
+ - **Performance Optimization**: Suggests improvements based on log patterns
197
+ - **Anomaly Detection**: Unusual log patterns and potential issues
198
 
199
+ ## Example AI Queries for OutSystems Logs
200
 
201
  Ask SmoLagent questions like:
202
 
203
+ **Error Analysis:**
204
+
205
+ - "What are the most common error types in these OutSystems logs?"
206
+ - "Which modules generate the most errors?"
207
+ - "Find patterns in error messages"
208
+ - "Identify critical errors that need immediate attention"
209
+
210
+ **Performance Insights:**
211
+
212
+ - "Analyze user session patterns for performance issues"
213
+ - "Find modules with the highest error rates"
214
+ - "Detect unusual activity patterns"
215
+ - "Suggest modules that need code review"
216
+
217
+ **Trend Analysis:**
218
+
219
+ - "Show error trends over the 6-month period"
220
+ - "Find seasonal patterns in system usage"
221
+ - "Identify peak error periods"
222
+ - "Correlate errors with specific time periods"
223
+
224
+ **Data Quality:**
225
+
226
+ - "Check for incomplete error records"
227
+ - "Find missing StackTrace patterns"
228
+ - "Validate log data completeness"
229
+ - "Suggest data quality improvements"
230
 
231
  ## Data Requirements
232
 
233
+ - **Format**: CSV format with OutSystems log structure
234
+ - **Expected Columns**: Timestamp, LogLevel, Module, User, Message, RequestUrl, SessionId, ErrorId, StackTrace
235
+ - **Default File**: `outsystems_sample_logs_6months.csv` (6 months of sample data)
236
+ - **File Location**: Update path in `upload.py` line 11 or `config.py`
237
+ - **Size**: Optimized for datasets with 5000+ log entries
238
+ - **Encoding**: UTF-8 encoding recommended
239
 
240
  ## Troubleshooting
241
 
242
  ### Common Issues:
243
 
244
+ 1. **"Module not found: smolagents"**
245
 
246
+ ```bash
247
+ pip install 'smolagents[transformers]'
248
+ pip install duckduckgo-search>=3.8.0
249
+ ```
250
 
251
+ 2. **"CodeAgent requires model parameter"**
252
 
253
+ - Run `python fixed_upload.py` for automatic model fallbacks
254
+ - Or configure Ollama: `python setup_ollama.py`
255
 
256
+ 3. **Model Download Taking Too Long**
257
+
258
+ ```bash
259
+ python quick_ai_demo.py # Use without heavy downloads
260
+ ```
261
+
262
+ 4. **OutSystems CSV File Not Found**
263
+
264
+ - Update file path in `upload.py` line 11
265
+ - Ensure CSV file exists at specified location
266
+ - Check file permissions
267
+
268
+ 5. **Ollama Connection Error**
269
+ ```bash
270
+ ollama serve # Start Ollama server
271
+ ollama pull llama2 # Download model
272
+ ```
273
 
274
  ### Getting Help:
275
 
276
+ - **Quick Test**: Run `python test_smolagent.py`
277
+ - **Setup Issues**: Run `python setup_free_ai.py`
278
+ - **Basic Analysis**: Use Mode 1 in `upload.py` (works without AI)
279
+ - **Check Logs**: Console output shows detailed error messages
280
 
281
  ## Advanced Usage
282
 
 
302
 
303
  ## Dependencies
304
 
305
+ **Core AI Framework:**
306
+
307
+ - `smolagents>=0.3.0` - AI agent framework with CodeAgent
308
+ - `duckduckgo-search>=3.8.0` - Web search capabilities
309
+
310
+ **Data Analysis Stack:**
311
+
312
+ - `pandas>=2.0.0` - Data manipulation and analysis
313
+ - `numpy>=1.24.0` - Numerical computing
314
+ - `scikit-learn>=1.3.0` - Machine learning tools
315
+
316
+ **Visualization:**
317
+
318
+ - `matplotlib>=3.7.0` - Basic plotting
319
+ - `seaborn>=0.12.0` - Statistical visualizations
320
+ - `plotly>=5.15.0` - Interactive visualizations
321
+
322
+ **AI Models:**
323
+
324
+ - `transformers>=4.30.0` - HuggingFace transformers
325
+ - `torch>=2.0.0` - PyTorch for model inference
326
+ - `huggingface_hub>=0.16.0` - Model hub access
327
+
328
+ **Web Interface:**
329
+
330
+ - `gradio>=5.37.0` - Web UI framework
331
+ - `Pillow>=10.0.0` - Image processing
332
+
333
+ **HTTP & Utilities:**
334
+
335
+ - `requests>=2.31.0` - HTTP requests
336
+
337
+ ## Project Structure
338
+
339
+ ```
340
+ Singtel_Use_Case1/
341
+ β”œβ”€β”€ πŸ“ Main Scripts
342
+ β”‚ β”œβ”€β”€ upload.py # Primary interactive analysis tool
343
+ β”‚ β”œβ”€β”€ app.py # Gradio web interface
344
+ β”‚ └── fixed_upload.py # Streamlined working version
345
+ β”‚
346
+ β”œβ”€β”€ πŸ“ Setup & Testing
347
+ β”‚ β”œβ”€β”€ setup_ollama.py # Ollama configuration helper
348
+ β”‚ β”œβ”€β”€ setup_free_ai.py # Free AI models setup
349
+ β”‚ β”œβ”€β”€ test_smolagent.py # SmoLagent testing
350
+ β”‚ └── quick_ai_demo.py # Quick demo script
351
+ β”‚
352
+ β”œβ”€β”€ πŸ“ Configuration
353
+ β”‚ β”œβ”€β”€ config.py # Model and data configuration
354
+ β”‚ β”œβ”€β”€ requirements.txt # Python dependencies
355
+ β”‚ └── ENHANCEMENT_GUIDE.md # Development guide
356
+ β”‚
357
+ β”œβ”€β”€ πŸ“ Analysis Examples
358
+ β”‚ β”œβ”€β”€ analyze.py # Programmatic analysis
359
+ β”‚ └── demo_enhanced.py # Feature demonstrations
360
+ β”‚
361
+ └── πŸ“ Data (Expected)
362
+ └── outsystems_sample_logs_6months.csv
363
+ ```
364
 
365
  ## License
366
 
367
+ This project is developed for Singtel Use Case 1 analysis and is available under the MIT License.
368
+
369
+ ---
370
 
371
+ ## Quick Commands Reference
372
+
373
+ ```bash
374
+ # πŸš€ Quick Start
375
+ python upload.py # Main interactive tool
376
+ python quick_ai_demo.py # Fast demo without downloads
377
+ python app.py # Web interface
378
+
379
+ # πŸ”§ Setup & Testing
380
+ python setup_ollama.py # Configure local AI
381
+ python test_smolagent.py # Test AI setup
382
+ python setup_free_ai.py # Free models setup
383
+
384
+ # πŸ“Š Analysis Options
385
+ # Mode 1: Basic data exploration (no AI required)
386
+ # Mode 2: Full AI-powered analysis with interactive menu
387
+ ```
388
 
389
+ **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.