File size: 19,475 Bytes
d09efd7 9e4cc43 e3a5c8e 8117a22 e3a5c8e 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 e3a5c8e 8117a22 9e4cc43 8117a22 9e4cc43 e3a5c8e 9e4cc43 8117a22 9e4cc43 8117a22 e3a5c8e 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 d09efd7 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 e3a5c8e 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 e3a5c8e 8117a22 e3a5c8e 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 d09efd7 8117a22 d09efd7 8117a22 d09efd7 8117a22 20a17de 8117a22 9e4cc43 8117a22 d09efd7 8117a22 d09efd7 8117a22 20a17de 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 20a17de d09efd7 8117a22 d09efd7 8117a22 d09efd7 9e4cc43 8117a22 9e4cc43 8117a22 20a17de d09efd7 8117a22 d09efd7 8117a22 d09efd7 8117a22 9e4cc43 8117a22 20a17de d09efd7 9e4cc43 8117a22 d09efd7 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 9e4cc43 8117a22 d09efd7 8117a22 d09efd7 8117a22 9e4cc43 8117a22 d09efd7 8117a22 d09efd7 8117a22 d09efd7 8117a22 d09efd7 9e4cc43 8117a22 9e4cc43 992e460 9e4cc43 d09efd7 8117a22 9e4cc43 8117a22 9e4cc43 d09efd7 8117a22 d09efd7 8117a22 d09efd7 8117a22 d09efd7 8117a22 d09efd7 8117a22 d09efd7 8117a22 9e4cc43 8117a22 9e4cc43 d09efd7 8117a22 d09efd7 8117a22 d09efd7 8117a22 d09efd7 8117a22 9e4cc43 8117a22 d09efd7 8117a22 d09efd7 8117a22 d09efd7 8117a22 d09efd7 8117a22 d09efd7 8117a22 d09efd7 8117a22 d09efd7 992e460 d09efd7 e3a5c8e 9e4cc43 8117a22 e3a5c8e | 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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 | import gradio as gr
import json
import time
import random
from datetime import datetime, timedelta
from functools import lru_cache
# Optimized demo controller
class OptimizedEnterpriseDemo:
def __init__(self):
self.request_count = 0
self.total_time_saved = 0
def calculate_business_impact(self, story_complexity="medium"):
"""Calculate concise business impact metrics"""
traditional_times = {"simple": 4, "medium": 8, "complex": 16}
traditional_hours = traditional_times.get(story_complexity, 8)
genai_time_minutes = 3
time_saved_hours = traditional_hours - (genai_time_minutes / 60)
efficiency_gain = (time_saved_hours / traditional_hours) * 100
cost_saved = time_saved_hours * 75 # $75/hour QA rate
self.total_time_saved += time_saved_hours
self.request_count += 1
return {
"traditional_hours": traditional_hours,
"time_saved_hours": round(time_saved_hours, 1),
"efficiency_gain": round(efficiency_gain, 1),
"cost_saved": round(cost_saved, 2)
}
demo_controller = OptimizedEnterpriseDemo()
# Simplified user stories
ENTERPRISE_STORIES = [
{
"id": 1,
"title": "Premium Payment Processing",
"description": "As a policyholder, I want to pay my premium using multiple payment methods with real-time validation and fraud detection so my payment is secure and processed immediately.",
"complexity": "complex",
"priority": "Critical"
},
{
"id": 2,
"title": "Claims Processing Automation",
"description": "As a claims adjuster, I want automated claims processing that validates documents, checks coverage, and detects fraud so I can process claims efficiently.",
"complexity": "complex",
"priority": "High"
},
{
"id": 3,
"title": "Invoice Generation & Compliance",
"description": "As a billing admin, I want automated invoice generation with regulatory compliance and tax calculations so invoices meet legal standards.",
"complexity": "medium",
"priority": "High"
},
{
"id": 4,
"title": "Customer Onboarding",
"description": "As a new customer, I want streamlined onboarding with risk assessment and quote generation so I can get coverage quickly.",
"complexity": "medium",
"priority": "Medium"
},
{
"id": 5,
"title": "Policy Renewal & Dynamic Pricing",
"description": "As a policyholder, I want automatic renewal with updated premiums based on current risk factors and claims history.",
"complexity": "complex",
"priority": "Medium"
}
]
def analyze_requirements_concise(user_story):
"""Concise requirement analysis"""
if "payment" in user_story.lower():
return {
"gaps": ["Payment retry logic", "Currency handling", "Timeout values"],
"rules": ["PCI compliance required", "Fraud detection mandatory", "Audit trail needed"],
"coverage": ["Security", "Integration", "Compliance"]
}
elif "claims" in user_story.lower():
return {
"gaps": ["Document formats", "Approval thresholds", "Appeal process"],
"rules": ["Policy validation required", "High-value manual review", "Fraud alerts immediate"],
"coverage": ["Document Processing", "Business Rules", "Fraud Detection"]
}
else:
return {
"gaps": ["Success criteria", "Error handling", "Performance SLAs"],
"rules": ["Data validation required", "Audit trail mandatory", "User feedback needed"],
"coverage": ["Functional", "Security", "Performance"]
}
def generate_concise_bdd(user_story, analysis):
"""Generate focused BDD scenario"""
if "payment" in user_story.lower():
return """Feature: Premium Payment Processing
Secure payment processing with fraud detection
Scenario: Successful credit card payment
Given I have a valid policy and credit card
When I process payment of $1,200
Then payment is validated and processed
And fraud detection approves transaction
And confirmation is sent
Scenario: Payment failure handling
Given insufficient funds on my card
When I attempt payment
Then I receive clear error message
And alternative payment options offered
And attempt is logged for audit"""
elif "claims" in user_story.lower():
return """Feature: Automated Claims Processing
Efficient claim validation and processing
Scenario: Successful claim processing
Given valid claim with documentation
When automated processing runs
Then documents are validated
And policy coverage is verified
And settlement is calculated
And approval is generated
Scenario: High-value claim review
Given claim exceeds $10,000 threshold
When processing begins
Then claim is flagged for manual review
And adjuster is notified
And summary is provided"""
else:
return """Feature: Core System Functionality
Reliable business operations
Scenario: Successful operation
Given authorized user access
When performing business operation
Then system validates inputs
And processes according to rules
And provides appropriate feedback
And maintains audit trail"""
def generate_focused_test_script():
"""Generate concise, focused test script"""
return '''import pytest
from unittest.mock import Mock, patch
from datetime import datetime
class TestInsuranceSystem:
"""Enterprise insurance system tests"""
def setup_method(self):
self.policy = {"id": "POL-12345", "premium": 1200.00}
self.payment_service = Mock()
self.fraud_detector = Mock()
@patch('payment.PaymentGateway')
def test_successful_payment_processing(self, mock_gateway):
"""Test end-to-end payment processing"""
# Given
mock_gateway.return_value.process.return_value = {
"status": "SUCCESS", "txn_id": "TXN-001"
}
# When
result = self.payment_service.process_payment(
self.policy["id"], 1200.00
)
# Then
assert result["status"] == "SUCCESS"
assert result["txn_id"] is not None
mock_gateway.return_value.process.assert_called_once()
def test_fraud_detection_integration(self):
"""Test fraud detection workflow"""
# Given
self.fraud_detector.analyze.return_value = {
"risk_score": 8.5, "approved": False
}
# When
result = self.payment_service.validate_transaction(
self.policy["id"], 1200.00
)
# Then
assert result["blocked"] is True
assert result["reason"] == "HIGH_RISK"
def test_audit_trail_creation(self):
"""Test comprehensive audit logging"""
# When
self.payment_service.process_payment(
self.policy["id"], 1200.00
)
# Then
self.payment_service.audit_log.assert_called()'''
def simulate_concise_execution(complexity, coverage_areas):
"""Generate concise execution results"""
test_counts = {"simple": 8, "medium": 12, "complex": 18}
total = test_counts.get(complexity, 12)
# Simulate realistic pass/fail rates
if complexity == "complex":
passed = random.randint(14, 16)
else:
passed = random.randint(total-2, total)
failed = total - passed
execution_time = round(random.uniform(1.8, 3.2), 1)
return {
"status": "PASS" if failed == 0 else "FAIL",
"total": total,
"passed": passed,
"failed": failed,
"time": execution_time,
"coverage_areas": coverage_areas,
"performance": {
"response_time": random.randint(120, 450),
"memory_mb": random.randint(45, 95),
"cpu_percent": random.randint(15, 55)
}
}
def generate_qa_ai_feedback(execution_result, story_complexity, business_impact):
"""Generate QA-AI tester feedback and recommendations"""
if execution_result["status"] == "PASS":
feedback = f"""π€ **QA-AI Tester Review: β
APPROVED**
**Quality Assessment:** All {execution_result['total']} tests passed
**Performance Grade:** A+ (Response: {execution_result['performance']['response_time']}ms)
**Coverage Score:** 98% - Comprehensive validation achieved
**π― AI Recommendations:**
β’ Ready for production deployment
β’ Consider adding performance monitoring
β’ Implement automated regression suite
**β‘ Efficiency Gains:**
β’ **Time Saved:** {business_impact['time_saved_hours']} hours
β’ **Cost Reduced:** ${business_impact['cost_saved']}
β’ **Quality Improved:** {len(execution_result['coverage_areas'])} areas validated"""
else:
feedback = f"""π€ **QA-AI Tester Review: β οΈ NEEDS ATTENTION**
**Quality Assessment:** {execution_result['failed']} of {execution_result['total']} tests failed
**Risk Level:** {'High' if execution_result['failed'] > 3 else 'Medium'}
**Performance Impact:** {execution_result['performance']['response_time']}ms response time
**π§ AI-Powered Fix Suggestions:**
β’ Priority 1: Address {execution_result['coverage_areas'][0]} failures
β’ Priority 2: Optimize performance (target <300ms)
β’ Priority 3: Enhanced error handling needed
**π Business Impact:**
β’ **Deployment Risk:** Production issues likely
β’ **Customer Impact:** {random.randint(200, 800)} users affected
β’ **Revenue Risk:** ${random.randint(10000, 50000)} potential loss
**π Next Steps:**
1. Fix critical failures (Est: 2-4 hours)
2. Re-run validation suite
3. Performance optimization review"""
return feedback
def process_optimized_lifecycle(selected_story_id, custom_story=""):
"""Streamlined test lifecycle process"""
try:
# Get story details
if custom_story.strip():
user_story = custom_story.strip()
story_title = "Custom Story"
complexity = "medium"
else:
story = next((s for s in ENTERPRISE_STORIES if s["id"] == int(selected_story_id)), None)
if not story:
return "β Story not found", "", "", "", "", "", ""
user_story = story["description"]
story_title = story["title"]
complexity = story["complexity"]
business_impact = demo_controller.calculate_business_impact(complexity)
# Step 1: Requirements Analysis
yield (
f"π Analyzing: {story_title}",
f"**User Story:** {user_story}\n\n**Complexity:** {complexity.title()} | **Traditional Time:** {business_impact['traditional_hours']} hours",
"β³ AI analyzing requirements...",
"", "", "", ""
)
time.sleep(1)
analysis = analyze_requirements_concise(user_story)
requirements_output = f"""**π§ AI Requirements Analysis:**
**Missing Requirements:** {', '.join(analysis['gaps'][:2])}
**Business Rules:** {len(analysis['rules'])} rules identified
**Test Coverage:** {', '.join(analysis['coverage'])} areas"""
# Step 2: BDD Generation
yield (
f"β
Requirements Complete: {story_title}",
f"**User Story:** {user_story}\n\n**Time Saved:** {business_impact['time_saved_hours']} hours | **Cost Saved:** ${business_impact['cost_saved']}",
requirements_output,
"β³ Generating BDD scenarios...",
"", "", ""
)
time.sleep(1.5)
bdd_scenario = generate_concise_bdd(user_story, analysis)
# Step 3: Test Script Generation
yield (
f"β
BDD Generated: {story_title}",
f"**User Story:** {user_story}\n\n**Efficiency Gain:** {business_impact['efficiency_gain']}%",
requirements_output,
f"**π― BDD Scenarios:**\n```gherkin\n{bdd_scenario}\n```",
"β³ Creating test scripts...",
"", ""
)
time.sleep(1.5)
test_script = generate_focused_test_script()
# Step 4: Test Execution
yield (
f"β
Scripts Ready: {story_title}",
f"**User Story:** {user_story}\n\n**ROI:** {business_impact['efficiency_gain']}% improvement",
requirements_output,
f"**π― BDD Scenarios:**\n```gherkin\n{bdd_scenario}\n```",
f"**π§ͺ Test Scripts:**\n```python\n{test_script}\n```",
"β‘ Executing tests...",
""
)
time.sleep(2)
execution_result = simulate_concise_execution(complexity, analysis['coverage'])
status_icon = "β
" if execution_result["status"] == "PASS" else "β"
execution_output = f"""**{status_icon} Test Results:** {execution_result['status']}
**Tests:** {execution_result['passed']}/{execution_result['total']} passed | **Time:** {execution_result['time']}s
**Performance:** {execution_result['performance']['response_time']}ms avg response
**Coverage:** {', '.join(execution_result['coverage_areas'])}"""
# Step 5: QA-AI Feedback
yield (
f"β
Testing Complete: {story_title}",
f"**User Story:** {user_story}\n\n**Business Value:** ${business_impact['cost_saved']} saved",
requirements_output,
f"**π― BDD Scenarios:**\n```gherkin\n{bdd_scenario}\n```",
f"**π§ͺ Test Scripts:**\n```python\n{test_script}\n```",
execution_output,
"π€ Generating AI tester feedback..."
)
time.sleep(1)
qa_feedback = generate_qa_ai_feedback(execution_result, complexity, business_impact)
# Final Result
yield (
f"π Complete: {story_title}",
f"**User Story:** {user_story}\n\n**Value Delivered:** {business_impact['time_saved_hours']} hours saved, ${business_impact['cost_saved']} cost reduction",
requirements_output,
f"**π― BDD Scenarios:**\n```gherkin\n{bdd_scenario}\n```",
f"**π§ͺ Test Scripts:**\n```python\n{test_script}\n```",
execution_output,
qa_feedback
)
except Exception as e:
yield (
"β Error occurred",
f"Error: {str(e)}",
"", "", "", "", ""
)
# Clean, focused Gradio interface
with gr.Blocks(
theme=gr.themes.Soft(),
title="Enterprise STLC-AI",
css="""
.gradio-container {
max-width: 1200px !important;
margin: 0 auto;
padding-bottom: 0 !important;
}
.header-banner {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 20px;
border-radius: 15px;
text-align: center;
margin-bottom: 20px;
}
.metrics-box {
background: #f8f9fa;
padding: 15px;
border-radius: 10px;
border-left: 4px solid #007bff;
}
.compact-accordion .accordion {
margin: 5px 0;
}
/* Remove extra spacing */
.footer {
margin-bottom: 0 !important;
padding-bottom: 0 !important;
}
.block {
margin-bottom: 0 !important;
}
/* Remove yellow highlighting/selection */
::selection {
background-color: transparent;
}
::-moz-selection {
background-color: transparent;
}
/* Ensure no extra space at bottom */
body {
margin-bottom: 0 !important;
padding-bottom: 0 !important;
}
.gradio-app {
margin-bottom: 0 !important;
padding-bottom: 0 !important;
}
"""
) as demo:
# Header
gr.HTML("""
<div class="header-banner">
<h1>π’ Enterprise STLC-AI: GenAI QA Automation</h1>
<p><strong>Transform 16-hour QA cycles into 3-minute automated workflows</strong></p>
</div>
""")
with gr.Row():
# Left Panel - Controls
with gr.Column(scale=1):
gr.Markdown("### π― Select Enterprise Scenario")
story_dropdown = gr.Dropdown(
choices=[(f"{s['title']} ({s['complexity'].title()})", str(s['id'])) for s in ENTERPRISE_STORIES],
label="Pre-built Scenarios",
value="1"
)
custom_story_input = gr.Textbox(
label="Custom Story",
placeholder="As a [role], I want [goal] so that [benefit]...",
lines=2
)
process_btn = gr.Button("π Start QA Automation", variant="primary", size="lg")
# Compact metrics
gr.HTML(f"""
<div class="metrics-box">
<h4>π Live Demo Stats</h4>
<p><strong>Scenarios:</strong> {len(ENTERPRISE_STORIES)} enterprise cases<br>
<strong>Avg Savings:</strong> 12+ hours per story<br>
<strong>Processed:</strong> {demo_controller.request_count} stories<br>
<strong>Total Saved:</strong> {demo_controller.total_time_saved:.1f} hours</p>
</div>
""")
# Right Panel - Results
with gr.Column(scale=2):
status_display = gr.Textbox(label="π Status", interactive=False)
with gr.Accordion("π Business Context", open=True):
story_output = gr.Markdown()
with gr.Accordion("π§ AI Analysis", open=True):
requirements_output = gr.Markdown()
with gr.Accordion("π― BDD Scenarios", open=False):
bdd_output = gr.Markdown()
with gr.Accordion("π§ͺ Test Scripts", open=False):
script_output = gr.Markdown()
with gr.Accordion("β‘ Test Results", open=False):
execution_output = gr.Markdown()
with gr.Accordion("π€ QA-AI Review", open=True):
feedback_output = gr.Markdown()
# Event binding
process_btn.click(
fn=process_optimized_lifecycle,
inputs=[story_dropdown, custom_story_input],
outputs=[status_display, story_output, requirements_output, bdd_output, script_output, execution_output, feedback_output]
)
# Footer with key benefits (compact, no extra spacing)
gr.HTML("""
<div style="margin: 20px 0 0 0; padding: 15px; background: #f8f9fa; border-radius: 10px;">
<h3 style="margin: 0 0 10px 0;">π― Enterprise Benefits Demonstrated</h3>
<p style="margin: 0;"><strong>β‘ Speed:</strong> 95% faster test creation | <strong>π° Cost:</strong> 75% reduction in QA effort | <strong>π― Quality:</strong> 100% coverage assurance | <strong>π€ Intelligence:</strong> AI-powered analysis & feedback</p>
<p style="margin: 5px 0 0 0; font-style: italic;">This demo shows how GenAI transforms traditional 16-hour QA cycles into 3-minute automated workflows with superior quality and coverage.</p>
</div>
""")
if __name__ == "__main__":
demo.launch(
share=False,
server_name="0.0.0.0",
server_port=7860,
show_error=True
) |