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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
# Constants and styling
|
| 5 |
+
CUSTOM_CSS = """
|
| 6 |
+
.gradio-container {
|
| 7 |
+
max-width: 1200px !important;
|
| 8 |
+
margin: auto;
|
| 9 |
+
}
|
| 10 |
+
.section-header {
|
| 11 |
+
margin-top: 1rem !important;
|
| 12 |
+
margin-bottom: 1rem !important;
|
| 13 |
+
font-size: 1.2em !important;
|
| 14 |
+
}
|
| 15 |
+
.results-container {
|
| 16 |
+
background-color: #f8fafc;
|
| 17 |
+
padding: 1rem;
|
| 18 |
+
border-radius: 8px;
|
| 19 |
+
margin: 1rem 0;
|
| 20 |
+
}
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
# Default compliance data
|
| 24 |
+
default_compliance_df = pd.DataFrame({
|
| 25 |
+
"Regulation": ["MNPI", "GLBA", "HIPAA"],
|
| 26 |
+
"Expected Violations": [1, 1, 1],
|
| 27 |
+
"Penalty": [50000, 75000, 100000],
|
| 28 |
+
"Attorney Cost": [25000, 30000, 40000]
|
| 29 |
+
})
|
| 30 |
+
|
| 31 |
+
def calculate_roi(num_employees, hours_saved_per_week, hourly_wage,
|
| 32 |
+
initial_platform_cost, num_ai_hires, avg_salary,
|
| 33 |
+
ai_maintenance_cost, ai_security_cost,
|
| 34 |
+
revenue_increase,
|
| 35 |
+
preamble_cost_per_user, preamble_deployment, estimated_api_calls,
|
| 36 |
+
compliance_data):
|
| 37 |
+
# Annual labor savings
|
| 38 |
+
total_hours_saved = num_employees * hours_saved_per_week * 52
|
| 39 |
+
labor_cost_savings = total_hours_saved * hourly_wage
|
| 40 |
+
|
| 41 |
+
# Calculate compliance savings
|
| 42 |
+
compliance_savings = 0
|
| 43 |
+
if compliance_data is not None:
|
| 44 |
+
try:
|
| 45 |
+
if isinstance(compliance_data, pd.DataFrame):
|
| 46 |
+
df = compliance_data
|
| 47 |
+
else:
|
| 48 |
+
df = pd.DataFrame(compliance_data)
|
| 49 |
+
for index, row in df.iterrows():
|
| 50 |
+
try:
|
| 51 |
+
violations = float(row["Expected Violations"])
|
| 52 |
+
penalty = float(row["Penalty"])
|
| 53 |
+
attorney = float(row["Attorney Cost"])
|
| 54 |
+
compliance_savings += violations * (penalty + attorney)
|
| 55 |
+
except Exception:
|
| 56 |
+
continue
|
| 57 |
+
except Exception:
|
| 58 |
+
compliance_savings = 0
|
| 59 |
+
|
| 60 |
+
# Total benefits
|
| 61 |
+
total_benefits = labor_cost_savings + revenue_increase + compliance_savings
|
| 62 |
+
|
| 63 |
+
# Calculate costs
|
| 64 |
+
total_costs_build = initial_platform_cost + (num_ai_hires * avg_salary) + ai_maintenance_cost + ai_security_cost
|
| 65 |
+
|
| 66 |
+
# Preamble costs based on deployment model
|
| 67 |
+
if preamble_deployment == "SaaS":
|
| 68 |
+
total_costs_preamble = num_employees * preamble_cost_per_user * 12
|
| 69 |
+
elif preamble_deployment == "On-Prem (Fixed $27K/mo)":
|
| 70 |
+
total_costs_preamble = 27000 * 12
|
| 71 |
+
else: # Guardrails option
|
| 72 |
+
total_costs_preamble = estimated_api_calls * 0.005 * 12
|
| 73 |
+
|
| 74 |
+
# ROI calculations
|
| 75 |
+
roi_build = ((total_benefits - total_costs_build) / total_costs_build) * 100 if total_costs_build else 0
|
| 76 |
+
roi_preamble = ((total_benefits - total_costs_preamble) / total_costs_preamble) * 100 if total_costs_preamble else 0
|
| 77 |
+
|
| 78 |
+
return roi_build, roi_preamble, total_benefits, total_costs_build, total_costs_preamble
|
| 79 |
+
|
| 80 |
+
def create_app():
|
| 81 |
+
with gr.Blocks(css=CUSTOM_CSS) as roi_app:
|
| 82 |
+
gr.Markdown("# π Generative AI ROI Calculator", elem_classes="section-header")
|
| 83 |
+
|
| 84 |
+
# Results section
|
| 85 |
+
with gr.Row(elem_classes="results-container"):
|
| 86 |
+
with gr.Column():
|
| 87 |
+
build_roi_box = gr.Markdown("**ROI (Building In-House):** 0%")
|
| 88 |
+
total_costs_build_box = gr.Markdown("**Total Costs:** $0")
|
| 89 |
+
with gr.Column():
|
| 90 |
+
preamble_roi_box = gr.Markdown("**ROI (Using Preamble):** 0%")
|
| 91 |
+
total_costs_preamble_box = gr.Markdown("**Total Costs:** $0")
|
| 92 |
+
|
| 93 |
+
# Input sections using tabs for better organization
|
| 94 |
+
with gr.Tabs():
|
| 95 |
+
# Organization Details tab
|
| 96 |
+
with gr.Tab("π Organization Details"):
|
| 97 |
+
with gr.Row():
|
| 98 |
+
num_employees = gr.Slider(
|
| 99 |
+
label="Number of Employees Impacted",
|
| 100 |
+
minimum=1, maximum=1000, value=50,
|
| 101 |
+
info="How many employees will use the AI solution?"
|
| 102 |
+
)
|
| 103 |
+
hours_saved_per_week = gr.Slider(
|
| 104 |
+
label="Hours Saved per Week per Employee",
|
| 105 |
+
minimum=0, maximum=40, value=5,
|
| 106 |
+
info="Estimated time savings per employee"
|
| 107 |
+
)
|
| 108 |
+
hourly_wage = gr.Slider(
|
| 109 |
+
label="Average Hourly Wage ($)",
|
| 110 |
+
minimum=10, maximum=200, value=50,
|
| 111 |
+
info="Average employee hourly compensation"
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
# Preamble Options tab
|
| 115 |
+
with gr.Tab("πΌ Preamble Options"):
|
| 116 |
+
preamble_cost_per_user = gr.Slider(
|
| 117 |
+
label="Preamble SaaS Cost per User per Month",
|
| 118 |
+
minimum=10, maximum=200, value=50,
|
| 119 |
+
info="Monthly cost per user for SaaS deployment"
|
| 120 |
+
)
|
| 121 |
+
preamble_deployment = gr.Radio(
|
| 122 |
+
["SaaS", "On-Prem (Fixed $27K/mo)", "Guardrails ($0.005 per API call)"],
|
| 123 |
+
label="Deployment Model",
|
| 124 |
+
info="Choose your preferred deployment option"
|
| 125 |
+
)
|
| 126 |
+
estimated_api_calls = gr.Number(
|
| 127 |
+
label="Monthly API Calls (Guardrails)",
|
| 128 |
+
value=10000,
|
| 129 |
+
info="Estimated API calls per month if using Guardrails"
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
# Compliance tab
|
| 133 |
+
with gr.Tab("π‘οΈ Compliance"):
|
| 134 |
+
compliance_data = gr.Dataframe(
|
| 135 |
+
value=default_compliance_df,
|
| 136 |
+
headers=["Regulation", "Expected Violations", "Penalty", "Attorney Cost"],
|
| 137 |
+
datatype="pandas",
|
| 138 |
+
label="Compliance Data"
|
| 139 |
+
)
|
| 140 |
+
|
| 141 |
+
# Build Costs tab
|
| 142 |
+
with gr.Tab("π¨ Build Costs"):
|
| 143 |
+
initial_platform_cost = gr.Number(
|
| 144 |
+
label="Initial Platform Development Cost ($)",
|
| 145 |
+
value=100000,
|
| 146 |
+
info="One-time cost to develop the platform"
|
| 147 |
+
)
|
| 148 |
+
with gr.Row():
|
| 149 |
+
num_ai_hires = gr.Number(
|
| 150 |
+
label="Number of AI Personnel",
|
| 151 |
+
value=1,
|
| 152 |
+
info="Required AI specialists"
|
| 153 |
+
)
|
| 154 |
+
avg_salary = gr.Number(
|
| 155 |
+
label="Average Annual Salary ($)",
|
| 156 |
+
value=150000,
|
| 157 |
+
info="Average annual salary per AI hire"
|
| 158 |
+
)
|
| 159 |
+
with gr.Row():
|
| 160 |
+
ai_maintenance_cost = gr.Number(
|
| 161 |
+
label="Annual Maintenance Costs ($)",
|
| 162 |
+
value=20000,
|
| 163 |
+
info="Yearly platform maintenance"
|
| 164 |
+
)
|
| 165 |
+
ai_security_cost = gr.Number(
|
| 166 |
+
label="Security & Compliance Costs ($)",
|
| 167 |
+
value=10000,
|
| 168 |
+
info="Annual security and compliance expenses"
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
# Additional Benefits tab
|
| 172 |
+
with gr.Tab("π Benefits"):
|
| 173 |
+
revenue_increase = gr.Number(
|
| 174 |
+
label="Estimated Annual Revenue Increase ($)",
|
| 175 |
+
value=50000,
|
| 176 |
+
info="Projected revenue growth from AI implementation"
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
# Calculate button
|
| 180 |
+
calculate_button = gr.Button("Calculate ROI", variant="primary")
|
| 181 |
+
|
| 182 |
+
# Update UI function
|
| 183 |
+
def update_ui(*inputs):
|
| 184 |
+
roi_build, roi_preamble, benefits, costs_build, costs_preamble = calculate_roi(*inputs)
|
| 185 |
+
|
| 186 |
+
build_text = f"**ROI (Building In-House):** {roi_build:,.2f}%"
|
| 187 |
+
preamble_text = f"**ROI (Using Preamble):** {roi_preamble:,.2f}%"
|
| 188 |
+
costs_build_text = f"**Total Costs:** ${costs_build:,.2f}"
|
| 189 |
+
costs_preamble_text = f"**Total Costs:** ${costs_preamble:,.2f}"
|
| 190 |
+
|
| 191 |
+
return build_text, costs_build_text, preamble_text, costs_preamble_text
|
| 192 |
+
|
| 193 |
+
# Connect the calculate button
|
| 194 |
+
calculate_button.click(
|
| 195 |
+
update_ui,
|
| 196 |
+
inputs=[
|
| 197 |
+
num_employees, hours_saved_per_week, hourly_wage,
|
| 198 |
+
initial_platform_cost, num_ai_hires, avg_salary,
|
| 199 |
+
ai_maintenance_cost, ai_security_cost,
|
| 200 |
+
revenue_increase,
|
| 201 |
+
preamble_cost_per_user, preamble_deployment, estimated_api_calls,
|
| 202 |
+
compliance_data
|
| 203 |
+
],
|
| 204 |
+
outputs=[
|
| 205 |
+
build_roi_box,
|
| 206 |
+
total_costs_build_box,
|
| 207 |
+
preamble_roi_box,
|
| 208 |
+
total_costs_preamble_box
|
| 209 |
+
]
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
+
return roi_app
|
| 213 |
+
|
| 214 |
+
# Create and launch the app
|
| 215 |
+
app = create_app()
|
| 216 |
+
|
| 217 |
+
if __name__ == "__main__":
|
| 218 |
+
app.launch()
|