jeronimo9 commited on
Commit
e69e3f7
Β·
verified Β·
1 Parent(s): beb523f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +201 -114
app.py CHANGED
@@ -2,134 +2,175 @@ import gradio as gr
2
  import pandas as pd
3
 
4
  PREAMBLE_COLORS = {
5
- 'light': '#081423', # Light bg
6
- 'yellow': '#1F2C6D', # Yellow accent
7
- 'blue': '#4556E4', # Primary blue
8
- 'navy': '#FFC700', # Navy
9
- 'dark': '#ECF0F6' # Dark bg
10
  }
11
 
12
  CUSTOM_CSS = """
13
- .gradio-container {
14
- max-width: 1200px !important;
15
- margin: auto !important;
16
- padding: 2rem !important;
 
 
17
  }
 
18
 
19
- /* Preamble branded elements */
20
- .header {
21
- background-color: #081423;
22
- padding: 1.5rem;
23
- border-radius: 12px;
24
- margin-bottom: 2rem;
25
- }
 
 
 
 
26
 
27
- .header h1 {
28
- color: white;
29
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- .results-container {
32
- background: linear-gradient(145deg, #4556E4, #1F2C6D);
33
- border-radius: 12px;
34
- padding: 1.5rem;
35
- margin-bottom: 2rem;
36
- color: white;
37
- }
38
 
39
- .primary-button {
40
- background-color: #FFC700 !important;
41
- color: #081423 !important;
42
- }
43
 
44
- /* Solution selector styling */
45
- .solution-card {
46
- border: 2px solid #4556E4;
47
- border-radius: 8px;
48
- padding: 1rem;
49
- margin: 0.5rem;
50
- }
 
51
 
52
- .solution-card.recommended {
53
- border-color: #FFC700;
54
- background-color: rgba(255, 199, 0, 0.1);
55
- }
56
- """
57
 
58
- # Enhanced compliance data
59
- default_compliance_df = pd.DataFrame({
60
- "Regulation": [
61
- "SEC Reg S-P (Privacy)",
62
- "GLBA (Financial)",
63
- "FINRA Rules",
64
- "Bank Secrecy Act",
65
- "Dodd-Frank Act"
66
- ],
67
- "Expected Violations": [1, 1, 1, 1, 1],
68
- "Penalty": [100000, 100000, 150000, 200000, 250000],
69
- "Attorney Cost": [50000, 45000, 75000, 100000, 125000]
70
- })
71
-
72
- def recommend_solution(num_employees, compliance_needs, budget_constraint):
73
- if num_employees <= 50 and budget_constraint == "Low":
74
- return "Guardrails"
75
- elif num_employees <= 500 and budget_constraint in ["Low", "Medium"]:
76
- return "SaaS"
77
- else:
78
- return "Enterprise"
79
 
80
  def create_app():
81
  with gr.Blocks(css=CUSTOM_CSS) as roi_app:
82
- # Header with Preamble branding
83
  with gr.Row(elem_classes="header"):
84
  gr.Markdown(
85
  "# πŸ“Š Preamble AI ROI Calculator\n"
86
- "[Visit Preamble.com](https://preamble.com) to learn more"
87
  )
88
 
89
  # Results section
90
  with gr.Row(elem_classes="results-container"):
91
  with gr.Column():
92
- build_roi_box = gr.Markdown("### Building In-House")
 
 
93
  with gr.Column():
94
- preamble_roi_box = gr.Markdown("### Using Preamble")
 
 
95
 
96
- # Solution Recommendation
97
  with gr.Row():
98
  with gr.Column():
99
- gr.Markdown("## 🎯 Find Your Ideal Preamble Solution")
100
- budget_constraint = gr.Radio(
101
- ["Low", "Medium", "High"],
102
- label="Budget Constraint",
103
- info="Select your budget level"
104
  )
105
- compliance_needs = gr.Checkboxgroup(
106
- ["Privacy", "Financial", "Healthcare", "Custom"],
107
- label="Compliance Requirements"
 
 
108
  )
109
-
110
- solution_recommendation = gr.Markdown(
111
- "Complete the information above to get a solution recommendation",
112
- elem_classes="solution-card"
 
 
 
 
 
 
113
  )
114
 
115
  # Main tabs
116
  with gr.Tabs():
117
- # Organization Details tab
118
  with gr.Tab("🏒 Organization Details"):
119
  num_employees = gr.Slider(
120
  label="Number of Employees",
121
  minimum=1,
122
- maximum=1000,
123
- value=215
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  )
125
- # ... rest of organization details ...
126
 
127
- # Compliance tab with enhanced UI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  with gr.Tab("πŸ›‘οΈ Compliance"):
129
- gr.Markdown("""
130
- ## US Financial Compliance Requirements
131
- Select applicable regulations and adjust expected violation rates
132
- """)
133
  compliance_data = gr.Dataframe(
134
  value=default_compliance_df,
135
  headers=["Regulation", "Expected Violations", "Penalty", "Attorney Cost"],
@@ -137,45 +178,91 @@ def create_app():
137
  label="US Financial Regulations"
138
  )
139
 
140
- # ... other tabs ...
 
 
 
 
 
 
 
 
 
141
 
142
  # Calculate button
143
- calculate_button = gr.Button(
144
- "Calculate ROI",
145
- elem_classes="primary-button"
146
- )
147
 
148
- # Update functions
149
- def update_solution_recommendation(employees, budget, compliance):
150
- solution = recommend_solution(employees, compliance, budget)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
- recommendations = {
153
- "Guardrails": "Recommended for smaller teams or API-first implementations",
154
- "SaaS": "Perfect for mid-sized organizations needing quick deployment",
155
- "Enterprise": "Ideal for large organizations with complex compliance needs"
156
- }
 
 
 
 
 
157
 
158
- return f"""### Recommended Solution: {solution}
159
- {recommendations[solution]}
 
 
 
 
160
 
161
- **Key Benefits:**
162
- - {'Lowest cost, pay-per-call pricing' if solution == 'Guardrails' else 'Simple per-user pricing' if solution == 'SaaS' else 'Full enterprise features'}
163
- - {'API-first implementation' if solution == 'Guardrails' else 'Quick cloud deployment' if solution == 'SaaS' else 'On-premises deployment'}
164
- - {'Perfect for developers' if solution == 'Guardrails' else 'Great for business users' if solution == 'SaaS' else 'Complete compliance controls'}
165
- """
 
 
 
166
 
167
  # Connect the recommendation update
168
- for input_elem in [num_employees, budget_constraint, compliance_needs]:
169
  input_elem.change(
170
- fn=update_solution_recommendation,
171
- inputs=[num_employees, budget_constraint, compliance_needs],
172
- outputs=[solution_recommendation]
173
  )
174
 
175
- # ... rest of the calculation logic ...
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
  return roi_app
178
 
 
179
  app = create_app()
180
 
181
  if __name__ == "__main__":
 
2
  import pandas as pd
3
 
4
  PREAMBLE_COLORS = {
5
+ 'light': '#081423',
6
+ 'yellow': '#1F2C6D',
7
+ 'blue': '#4556E4',
8
+ 'navy': '#FFC700',
9
+ 'dark': '#ECF0F6'
10
  }
11
 
12
  CUSTOM_CSS = """
13
+ /* Previous CSS styles remain the same */
14
+ .recommendation-panel {
15
+ background-color: rgba(69, 86, 228, 0.1);
16
+ border-radius: 8px;
17
+ padding: 1rem;
18
+ margin-top: 1rem;
19
  }
20
+ """
21
 
22
+ def calculate_roi(
23
+ num_employees, hours_saved_per_week, hourly_wage,
24
+ initial_platform_cost, num_ai_hires, avg_salary,
25
+ ai_maintenance_cost, ai_security_cost,
26
+ revenue_increase,
27
+ monthly_budget, deployment_type, existing_ai, estimated_api_calls,
28
+ compliance_data
29
+ ):
30
+ # Annual labor savings
31
+ total_hours_saved = num_employees * hours_saved_per_week * 52
32
+ labor_cost_savings = total_hours_saved * hourly_wage
33
 
34
+ # Calculate compliance savings
35
+ compliance_savings = 0
36
+ if compliance_data is not None:
37
+ try:
38
+ if isinstance(compliance_data, pd.DataFrame):
39
+ df = compliance_data
40
+ else:
41
+ df = pd.DataFrame(compliance_data)
42
+ for index, row in df.iterrows():
43
+ try:
44
+ violations = float(row["Expected Violations"])
45
+ penalty = float(row["Penalty"])
46
+ attorney = float(row["Attorney Cost"])
47
+ compliance_savings += violations * (penalty + attorney)
48
+ except Exception:
49
+ continue
50
+ except Exception:
51
+ compliance_savings = 0
52
 
53
+ # Total benefits
54
+ total_benefits = labor_cost_savings + revenue_increase + compliance_savings
 
 
 
 
 
55
 
56
+ # Calculate costs for building in-house
57
+ total_costs_build = initial_platform_cost + (num_ai_hires * avg_salary) + ai_maintenance_cost + ai_security_cost
 
 
58
 
59
+ # Calculate Preamble costs based on selected options
60
+ if deployment_type == "On-Premises":
61
+ total_costs_preamble = 27000 * 12 # Fixed cost for enterprise
62
+ else: # Cloud/SaaS
63
+ if monthly_budget <= 10000: # Guardrails tier
64
+ total_costs_preamble = estimated_api_calls * 0.005 * 12
65
+ else: # SaaS tier
66
+ total_costs_preamble = num_employees * 50 * 12 # $50 per user per month
67
 
68
+ # ROI calculations
69
+ roi_build = ((total_benefits - total_costs_build) / total_costs_build) * 100 if total_costs_build else 0
70
+ roi_preamble = ((total_benefits - total_costs_preamble) / total_costs_preamble) * 100 if total_costs_preamble else 0
 
 
71
 
72
+ return roi_build, roi_preamble, total_benefits, total_costs_build, total_costs_preamble
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  def create_app():
75
  with gr.Blocks(css=CUSTOM_CSS) as roi_app:
76
+ # Header
77
  with gr.Row(elem_classes="header"):
78
  gr.Markdown(
79
  "# πŸ“Š Preamble AI ROI Calculator\n"
80
+ "[Visit Preamble.com](https://preamble.com/) to learn more"
81
  )
82
 
83
  # Results section
84
  with gr.Row(elem_classes="results-container"):
85
  with gr.Column():
86
+ build_roi_box = gr.Markdown(
87
+ "### πŸ—οΏ½οΏ½ Building In-House\n**ROI:** 0%\n**Total Costs:** $0"
88
+ )
89
  with gr.Column():
90
+ preamble_roi_box = gr.Markdown(
91
+ "### πŸš€ Using Preamble\n**ROI:** 0%\n**Total Costs:** $0"
92
+ )
93
 
94
+ # Product Selection Section
95
  with gr.Row():
96
  with gr.Column():
97
+ gr.Markdown("## 🎯 Select Your Preamble Solution")
98
+ monthly_budget = gr.Number(
99
+ label="Monthly Budget ($)",
100
+ value=50000,
101
+ info="Enter your monthly budget for AI governance"
102
  )
103
+ deployment_type = gr.Radio(
104
+ ["Cloud/SaaS", "On-Premises"],
105
+ label="Deployment Type",
106
+ value="Cloud/SaaS",
107
+ info="Choose your preferred deployment model"
108
  )
109
+ existing_ai = gr.Radio(
110
+ ["Yes, we have existing AI applications", "No, we need a full platform"],
111
+ label="Existing AI Applications",
112
+ value="No, we need a full platform",
113
+ info="Tell us about your current AI implementation"
114
+ )
115
+ estimated_api_calls = gr.Number(
116
+ label="Estimated Monthly API Calls",
117
+ value=1000000,
118
+ info="Required for Guardrails pricing calculation"
119
  )
120
 
121
  # Main tabs
122
  with gr.Tabs():
123
+ # Organization Details
124
  with gr.Tab("🏒 Organization Details"):
125
  num_employees = gr.Slider(
126
  label="Number of Employees",
127
  minimum=1,
128
+ maximum=5000,
129
+ value=200,
130
+ info="How many employees will use the solution?"
131
+ )
132
+ hours_saved_per_week = gr.Slider(
133
+ label="Hours Saved per Week per Employee",
134
+ minimum=0,
135
+ maximum=40,
136
+ value=6.3,
137
+ info="Estimated time savings per employee"
138
+ )
139
+ hourly_wage = gr.Slider(
140
+ label="Average Hourly Wage ($)",
141
+ minimum=10,
142
+ maximum=200,
143
+ value=62,
144
+ info="Average employee hourly compensation"
145
  )
 
146
 
147
+ # Build Costs
148
+ with gr.Tab("πŸ”¨ Build Costs"):
149
+ initial_platform_cost = gr.Number(
150
+ label="Initial Platform Development Cost ($)",
151
+ value=1000000
152
+ )
153
+ with gr.Row():
154
+ num_ai_hires = gr.Number(
155
+ label="Number of AI Personnel",
156
+ value=1
157
+ )
158
+ avg_salary = gr.Number(
159
+ label="Average Annual Salary ($)",
160
+ value=200000
161
+ )
162
+ with gr.Row():
163
+ ai_maintenance_cost = gr.Number(
164
+ label="Annual Maintenance Costs ($)",
165
+ value=500000
166
+ )
167
+ ai_security_cost = gr.Number(
168
+ label="Security & Compliance Costs ($)",
169
+ value=250000
170
+ )
171
+
172
+ # Compliance
173
  with gr.Tab("πŸ›‘οΈ Compliance"):
 
 
 
 
174
  compliance_data = gr.Dataframe(
175
  value=default_compliance_df,
176
  headers=["Regulation", "Expected Violations", "Penalty", "Attorney Cost"],
 
178
  label="US Financial Regulations"
179
  )
180
 
181
+ # Benefits
182
+ with gr.Tab("πŸ“ˆ Benefits"):
183
+ revenue_increase = gr.Number(
184
+ label="Estimated Annual Revenue Increase ($)",
185
+ value=50000,
186
+ info="Projected revenue growth from AI implementation"
187
+ )
188
+
189
+ # Product Recommendation Display
190
+ recommendation_box = gr.Markdown(elem_classes="recommendation-panel")
191
 
192
  # Calculate button
193
+ calculate_button = gr.Button("Calculate ROI", elem_classes="primary-button")
 
 
 
194
 
195
+ def update_recommendation(monthly_budget, deployment_type, existing_ai, num_employees):
196
+ if deployment_type == "On-Premises":
197
+ return """### 🏒 Enterprise (On-Premises)
198
+ **Recommended Solution**: Full Enterprise Platform
199
+ - Complete compliance controls
200
+ - On-premises deployment
201
+ - Dedicated support team
202
+ - Custom integrations
203
+ Price: Starting at $27,000/month"""
204
+
205
+ if existing_ai == "Yes, we have existing AI applications" and monthly_budget <= 5000:
206
+ return """### ⚑ Guardrails
207
+ **Recommended Solution**: API-First Implementation
208
+ - Pay-per-call pricing at $0.005/call
209
+ - Perfect for existing AI applications
210
+ - Quick API integration
211
+ - Flexible scaling
212
+ Estimated Cost: Based on API usage"""
213
 
214
+ return """### πŸš€ SaaS Platform
215
+ **Recommended Solution**: Cloud Platform
216
+ - $50 per user per month
217
+ - Quick cloud deployment
218
+ - Full platform features
219
+ - Regular updates
220
+ Estimated Monthly Cost: ${:,.2f}""".format(num_employees * 50)
221
+
222
+ def update_results(*inputs):
223
+ roi_build, roi_preamble, benefits, costs_build, costs_preamble = calculate_roi(*inputs)
224
 
225
+ build_text = (
226
+ f"### πŸ—οΈ Building In-House\n"
227
+ f"**ROI:** {roi_build:,.1f}%\n"
228
+ f"**Total Costs:** ${costs_build:,.2f}\n"
229
+ f"**Total Benefits:** ${benefits:,.2f}"
230
+ )
231
 
232
+ preamble_text = (
233
+ f"### πŸš€ Using Preamble\n"
234
+ f"**ROI:** {roi_preamble:,.1f}%\n"
235
+ f"**Total Costs:** ${costs_preamble:,.2f}\n"
236
+ f"**Total Benefits:** ${benefits:,.2f}"
237
+ )
238
+
239
+ return build_text, preamble_text
240
 
241
  # Connect the recommendation update
242
+ for input_elem in [monthly_budget, deployment_type, existing_ai, num_employees]:
243
  input_elem.change(
244
+ fn=update_recommendation,
245
+ inputs=[monthly_budget, deployment_type, existing_ai, num_employees],
246
+ outputs=[recommendation_box]
247
  )
248
 
249
+ # Connect the calculate button
250
+ calculate_button.click(
251
+ fn=update_results,
252
+ inputs=[
253
+ num_employees, hours_saved_per_week, hourly_wage,
254
+ initial_platform_cost, num_ai_hires, avg_salary,
255
+ ai_maintenance_cost, ai_security_cost,
256
+ revenue_increase,
257
+ monthly_budget, deployment_type, existing_ai, estimated_api_calls,
258
+ compliance_data
259
+ ],
260
+ outputs=[build_roi_box, preamble_roi_box]
261
+ )
262
 
263
  return roi_app
264
 
265
+ # Create and launch the app
266
  app = create_app()
267
 
268
  if __name__ == "__main__":