Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,134 +2,175 @@ import gradio as gr
|
|
| 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 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
}
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
border-radius: 12px;
|
| 34 |
-
padding: 1.5rem;
|
| 35 |
-
margin-bottom: 2rem;
|
| 36 |
-
color: white;
|
| 37 |
-
}
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
color: #081423 !important;
|
| 42 |
-
}
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
}
|
| 56 |
-
"""
|
| 57 |
|
| 58 |
-
|
| 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
|
| 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(
|
|
|
|
|
|
|
| 93 |
with gr.Column():
|
| 94 |
-
preamble_roi_box = gr.Markdown(
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
#
|
| 97 |
with gr.Row():
|
| 98 |
with gr.Column():
|
| 99 |
-
gr.Markdown("## π―
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
info="
|
| 104 |
)
|
| 105 |
-
|
| 106 |
-
["
|
| 107 |
-
label="
|
|
|
|
|
|
|
| 108 |
)
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
"
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
)
|
| 114 |
|
| 115 |
# Main tabs
|
| 116 |
with gr.Tabs():
|
| 117 |
-
# Organization Details
|
| 118 |
with gr.Tab("π’ Organization Details"):
|
| 119 |
num_employees = gr.Slider(
|
| 120 |
label="Number of Employees",
|
| 121 |
minimum=1,
|
| 122 |
-
maximum=
|
| 123 |
-
value=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
)
|
| 125 |
-
# ... rest of organization details ...
|
| 126 |
|
| 127 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
# Calculate button
|
| 143 |
-
calculate_button = gr.Button(
|
| 144 |
-
"Calculate ROI",
|
| 145 |
-
elem_classes="primary-button"
|
| 146 |
-
)
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
-
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
# Connect the recommendation update
|
| 168 |
-
for input_elem in [
|
| 169 |
input_elem.change(
|
| 170 |
-
fn=
|
| 171 |
-
inputs=[
|
| 172 |
-
outputs=[
|
| 173 |
)
|
| 174 |
|
| 175 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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__":
|