saptyfun commited on
Commit
d053b0b
Β·
verified Β·
1 Parent(s): 2e8352c

Upload streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +226 -17
src/streamlit_app.py CHANGED
@@ -58,20 +58,29 @@ class SimpleDashboard:
58
  data = []
59
 
60
  for i in range(50):
 
 
61
  data.append({
62
  'id': i,
63
  'session_id': f"session_{random.randint(1000, 9999)}",
64
  'agent_name': random.choice(agents),
65
  'query': f"Sample query {i}",
66
- 'response': f"Sample response {i} with detailed information...",
67
- 'overall_score': random.uniform(7.0, 9.5),
68
  'relevance_score': random.uniform(7.0, 9.5),
69
- 'accuracy_score': random.uniform(7.0, 9.5),
70
  'completeness_score': random.uniform(7.0, 9.5),
71
  'coherence_score': random.uniform(7.0, 9.5),
 
72
  'guardrails_passed': True,
73
  'safety_score': random.uniform(8.0, 10.0),
74
  'execution_time_ms': random.uniform(500, 2000),
 
 
 
 
 
 
75
  'timestamp': datetime.now() - timedelta(days=random.randint(0, 30))
76
  })
77
 
@@ -103,9 +112,16 @@ class SimpleDashboard:
103
  accuracy_score REAL,
104
  completeness_score REAL,
105
  coherence_score REAL,
 
106
  guardrails_passed BOOLEAN,
107
  safety_score REAL,
108
  execution_time_ms REAL,
 
 
 
 
 
 
109
  timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
110
  )
111
  ''')
@@ -142,11 +158,52 @@ class SimpleDashboard:
142
  agent = random.choice(agents)
143
  query = random.choice(sample_queries[agent])
144
 
145
- # Generate detailed response
146
- response = f"Based on your query about {query[:30]}..., here's a comprehensive response with detailed information and actionable recommendations."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
  # Generate realistic scores
149
  base_score = random.uniform(7.0, 9.5)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  timestamp = datetime.now() - timedelta(days=random.randint(0, 30))
152
 
@@ -154,18 +211,16 @@ class SimpleDashboard:
154
  INSERT INTO evaluation_logs (
155
  session_id, agent_name, query, response, overall_score,
156
  relevance_score, accuracy_score, completeness_score, coherence_score,
157
- guardrails_passed, safety_score, execution_time_ms, timestamp
158
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
 
159
  ''', (
160
  session_id, agent, query, response, base_score,
161
- base_score + random.uniform(-0.3, 0.3),
162
- base_score + random.uniform(-0.4, 0.2),
163
- base_score + random.uniform(-0.5, 0.3),
164
- base_score + random.uniform(-0.2, 0.4),
165
- random.choice([True, True, True, False]), # 75% pass rate
166
- random.uniform(8.0, 10.0),
167
- random.uniform(500, 2000),
168
- timestamp.isoformat()
169
  ))
170
 
171
  conn.commit()
@@ -360,6 +415,156 @@ class SimpleDashboard:
360
  if 'timestamp' in row:
361
  st.write(f"Timestamp: {row['timestamp']}")
362
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
  def run(self):
364
  """Run the dashboard"""
365
  st.title("πŸ€– Multi-Agent System Dashboard")
@@ -371,10 +576,11 @@ class SimpleDashboard:
371
  df = self.load_data()
372
 
373
  # Create tabs
374
- tab1, tab2, tab3 = st.tabs([
375
  "πŸ“ˆ Overview",
376
  "πŸ€– Agent Performance",
377
- "πŸ“ Response Analysis"
 
378
  ])
379
 
380
  with tab1:
@@ -386,6 +592,9 @@ class SimpleDashboard:
386
  with tab3:
387
  self.show_response_analysis(df)
388
 
 
 
 
389
  # Footer
390
  st.markdown("---")
391
  st.markdown("πŸš€ **Multi-Agent System Dashboard** | Built with Streamlit & Plotly")
 
58
  data = []
59
 
60
  for i in range(50):
61
+ base_score = random.uniform(7.0, 9.5)
62
+ accuracy = random.uniform(7.0, 9.5)
63
  data.append({
64
  'id': i,
65
  'session_id': f"session_{random.randint(1000, 9999)}",
66
  'agent_name': random.choice(agents),
67
  'query': f"Sample query {i}",
68
+ 'response': f"Sample response {i} with detailed information and comprehensive guidance...",
69
+ 'overall_score': base_score,
70
  'relevance_score': random.uniform(7.0, 9.5),
71
+ 'accuracy_score': accuracy,
72
  'completeness_score': random.uniform(7.0, 9.5),
73
  'coherence_score': random.uniform(7.0, 9.5),
74
+ 'hallucination_score': max(0, min(10, 10 - accuracy + random.uniform(-1.0, 1.0))),
75
  'guardrails_passed': True,
76
  'safety_score': random.uniform(8.0, 10.0),
77
  'execution_time_ms': random.uniform(500, 2000),
78
+ 'input_tokens': random.randint(20, 100),
79
+ 'output_tokens': random.randint(100, 500),
80
+ 'total_tokens': random.randint(120, 600),
81
+ 'cost_usd': random.uniform(0.001, 0.02),
82
+ 'llm_provider': random.choice(["azure", "openai", "anthropic"]),
83
+ 'model_name': 'gpt-4o',
84
  'timestamp': datetime.now() - timedelta(days=random.randint(0, 30))
85
  })
86
 
 
112
  accuracy_score REAL,
113
  completeness_score REAL,
114
  coherence_score REAL,
115
+ hallucination_score REAL,
116
  guardrails_passed BOOLEAN,
117
  safety_score REAL,
118
  execution_time_ms REAL,
119
+ input_tokens INTEGER,
120
+ output_tokens INTEGER,
121
+ total_tokens INTEGER,
122
+ cost_usd REAL,
123
+ llm_provider TEXT,
124
+ model_name TEXT,
125
  timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
126
  )
127
  ''')
 
158
  agent = random.choice(agents)
159
  query = random.choice(sample_queries[agent])
160
 
161
+ # Generate comprehensive response
162
+ response_templates = {
163
+ "Diet Agent": [
164
+ "Thank you for your question about nutrition and dietary guidance. I'd be happy to help you develop a healthier relationship with food and create sustainable eating habits.",
165
+ "I understand you're looking for dietary advice, and I'm here to provide evidence-based nutritional guidance tailored to your specific needs and goals."
166
+ ],
167
+ "Support Agent": [
168
+ "I appreciate you reaching out for support. It takes courage to ask for help, and I'm here to provide you with practical strategies and emotional guidance.",
169
+ "Thank you for sharing your concerns with me. I understand this can be challenging, and I want to help you work through this step by step with compassion and understanding."
170
+ ],
171
+ "Queries Agent": [
172
+ "Excellent question! This is a fascinating topic that involves cutting-edge technology and has significant implications for our future. Let me provide you with a comprehensive overview.",
173
+ "Thank you for this thought-provoking question. This subject encompasses multiple disciplines and recent innovations. I'll break this down into key concepts and practical applications."
174
+ ]
175
+ }
176
+
177
+ base_response = random.choice(response_templates[agent])
178
+
179
+ # Add detailed information
180
+ if agent == "Diet Agent":
181
+ details = "**Key Nutritional Recommendations:**\n\n1. **Whole Foods Focus**: Prioritize unprocessed foods like fresh fruits, vegetables, whole grains, lean proteins, and healthy fats.\n\n2. **Portion Control**: Use the plate method - fill half your plate with non-starchy vegetables, one quarter with lean protein, and one quarter with complex carbohydrates.\n\n3. **Hydration**: Aim for 8-10 glasses of water daily to support metabolism and overall health."
182
+ elif agent == "Support Agent":
183
+ details = "**Comprehensive Support Strategy:**\n\n**Immediate Coping Techniques:**\n1. **Deep Breathing**: Practice the 4-7-8 technique - inhale for 4 counts, hold for 7, exhale for 8.\n\n2. **Grounding Exercises**: Use the 5-4-3-2-1 method - identify 5 things you can see, 4 you can touch, 3 you can hear, 2 you can smell, and 1 you can taste.\n\n**Long-term Strategies:**\n- Establish a consistent daily routine\n- Practice mindfulness meditation for 10-15 minutes daily"
184
+ else: # Queries Agent
185
+ details = "**Technical Deep Dive:**\n\n**Fundamental Concepts:**\nThis technology represents a convergence of multiple disciplines including computer science, mathematics, engineering, and domain-specific expertise.\n\n**Current Implementation:**\n1. **Healthcare**: AI-powered diagnostic tools and personalized treatment plans\n2. **Finance**: Algorithmic trading and fraud detection\n3. **Transportation**: Autonomous vehicles and traffic optimization"
186
+
187
+ response = f"{base_response}\n\n{details}"
188
 
189
  # Generate realistic scores
190
  base_score = random.uniform(7.0, 9.5)
191
+ relevance_score = max(0, min(10, base_score + random.uniform(-0.3, 0.3)))
192
+ accuracy_score = max(0, min(10, base_score + random.uniform(-0.4, 0.2)))
193
+ completeness_score = max(0, min(10, base_score + random.uniform(-0.5, 0.3)))
194
+ coherence_score = max(0, min(10, base_score + random.uniform(-0.2, 0.4)))
195
+ hallucination_score = max(0, min(10, 10 - accuracy_score + random.uniform(-1.0, 1.0)))
196
+
197
+ # Generate token consumption
198
+ response_length = len(response)
199
+ input_tokens = int(len(query.split()) * 1.3)
200
+ output_tokens = int(response_length / 4)
201
+ total_tokens = input_tokens + output_tokens
202
+
203
+ # Calculate cost
204
+ llm_provider = random.choice(["azure", "openai", "anthropic"])
205
+ cost_per_1k = {"azure": 0.03, "openai": 0.03, "anthropic": 0.025}
206
+ cost_usd = (total_tokens / 1000) * cost_per_1k[llm_provider]
207
 
208
  timestamp = datetime.now() - timedelta(days=random.randint(0, 30))
209
 
 
211
  INSERT INTO evaluation_logs (
212
  session_id, agent_name, query, response, overall_score,
213
  relevance_score, accuracy_score, completeness_score, coherence_score,
214
+ hallucination_score, guardrails_passed, safety_score, execution_time_ms,
215
+ input_tokens, output_tokens, total_tokens, cost_usd, llm_provider, model_name, timestamp
216
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
217
  ''', (
218
  session_id, agent, query, response, base_score,
219
+ relevance_score, accuracy_score, completeness_score, coherence_score,
220
+ hallucination_score, random.choice([True, True, True, False]), # 75% pass rate
221
+ random.uniform(8.0, 10.0), random.uniform(500, 2000),
222
+ input_tokens, output_tokens, total_tokens, round(cost_usd, 4),
223
+ llm_provider, "gpt-4o", timestamp.isoformat()
 
 
 
224
  ))
225
 
226
  conn.commit()
 
415
  if 'timestamp' in row:
416
  st.write(f"Timestamp: {row['timestamp']}")
417
 
418
+ def show_workflow_visualization(self, df):
419
+ """Show workflow visualization tab"""
420
+ st.header("πŸ”„ Workflow Visualization")
421
+
422
+ if df.empty:
423
+ st.warning("No data available for workflow visualization.")
424
+ return
425
+
426
+ # Session selection
427
+ sessions = df['session_id'].unique()
428
+ selected_session = st.selectbox("Select Session", sessions, key="workflow_session")
429
+
430
+ # Filter data for selected session
431
+ session_data = df[df['session_id'] == selected_session]
432
+
433
+ if session_data.empty:
434
+ st.warning("No data found for selected session.")
435
+ return
436
+
437
+ # Session metrics overview
438
+ st.subheader("πŸ“ˆ Session Metrics Overview")
439
+
440
+ col1, col2, col3, col4 = st.columns(4)
441
+
442
+ with col1:
443
+ avg_score = session_data['overall_score'].mean()
444
+ st.metric("Avg Overall Score", f"{avg_score:.2f}/10")
445
+
446
+ with col2:
447
+ avg_latency = session_data['execution_time_ms'].mean()
448
+ st.metric("Avg Response Time", f"{avg_latency:.0f}ms")
449
+
450
+ with col3:
451
+ if 'hallucination_score' in session_data.columns:
452
+ avg_hallucination = session_data['hallucination_score'].mean()
453
+ st.metric("Avg Hallucination", f"{avg_hallucination:.2f}/10")
454
+ else:
455
+ st.metric("Avg Hallucination", "N/A")
456
+
457
+ with col4:
458
+ if 'total_tokens' in session_data.columns:
459
+ total_tokens = session_data['total_tokens'].sum()
460
+ total_cost = session_data['cost_usd'].sum() if 'cost_usd' in session_data.columns else 0
461
+ st.metric("Total Cost", f"${total_cost:.4f}", f"{total_tokens:,} tokens")
462
+ else:
463
+ st.metric("Total Cost", "N/A")
464
+
465
+ # Workflow steps
466
+ st.subheader("πŸ” Workflow Steps")
467
+
468
+ for idx, (_, row) in enumerate(session_data.iterrows()):
469
+ with st.expander(f"Step {idx + 1}: {row['agent_name']} - Score: {row['overall_score']:.2f}/10"):
470
+
471
+ col1, col2 = st.columns([1, 1])
472
+
473
+ with col1:
474
+ st.markdown("**Query:**")
475
+ st.write(row['query'])
476
+
477
+ # Performance metrics chart
478
+ st.markdown("**Performance Metrics:**")
479
+ metrics_data = {
480
+ 'Overall': row['overall_score'],
481
+ 'Relevance': row.get('relevance_score', 0),
482
+ 'Accuracy': row.get('accuracy_score', 0),
483
+ 'Completeness': row.get('completeness_score', 0),
484
+ 'Coherence': row.get('coherence_score', 0)
485
+ }
486
+
487
+ if 'hallucination_score' in row:
488
+ metrics_data['Hallucination'] = row['hallucination_score']
489
+
490
+ fig = px.bar(
491
+ x=list(metrics_data.keys()),
492
+ y=list(metrics_data.values()),
493
+ title="Score Breakdown",
494
+ labels={'x': 'Metric', 'y': 'Score (0-10)'}
495
+ )
496
+ fig.update_layout(height=300, showlegend=False)
497
+ st.plotly_chart(fig, use_container_width=True)
498
+
499
+ with col2:
500
+ st.markdown("**Response:**")
501
+ if pd.notna(row['response']):
502
+ st.write(row['response'])
503
+ else:
504
+ st.write("No response available")
505
+
506
+ # Resource consumption
507
+ st.markdown("**Resource Consumption:**")
508
+
509
+ if 'input_tokens' in row and pd.notna(row['input_tokens']):
510
+ token_col1, token_col2 = st.columns(2)
511
+ with token_col1:
512
+ st.metric("Input Tokens", f"{int(row['input_tokens']):,}")
513
+ st.metric("Output Tokens", f"{int(row.get('output_tokens', 0)):,}")
514
+
515
+ with token_col2:
516
+ st.metric("Total Tokens", f"{int(row.get('total_tokens', 0)):,}")
517
+ st.metric("Cost", f"${row.get('cost_usd', 0):.4f}")
518
+
519
+ # Execution details
520
+ st.markdown("**Execution Details:**")
521
+ st.write(f"⏱️ **Execution Time:** {row['execution_time_ms']:.0f}ms")
522
+ if 'llm_provider' in row:
523
+ st.write(f"πŸ€– **LLM Provider:** {row['llm_provider']}")
524
+ if 'model_name' in row:
525
+ st.write(f"🧠 **Model:** {row['model_name']}")
526
+ st.write(f"πŸ›‘οΈ **Safety Passed:** {'βœ…' if row['guardrails_passed'] else '❌'}")
527
+
528
+ # Session summary
529
+ st.subheader("πŸ“‹ Session Summary")
530
+
531
+ summary_col1, summary_col2, summary_col3 = st.columns(3)
532
+
533
+ with summary_col1:
534
+ st.markdown("**Quality Metrics:**")
535
+ st.write(f"β€’ Average Overall Score: {session_data['overall_score'].mean():.2f}/10")
536
+ best_step = session_data.loc[session_data['overall_score'].idxmax()]
537
+ st.write(f"β€’ Best Performing Step: {best_step['agent_name']}")
538
+ st.write(f"β€’ Consistency (Std Dev): {session_data['overall_score'].std():.2f}")
539
+
540
+ with summary_col2:
541
+ st.markdown("**Performance Metrics:**")
542
+ st.write(f"β€’ Total Execution Time: {session_data['execution_time_ms'].sum():.0f}ms")
543
+ st.write(f"β€’ Average Response Time: {session_data['execution_time_ms'].mean():.0f}ms")
544
+ st.write(f"β€’ Fastest Step: {session_data['execution_time_ms'].min():.0f}ms")
545
+
546
+ with summary_col3:
547
+ st.markdown("**Resource Usage:**")
548
+ if 'total_tokens' in session_data.columns:
549
+ st.write(f"β€’ Total Tokens Used: {session_data['total_tokens'].sum():,}")
550
+ if 'cost_usd' in session_data.columns:
551
+ st.write(f"β€’ Total Cost: ${session_data['cost_usd'].sum():.4f}")
552
+ st.write(f"β€’ Avg Cost per Query: ${session_data['cost_usd'].mean():.4f}")
553
+ else:
554
+ st.write("β€’ Token data not available")
555
+
556
+ # Export functionality
557
+ st.subheader("πŸ“€ Export Workflow Data")
558
+
559
+ if st.button("Export Session Data to CSV", key="export_workflow"):
560
+ csv_data = session_data.to_csv(index=False)
561
+ st.download_button(
562
+ label="Download CSV",
563
+ data=csv_data,
564
+ file_name=f"workflow_session_{selected_session}.csv",
565
+ mime="text/csv"
566
+ )
567
+
568
  def run(self):
569
  """Run the dashboard"""
570
  st.title("πŸ€– Multi-Agent System Dashboard")
 
576
  df = self.load_data()
577
 
578
  # Create tabs
579
+ tab1, tab2, tab3, tab4 = st.tabs([
580
  "πŸ“ˆ Overview",
581
  "πŸ€– Agent Performance",
582
+ "πŸ“ Response Analysis",
583
+ "πŸ”„ Workflow Visualization"
584
  ])
585
 
586
  with tab1:
 
592
  with tab3:
593
  self.show_response_analysis(df)
594
 
595
+ with tab4:
596
+ self.show_workflow_visualization(df)
597
+
598
  # Footer
599
  st.markdown("---")
600
  st.markdown("πŸš€ **Multi-Agent System Dashboard** | Built with Streamlit & Plotly")