jeronimo9 commited on
Commit
beb523f
·
verified ·
1 Parent(s): 86b214d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +117 -247
app.py CHANGED
@@ -1,6 +1,14 @@
1
  import gradio as gr
2
  import pandas as pd
3
 
 
 
 
 
 
 
 
 
4
  CUSTOM_CSS = """
5
  .gradio-container {
6
  max-width: 1200px !important;
@@ -8,235 +16,128 @@ CUSTOM_CSS = """
8
  padding: 2rem !important;
9
  }
10
 
11
- /* Dark theme styles */
12
- .dark {
13
- background-color: #1a1a1a;
14
- color: #ffffff;
15
- }
16
-
17
- /* Results styling */
18
- .results-container {
19
- background: linear-gradient(145deg, #2d2d2d, #363636);
20
- border-radius: 12px;
21
  padding: 1.5rem;
 
22
  margin-bottom: 2rem;
23
- box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
24
  }
25
 
26
- .result-card {
27
- background-color: #2d2d2d;
28
- border-radius: 8px;
29
- padding: 1rem;
30
- margin: 0.5rem;
31
  }
32
 
33
- /* Tab styling */
34
- .tabs {
35
- margin-top: 1rem;
36
- }
37
-
38
- .tab-selected {
39
- border-bottom: 2px solid #f4511e !important;
40
  }
41
 
42
- /* Button styling */
43
  .primary-button {
44
- background-color: #f4511e !important;
45
- color: white !important;
46
- padding: 1rem 2rem !important;
47
- border-radius: 8px !important;
48
- font-weight: 600 !important;
49
- transition: all 0.2s !important;
50
  }
51
 
52
- .primary-button:hover {
53
- transform: translateY(-2px);
54
- box-shadow: 0 4px 12px rgba(244, 81, 30, 0.3);
55
- }
56
-
57
- /* Slider customization */
58
- .slider-track {
59
- background-color: #404040;
60
  }
61
 
62
- .slider-track-fill {
63
- background-color: #f4511e;
 
64
  }
65
  """
66
 
67
- # Default compliance data
68
  default_compliance_df = pd.DataFrame({
69
- "Regulation": ["MNPI", "GLBA", "HIPAA"],
70
- "Expected Violations": [1, 1, 1],
71
- "Penalty": [50000, 75000, 100000],
72
- "Attorney Cost": [25000, 30000, 40000]
 
 
 
 
 
 
73
  })
74
 
75
- def calculate_roi(num_employees, hours_saved_per_week, hourly_wage,
76
- initial_platform_cost, num_ai_hires, avg_salary,
77
- ai_maintenance_cost, ai_security_cost,
78
- revenue_increase,
79
- preamble_cost_per_user, preamble_deployment, estimated_api_calls,
80
- compliance_data):
81
- # Annual labor savings
82
- total_hours_saved = num_employees * hours_saved_per_week * 52
83
- labor_cost_savings = total_hours_saved * hourly_wage
84
-
85
- # Calculate compliance savings
86
- compliance_savings = 0
87
- if compliance_data is not None:
88
- try:
89
- if isinstance(compliance_data, pd.DataFrame):
90
- df = compliance_data
91
- else:
92
- df = pd.DataFrame(compliance_data)
93
- for index, row in df.iterrows():
94
- try:
95
- violations = float(row["Expected Violations"])
96
- penalty = float(row["Penalty"])
97
- attorney = float(row["Attorney Cost"])
98
- compliance_savings += violations * (penalty + attorney)
99
- except Exception:
100
- continue
101
- except Exception:
102
- compliance_savings = 0
103
-
104
- # Total benefits
105
- total_benefits = labor_cost_savings + revenue_increase + compliance_savings
106
-
107
- # Calculate costs
108
- total_costs_build = initial_platform_cost + (num_ai_hires * avg_salary) + ai_maintenance_cost + ai_security_cost
109
-
110
- # Preamble costs based on deployment model
111
- if preamble_deployment == "SaaS":
112
- total_costs_preamble = num_employees * preamble_cost_per_user * 12
113
- elif preamble_deployment == "On-Prem (Fixed $27K/mo)":
114
- total_costs_preamble = 27000 * 12
115
- else: # Guardrails option
116
- total_costs_preamble = estimated_api_calls * 0.005 * 12
117
-
118
- # ROI calculations
119
- roi_build = ((total_benefits - total_costs_build) / total_costs_build) * 100 if total_costs_build else 0
120
- roi_preamble = ((total_benefits - total_costs_preamble) / total_costs_preamble) * 100 if total_costs_preamble else 0
121
-
122
- return roi_build, roi_preamble, total_benefits, total_costs_build, total_costs_preamble
123
 
124
  def create_app():
125
- with gr.Blocks(css=CUSTOM_CSS, theme=gr.themes.Soft(primary_hue="orange")) as roi_app:
126
- # Header
127
- gr.Markdown("# 📊 Generative AI ROI Calculator")
 
 
 
 
128
 
129
  # Results section
130
  with gr.Row(elem_classes="results-container"):
131
  with gr.Column():
132
- build_roi_box = gr.Markdown(
133
- value="### 🏗️ Building In-House\n**ROI:** 0%\n**Total Costs:** $0",
134
- elem_classes="result-card"
135
- )
136
  with gr.Column():
137
- preamble_roi_box = gr.Markdown(
138
- value="### 🚀 Using Preamble\n**ROI:** 0%\n**Total Costs:** $0",
139
- elem_classes="result-card"
140
- )
141
-
142
- # Main content tabs
143
- with gr.Tabs(elem_classes="tabs"):
144
- # Organization Details
145
- with gr.Tab("🏢 Organization Details", elem_classes="tab"):
146
- with gr.Group():
147
- num_employees = gr.Slider(
148
- label="Number of Employees Impacted",
149
- minimum=1,
150
- maximum=1000,
151
- value=215,
152
- step=1,
153
- info="How many employees will use the AI solution?"
154
- )
155
- hours_saved_per_week = gr.Slider(
156
- label="Hours Saved per Week per Employee",
157
- minimum=0,
158
- maximum=40,
159
- value=6.3,
160
- step=0.1,
161
- info="Estimated time savings per employee"
162
- )
163
- hourly_wage = gr.Slider(
164
- label="Average Hourly Wage ($)",
165
- minimum=10,
166
- maximum=200,
167
- value=62,
168
- step=1,
169
- info="Average employee hourly compensation"
170
- )
171
 
172
- # Preamble Options
173
- with gr.Tab("💼 Preamble Options"):
174
- preamble_cost_per_user = gr.Slider(
175
- label="Preamble SaaS Cost per User per Month ($)",
176
- minimum=10,
177
- maximum=200,
178
- value=50,
179
- step=10,
180
- info="Monthly cost per user for SaaS deployment"
 
 
 
181
  )
182
- preamble_deployment = gr.Radio(
183
- choices=["SaaS", "On-Prem (Fixed $27K/mo)", "Guardrails ($0.005 per API call)"],
184
- label="Deployment Model",
185
- value="SaaS",
186
- info="Choose your preferred deployment option"
187
  )
188
- estimated_api_calls = gr.Number(
189
- label="Estimated Monthly API Calls (for Guardrails)",
190
- value=10000,
191
- info="Required only for Guardrails option"
 
 
 
 
 
 
192
  )
 
193
 
194
- # Compliance
195
  with gr.Tab("🛡️ Compliance"):
 
 
 
 
196
  compliance_data = gr.Dataframe(
197
  value=default_compliance_df,
198
  headers=["Regulation", "Expected Violations", "Penalty", "Attorney Cost"],
199
  datatype="pandas",
200
- label="Compliance Prevention Savings"
201
  )
202
 
203
- # Build Costs
204
- with gr.Tab("🔨 Build Costs"):
205
- initial_platform_cost = gr.Number(
206
- label="Initial Platform Development Cost ($)",
207
- value=100000,
208
- info="One-time cost to develop the platform"
209
- )
210
- with gr.Row():
211
- num_ai_hires = gr.Number(
212
- label="Number of AI Personnel",
213
- value=1,
214
- info="Required AI specialists"
215
- )
216
- avg_salary = gr.Number(
217
- label="Average Annual Salary ($)",
218
- value=150000,
219
- info="Average annual salary per AI hire"
220
- )
221
- with gr.Row():
222
- ai_maintenance_cost = gr.Number(
223
- label="Annual Maintenance Costs ($)",
224
- value=20000,
225
- info="Yearly platform maintenance"
226
- )
227
- ai_security_cost = gr.Number(
228
- label="Security & Compliance Costs ($)",
229
- value=10000,
230
- info="Annual security and compliance expenses"
231
- )
232
-
233
- # Benefits
234
- with gr.Tab("📈 Benefits"):
235
- revenue_increase = gr.Number(
236
- label="Estimated Annual Revenue Increase ($)",
237
- value=50000,
238
- info="Projected revenue growth from AI implementation"
239
- )
240
 
241
  # Calculate button
242
  calculate_button = gr.Button(
@@ -244,68 +145,37 @@ def create_app():
244
  elem_classes="primary-button"
245
  )
246
 
247
- # State for employee count sync
248
- employee_count_state = gr.State(value=215)
249
-
250
- def update_results(num_employees, hours_saved_per_week, hourly_wage,
251
- initial_platform_cost, num_ai_hires, avg_salary,
252
- ai_maintenance_cost, ai_security_cost,
253
- revenue_increase,
254
- preamble_cost_per_user, preamble_deployment, estimated_api_calls,
255
- compliance_data):
256
 
257
- roi_build, roi_preamble, benefits, costs_build, costs_preamble = calculate_roi(
258
- num_employees, hours_saved_per_week, hourly_wage,
259
- initial_platform_cost, num_ai_hires, avg_salary,
260
- ai_maintenance_cost, ai_security_cost,
261
- revenue_increase,
262
- preamble_cost_per_user, preamble_deployment, estimated_api_calls,
263
- compliance_data
264
- )
265
-
266
- build_text = (
267
- f"### 🏗️ Building In-House\n"
268
- f"**ROI:** {roi_build:,.1f}%\n"
269
- f"**Total Costs:** ${costs_build:,.2f}\n"
270
- f"**Total Benefits:** ${benefits:,.2f}"
271
- )
272
-
273
- preamble_text = (
274
- f"### 🚀 Using Preamble\n"
275
- f"**ROI:** {roi_preamble:,.1f}%\n"
276
- f"**Total Costs:** ${costs_preamble:,.2f}\n"
277
- f"**Total Benefits:** ${benefits:,.2f}"
278
  )
279
 
280
- return build_text, preamble_text
281
-
282
- # Connect the calculate button
283
- calculate_button.click(
284
- fn=update_results,
285
- inputs=[
286
- num_employees, hours_saved_per_week, hourly_wage,
287
- initial_platform_cost, num_ai_hires, avg_salary,
288
- ai_maintenance_cost, ai_security_cost,
289
- revenue_increase,
290
- preamble_cost_per_user, preamble_deployment, estimated_api_calls,
291
- compliance_data
292
- ],
293
- outputs=[build_roi_box, preamble_roi_box]
294
- )
295
-
296
- # Sync employee count between tabs
297
- def sync_employee_count(count):
298
- return count
299
-
300
- num_employees.change(
301
- fn=sync_employee_count,
302
- inputs=[num_employees],
303
- outputs=[employee_count_state]
304
- )
305
 
306
  return roi_app
307
 
308
- # Create and launch the app
309
  app = create_app()
310
 
311
  if __name__ == "__main__":
 
1
  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;
 
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"],
136
  datatype="pandas",
137
+ label="US Financial Regulations"
138
  )
139
 
140
+ # ... other tabs ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
  # Calculate button
143
  calculate_button = gr.Button(
 
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__":