JanviMl commited on
Commit
f965200
·
verified ·
1 Parent(s): 4933f63

Create app_stable.py

Browse files
Files changed (1) hide show
  1. app_stable.py +67 -0
app_stable.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import time
4
+ import random
5
+ from datetime import datetime
6
+ from functools import lru_cache
7
+ import os
8
+
9
+ # Performance monitoring
10
+ class SimpleMonitor:
11
+ def __init__(self):
12
+ self.request_count = 0
13
+ self.last_request_time = 0
14
+ self.min_delay = 1.5 # Reduced from 2 seconds for better UX
15
+
16
+ def rate_limit(self):
17
+ """Apply rate limiting with shorter delays"""
18
+ current_time = time.time()
19
+ if current_time - self.last_request_time < self.min_delay:
20
+ time.sleep(self.min_delay - (current_time - self.last_request_time))
21
+ self.last_request_time = time.time()
22
+ self.request_count += 1
23
+
24
+ # Initialize monitor
25
+ monitor = SimpleMonitor()
26
+
27
+ # Load data with fallbacks
28
+ def load_stories():
29
+ try:
30
+ with open('dummy_user_stories.json', 'r') as f:
31
+ return json.load(f)
32
+ except:
33
+ return [
34
+ {"id": 1, "title": "Invoice Generation",
35
+ "description": "As a policyholder, I want an invoice generated within 24 hours after policy issuance so I can view my premium charges."},
36
+ {"id": 2, "title": "Credit Card Payment",
37
+ "description": "As a policyholder, I want to pay my premium using a credit card with proper validation so my payment is secure."},
38
+ {"id": 3, "title": "Policy Renewal",
39
+ "description": "As a policyholder, I want to receive renewal notifications 30 days before expiry so I can review my coverage."},
40
+ {"id": 4, "title": "Claims Submission",
41
+ "description": "As a policyholder, I want to submit claims online with document uploads so I can initiate the process quickly."},
42
+ {"id": 5, "title": "Premium Calculator",
43
+ "description": "As a potential customer, I want to calculate my insurance premium based on my profile and coverage options."}
44
+ ]
45
+
46
+ STORIES = load_stories()
47
+
48
+ # Optimized response generation with variety
49
+ @lru_cache(maxsize=50)
50
+ def generate_bdd_cached(story_key, story_type):
51
+ """Generate BDD with caching and variety based on story type"""
52
+
53
+ bdd_templates = {
54
+ "invoice": """Feature: Invoice Generation System
55
+ As a policyholder
56
+ I want automated invoice generation
57
+ So that I can receive timely billing information
58
+
59
+ Scenario: Successful invoice generation within SLA
60
+ Given I am a policyholder with an active policy "POL-12345"
61
+ And my policy was issued within the last 24 hours
62
+ And the billing system is operational
63
+ When the automated invoice generation process runs
64
+ Then an invoice should be created within 24 hours
65
+ And the invoice should include policy number and premium details
66
+ And the invoice should be sent to my registered email address
67
+ And the invoice status should be marked as "Generated"