| import gradio as gr |
| import json |
| import time |
| import random |
| from datetime import datetime |
| from functools import lru_cache |
| import os |
|
|
| |
| class SimpleMonitor: |
| def __init__(self): |
| self.request_count = 0 |
| self.last_request_time = 0 |
| self.min_delay = 1.5 |
| |
| def rate_limit(self): |
| """Apply rate limiting with shorter delays""" |
| current_time = time.time() |
| if current_time - self.last_request_time < self.min_delay: |
| time.sleep(self.min_delay - (current_time - self.last_request_time)) |
| self.last_request_time = time.time() |
| self.request_count += 1 |
|
|
| |
| monitor = SimpleMonitor() |
|
|
| |
| def load_stories(): |
| try: |
| with open('dummy_user_stories.json', 'r') as f: |
| return json.load(f) |
| except: |
| return [ |
| {"id": 1, "title": "Invoice Generation", |
| "description": "As a policyholder, I want an invoice generated within 24 hours after policy issuance so I can view my premium charges."}, |
| {"id": 2, "title": "Credit Card Payment", |
| "description": "As a policyholder, I want to pay my premium using a credit card with proper validation so my payment is secure."}, |
| {"id": 3, "title": "Policy Renewal", |
| "description": "As a policyholder, I want to receive renewal notifications 30 days before expiry so I can review my coverage."}, |
| {"id": 4, "title": "Claims Submission", |
| "description": "As a policyholder, I want to submit claims online with document uploads so I can initiate the process quickly."}, |
| {"id": 5, "title": "Premium Calculator", |
| "description": "As a potential customer, I want to calculate my insurance premium based on my profile and coverage options."} |
| ] |
|
|
| STORIES = load_stories() |
|
|
| |
| @lru_cache(maxsize=50) |
| def generate_bdd_cached(story_key, story_type): |
| """Generate BDD with caching and variety based on story type""" |
| |
| bdd_templates = { |
| "invoice": """Feature: Invoice Generation System |
| As a policyholder |
| I want automated invoice generation |
| So that I can receive timely billing information |
| |
| Scenario: Successful invoice generation within SLA |
| Given I am a policyholder with an active policy "POL-12345" |
| And my policy was issued within the last 24 hours |
| And the billing system is operational |
| When the automated invoice generation process runs |
| Then an invoice should be created within 24 hours |
| And the invoice should include policy number and premium details |
| And the invoice should be sent to my registered email address |
| And the invoice status should be marked as "Generated" |