|
|
import gradio as gr |
|
|
import json |
|
|
import time |
|
|
import random |
|
|
from datetime import datetime, timedelta |
|
|
from functools import lru_cache |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
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: |
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
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""" |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
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'])}""" |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
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)}", |
|
|
"", "", "", "", "" |
|
|
) |
|
|
|
|
|
|
|
|
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: |
|
|
|
|
|
|
|
|
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(): |
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
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> |
|
|
""") |
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
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] |
|
|
) |
|
|
|
|
|
|
|
|
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 |
|
|
) |