jeronimo9 commited on
Commit
3ca015f
·
verified ·
1 Parent(s): fb75cfa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +230 -119
app.py CHANGED
@@ -1,97 +1,73 @@
1
  import gradio as gr
2
  import pandas as pd
3
 
4
- # Preamble brand colors from the image
5
- PREAMBLE_COLORS = {
6
- 'white': '#081423', # Light background
7
- 'yellow': '#FFC700', # Yellow accent
8
- 'blue': '#4556E4', # Primary blue
9
- 'navy': '#1F2C6D', # Navy blue
10
- 'black': '#ECF0F6' # Dark background
11
  }
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  CUSTOM_CSS = """
14
  .gradio-container {
15
  max-width: 1200px !important;
16
  margin: auto !important;
17
  padding: 2rem !important;
18
  background-color: #081423 !important;
19
- color: #FFFFFF !important;
20
  }
21
 
22
- /* Header styling */
23
  .header {
24
- background-color: #1F2C6D;
25
  padding: 1.5rem;
26
  border-radius: 12px;
27
  margin-bottom: 2rem;
28
- color: white;
29
  }
30
 
31
- /* Product selector styling */
32
  .product-selector {
33
- background: linear-gradient(145deg, #4556E4, #1F2C6D);
34
  border-radius: 12px;
35
  padding: 1.5rem;
36
  margin-bottom: 2rem;
37
- color: white;
38
  }
39
 
40
- /* Results styling */
41
  .results-container {
42
- background: #ECF0F6;
43
  border-radius: 12px;
44
  padding: 1.5rem;
45
  margin-bottom: 2rem;
46
  }
47
 
48
- .result-card {
49
- background-color: #FFFFFF;
50
- border-radius: 8px;
51
- padding: 1rem;
52
- margin: 0.5rem;
53
- color: #081423;
54
- }
55
-
56
- /* Button styling */
57
  .primary-button {
58
  background-color: #FFC700 !important;
59
  color: #081423 !important;
60
  font-weight: bold !important;
61
- padding: 0.75rem 1.5rem !important;
62
- border-radius: 8px !important;
63
- transition: all 0.2s !important;
64
  }
65
 
66
- .primary-button:hover {
67
- transform: translateY(-2px);
68
- box-shadow: 0 4px 12px rgba(255, 199, 0, 0.3);
69
- }
70
-
71
- /* Tab styling */
72
- .tab-nav {
73
- background-color: #1F2C6D !important;
74
- border-radius: 8px !important;
75
- }
76
-
77
- .tab-nav button {
78
- color: white !important;
79
- }
80
-
81
- .tab-nav button.selected {
82
- background-color: #4556E4 !important;
83
- color: white !important;
84
- }
85
-
86
- /* Input styling */
87
- .input-row {
88
- background-color: rgba(69, 86, 228, 0.1);
89
  border-radius: 8px;
90
  padding: 1rem;
91
- margin-bottom: 1rem;
92
  }
93
 
94
- /* Recommendation panel */
95
  .recommendation-panel {
96
  background-color: #FFC700;
97
  color: #081423;
@@ -102,10 +78,93 @@ CUSTOM_CSS = """
102
  }
103
  """
104
 
105
- # [Previous code for compliance_df and calculate_roi remains the same]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
  def create_app():
108
- with gr.Blocks(css=CUSTOM_CSS, theme=gr.themes.Soft(primary_hue="orange")) as roi_app:
109
  # Header
110
  with gr.Row(elem_classes="header"):
111
  gr.Markdown(
@@ -113,90 +172,142 @@ def create_app():
113
  "[Visit Preamble.com](https://preamble.com) to learn more"
114
  )
115
 
116
- # Product Selection Section - Moved to top
117
  with gr.Row(elem_classes="product-selector"):
118
  with gr.Column():
119
- gr.Markdown("## 🎯 Find Your Ideal Preamble Solution")
120
- with gr.Row(elem_classes="input-row"):
121
- deployment_type = gr.Radio(
122
- ["Cloud/SaaS", "On-Premises"],
123
- label="How would you like to deploy?",
124
- value="Cloud/SaaS"
125
- )
126
- existing_ai = gr.Radio(
127
- ["Yes, we have existing AI applications", "No, we need a full platform"],
128
- label="Do you have existing AI applications?",
129
- value="No, we need a full platform"
130
- )
131
-
132
- with gr.Row(elem_classes="input-row"):
133
- monthly_budget = gr.Number(
134
- label="Monthly Budget ($)",
135
- value=5000,
136
- info="What's your monthly budget for AI governance?"
137
- )
138
- estimated_api_calls = gr.Number(
139
- label="Estimated Monthly API Calls",
140
- value=10000,
141
- info="Required for Guardrails pricing"
142
- )
143
-
144
- recommendation_box = gr.Markdown(
145
- "Complete the information above to get your personalized solution recommendation",
146
- elem_classes="recommendation-panel"
147
  )
 
148
 
149
  # Results section
150
  with gr.Row(elem_classes="results-container"):
151
  with gr.Column():
152
  build_roi_box = gr.Markdown(
153
- "### 🏗️ Building In-House\n**ROI:** 0%\n**Total Costs:** $0",
154
  elem_classes="result-card"
155
  )
156
  with gr.Column():
157
  preamble_roi_box = gr.Markdown(
158
- "### 🚀 Using Preamble\n**ROI:** 0%\n**Total Costs:** $0",
159
  elem_classes="result-card"
160
  )
161
 
162
- # ROI Calculator Section
163
- gr.Markdown("## 📈 Calculate Your ROI")
164
-
165
- # [Rest of the tabs and calculator remain the same]
166
-
167
- # Update functions
168
- def update_recommendation(monthly_budget, deployment_type, existing_ai, num_employees):
169
- if deployment_type == "On-Premises":
170
- return """### 🏢 Enterprise (On-Premises)
171
- **Perfect for:** Large enterprises with complex compliance needs
172
- - Full platform deployment
173
- - Complete compliance controls
174
- - Dedicated support team
175
- - Custom integrations
176
- Starting at $27,000/month"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
 
178
- if existing_ai == "Yes, we have existing AI applications" and monthly_budget <= 5000:
179
- return """### Guardrails
180
- **Perfect for:** Teams with existing AI applications
181
- - API-first implementation
182
- - $0.005 per API call
183
- - Quick integration
184
- - Usage-based pricing
185
- Estimated monthly cost: ${:,.2f}""".format(estimated_api_calls * 0.005)
186
 
187
- return """### 🚀 SaaS Platform
188
- **Perfect for:** Teams getting started with AI
189
- - Full platform features
190
- - Quick cloud deployment
191
- - Regular updates
192
- - Simple per-user pricing
193
- $50 per user/month (estimated: ${:,.2f}/month)""".format(num_employees * 50)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
195
- # [Rest of the event handlers remain the same]
 
 
 
 
 
 
 
 
 
 
 
 
196
 
197
- return roi_app
198
 
199
- # Create and launch the app
200
  app = create_app()
201
 
202
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  import pandas as pd
3
 
4
+ # Preamble brand colors from the brand guide
5
+ BRAND_COLORS = {
6
+ 'light_gray': '#081423',
7
+ 'yellow': '#1F2C6D',
8
+ 'blue': '#4556E4',
9
+ 'navy': '#FFC700',
10
+ 'dark_gray': '#ECF0F6'
11
  }
12
 
13
+ # Default compliance data
14
+ default_compliance_df = pd.DataFrame({
15
+ "Regulation": [
16
+ "SEC Reg S-P (Privacy)",
17
+ "GLBA (Financial)",
18
+ "FINRA Rules",
19
+ "Bank Secrecy Act",
20
+ "Dodd-Frank Act"
21
+ ],
22
+ "Expected Violations": [1, 1, 1, 1, 1],
23
+ "Penalty": [100000, 100000, 150000, 200000, 250000],
24
+ "Attorney Cost": [50000, 45000, 75000, 100000, 125000]
25
+ })
26
+
27
  CUSTOM_CSS = """
28
  .gradio-container {
29
  max-width: 1200px !important;
30
  margin: auto !important;
31
  padding: 2rem !important;
32
  background-color: #081423 !important;
33
+ color: #ECF0F6 !important;
34
  }
35
 
 
36
  .header {
37
+ background-color: #4556E4;
38
  padding: 1.5rem;
39
  border-radius: 12px;
40
  margin-bottom: 2rem;
 
41
  }
42
 
 
43
  .product-selector {
44
+ background: #1F2C6D;
45
  border-radius: 12px;
46
  padding: 1.5rem;
47
  margin-bottom: 2rem;
 
48
  }
49
 
 
50
  .results-container {
51
+ background: #4556E4;
52
  border-radius: 12px;
53
  padding: 1.5rem;
54
  margin-bottom: 2rem;
55
  }
56
 
 
 
 
 
 
 
 
 
 
57
  .primary-button {
58
  background-color: #FFC700 !important;
59
  color: #081423 !important;
60
  font-weight: bold !important;
 
 
 
61
  }
62
 
63
+ .result-card {
64
+ background-color: #ECF0F6;
65
+ color: #081423;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  border-radius: 8px;
67
  padding: 1rem;
68
+ margin: 0.5rem;
69
  }
70
 
 
71
  .recommendation-panel {
72
  background-color: #FFC700;
73
  color: #081423;
 
78
  }
79
  """
80
 
81
+ def recommend_preamble_solution(deployment_type, existing_ai, monthly_budget):
82
+ """
83
+ Logic for recommending Preamble solution:
84
+ - If on-prem is needed -> Enterprise
85
+ - If no existing AI:
86
+ - If budget > 5000 -> SaaS Platform
87
+ - If budget <= 5000 -> Guardrails
88
+ - If has existing AI -> Recommend Guardrails first
89
+ """
90
+ if deployment_type == "On-Premises":
91
+ return ("Enterprise", """### 🏢 Enterprise License
92
+ **Perfect for organizations that need:**
93
+ - On-premises deployment
94
+ - Complete compliance controls
95
+ - Dedicated support team
96
+ - Custom integrations
97
+ Starting at $27,000/month""")
98
+
99
+ if existing_ai == "No, we need a full platform":
100
+ if monthly_budget > 5000:
101
+ return ("SaaS", """### 🚀 SaaS Platform
102
+ **Perfect for teams getting started with AI:**
103
+ - Full platform features
104
+ - Quick cloud deployment
105
+ - Regular updates
106
+ - $50 per user/month""")
107
+ else:
108
+ return ("Guardrails", """### ⚡ Guardrails
109
+ **Start with our foundational offering:**
110
+ - Basic AI safety controls
111
+ - API-first implementation
112
+ - $0.005 per API call
113
+ - Usage-based pricing""")
114
+
115
+ return ("Guardrails", """### ⚡ Guardrails Recommended
116
+ **Perfect for existing AI applications:**
117
+ - Quick integration with your AI
118
+ - API-first implementation
119
+ - $0.005 per API call
120
+ - Usage-based pricing""")
121
+
122
+ def calculate_roi(inputs):
123
+ [num_employees, hours_saved_per_week, hourly_wage,
124
+ initial_platform_cost, num_ai_hires, avg_salary,
125
+ ai_maintenance_cost, ai_security_cost,
126
+ revenue_increase,
127
+ monthly_budget, deployment_type, existing_ai, estimated_api_calls,
128
+ compliance_data] = inputs
129
+
130
+ # Calculate savings and costs
131
+ total_hours_saved = num_employees * hours_saved_per_week * 52
132
+ labor_cost_savings = total_hours_saved * hourly_wage
133
+
134
+ # Compliance savings
135
+ compliance_savings = sum(
136
+ row["Expected Violations"] * (row["Penalty"] + row["Attorney Cost"])
137
+ for _, row in compliance_data.iterrows()
138
+ )
139
+
140
+ # Total benefits
141
+ total_benefits = labor_cost_savings + revenue_increase + compliance_savings
142
+
143
+ # In-house costs
144
+ total_costs_build = (
145
+ initial_platform_cost +
146
+ (num_ai_hires * avg_salary) +
147
+ ai_maintenance_cost +
148
+ ai_security_cost
149
+ )
150
+
151
+ # Preamble costs
152
+ solution_type, _ = recommend_preamble_solution(deployment_type, existing_ai, monthly_budget)
153
+ if solution_type == "Enterprise":
154
+ total_costs_preamble = 27000 * 12
155
+ elif solution_type == "SaaS":
156
+ total_costs_preamble = num_employees * 50 * 12
157
+ else: # Guardrails
158
+ total_costs_preamble = estimated_api_calls * 0.005 * 12
159
+
160
+ # ROI calculations
161
+ roi_build = ((total_benefits - total_costs_build) / total_costs_build) * 100 if total_costs_build else 0
162
+ roi_preamble = ((total_benefits - total_costs_preamble) / total_costs_preamble) * 100 if total_costs_preamble else 0
163
+
164
+ return roi_build, roi_preamble, total_benefits, total_costs_build, total_costs_preamble
165
 
166
  def create_app():
167
+ with gr.Blocks(css=CUSTOM_CSS, theme=gr.themes.Soft(primary_hue="blue")) as roi_app:
168
  # Header
169
  with gr.Row(elem_classes="header"):
170
  gr.Markdown(
 
172
  "[Visit Preamble.com](https://preamble.com) to learn more"
173
  )
174
 
175
+ # Product Selection
176
  with gr.Row(elem_classes="product-selector"):
177
  with gr.Column():
178
+ gr.Markdown("## Find Your Ideal Preamble Solution")
179
+ deployment_type = gr.Radio(
180
+ ["Cloud/SaaS", "On-Premises"],
181
+ label="Deployment Preference",
182
+ value="Cloud/SaaS"
183
+ )
184
+ existing_ai = gr.Radio(
185
+ ["Yes, we have existing AI applications", "No, we need a full platform"],
186
+ label="AI Implementation Status",
187
+ value="No, we need a full platform"
188
+ )
189
+ monthly_budget = gr.Number(
190
+ label="Monthly Budget ($)",
191
+ value=5000
192
+ )
193
+ estimated_api_calls = gr.Number(
194
+ label="Estimated Monthly API Calls",
195
+ value=10000,
196
+ visible=False
 
 
 
 
 
 
 
 
 
197
  )
198
+ recommendation_box = gr.Markdown(elem_classes="recommendation-panel")
199
 
200
  # Results section
201
  with gr.Row(elem_classes="results-container"):
202
  with gr.Column():
203
  build_roi_box = gr.Markdown(
204
+ "### Building In-House\n**ROI:** --%\n**Total Costs:** $0",
205
  elem_classes="result-card"
206
  )
207
  with gr.Column():
208
  preamble_roi_box = gr.Markdown(
209
+ "### Using Preamble\n**ROI:** --%\n**Total Costs:** $0",
210
  elem_classes="result-card"
211
  )
212
 
213
+ # Calculator Inputs
214
+ with gr.Tabs():
215
+ with gr.Tab("Organization Details"):
216
+ num_employees = gr.Slider(
217
+ label="Number of Employees",
218
+ minimum=1, maximum=1000, value=215
219
+ )
220
+ hours_saved_per_week = gr.Slider(
221
+ label="Hours Saved per Week per Employee",
222
+ minimum=0, maximum=40, value=6.3
223
+ )
224
+ hourly_wage = gr.Slider(
225
+ label="Average Hourly Wage ($)",
226
+ minimum=10, maximum=200, value=62
227
+ )
228
+
229
+ with gr.Tab("Build Costs"):
230
+ initial_platform_cost = gr.Number(label="Initial Development Cost ($)", value=100000)
231
+ num_ai_hires = gr.Number(label="Number of AI Hires", value=1)
232
+ avg_salary = gr.Number(label="Average Annual Salary ($)", value=150000)
233
+ ai_maintenance_cost = gr.Number(label="Annual Maintenance ($)", value=20000)
234
+ ai_security_cost = gr.Number(label="Security & Compliance ($)", value=10000)
235
+
236
+ with gr.Tab("Compliance"):
237
+ compliance_data = gr.Dataframe(
238
+ value=default_compliance_df,
239
+ headers=["Regulation", "Expected Violations", "Penalty", "Attorney Cost"],
240
+ datatype="pandas"
241
+ )
242
+
243
+ with gr.Tab("Benefits"):
244
+ revenue_increase = gr.Number(
245
+ label="Estimated Annual Revenue Increase ($)",
246
+ value=50000
247
+ )
248
+
249
+ calculate_button = gr.Button("Calculate ROI", elem_classes="primary-button")
250
+
251
+ def update_results(*inputs):
252
+ roi_build, roi_preamble, benefits, costs_build, costs_preamble = calculate_roi(inputs)
253
 
254
+ build_text = (
255
+ f"### 🏗️ Building In-House\n"
256
+ f"**ROI:** {roi_build:,.1f}%\n"
257
+ f"**Total Costs:** ${costs_build:,.2f}\n"
258
+ f"**Total Benefits:** ${benefits:,.2f}"
259
+ )
 
 
260
 
261
+ preamble_text = (
262
+ f"### 🚀 Using Preamble\n"
263
+ f"**ROI:** {roi_preamble:,.1f}%\n"
264
+ f"**Total Costs:** ${costs_preamble:,.2f}\n"
265
+ f"**Total Benefits:** ${benefits:,.2f}"
266
+ )
267
+
268
+ return build_text, preamble_text
269
+
270
+ def update_api_calls_visibility(existing_ai, deployment_type):
271
+ # Show API calls input only for Guardrails candidates
272
+ should_show = (
273
+ deployment_type != "On-Premises" and
274
+ (existing_ai == "Yes, we have existing AI applications" or
275
+ monthly_budget <= 5000)
276
+ )
277
+ return gr.update(visible=should_show)
278
+
279
+ # Update recommendation when inputs change
280
+ for input_elem in [deployment_type, existing_ai, monthly_budget]:
281
+ input_elem.change(
282
+ fn=lambda d, e, b: recommend_preamble_solution(d, e, b)[1],
283
+ inputs=[deployment_type, existing_ai, monthly_budget],
284
+ outputs=[recommendation_box]
285
+ )
286
+
287
+ # Update API calls visibility
288
+ if input_elem in [deployment_type, existing_ai]:
289
+ input_elem.change(
290
+ fn=update_api_calls_visibility,
291
+ inputs=[existing_ai, deployment_type],
292
+ outputs=[estimated_api_calls]
293
+ )
294
 
295
+ # Connect calculate button
296
+ calculate_button.click(
297
+ fn=update_results,
298
+ inputs=[
299
+ num_employees, hours_saved_per_week, hourly_wage,
300
+ initial_platform_cost, num_ai_hires, avg_salary,
301
+ ai_maintenance_cost, ai_security_cost,
302
+ revenue_increase,
303
+ monthly_budget, deployment_type, existing_ai, estimated_api_calls,
304
+ compliance_data
305
+ ],
306
+ outputs=[build_roi_box, preamble_roi_box]
307
+ )
308
 
309
+ return roi_app
310
 
 
311
  app = create_app()
312
 
313
  if __name__ == "__main__":