Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,66 @@
|
|
| 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 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
| 14 |
}
|
|
|
|
|
|
|
| 15 |
.results-container {
|
| 16 |
-
background
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
border-radius: 8px;
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
}
|
| 21 |
"""
|
| 22 |
|
|
@@ -29,11 +73,11 @@ default_compliance_df = pd.DataFrame({
|
|
| 29 |
})
|
| 30 |
|
| 31 |
def calculate_roi(num_employees, hours_saved_per_week, hourly_wage,
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
# Annual labor savings
|
| 38 |
total_hours_saved = num_employees * hours_saved_per_week * 52
|
| 39 |
labor_cost_savings = total_hours_saved * hourly_wage
|
|
@@ -78,67 +122,85 @@ def calculate_roi(num_employees, hours_saved_per_week, hourly_wage,
|
|
| 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 |
-
|
|
|
|
| 83 |
|
| 84 |
# Results section
|
| 85 |
with gr.Row(elem_classes="results-container"):
|
| 86 |
with gr.Column():
|
| 87 |
-
build_roi_box = gr.Markdown(
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
with gr.Column():
|
| 90 |
-
preamble_roi_box = gr.Markdown(
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
| 98 |
num_employees = gr.Slider(
|
| 99 |
label="Number of Employees Impacted",
|
| 100 |
-
minimum=1,
|
|
|
|
|
|
|
|
|
|
| 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,
|
|
|
|
|
|
|
|
|
|
| 106 |
info="Estimated time savings per employee"
|
| 107 |
)
|
| 108 |
hourly_wage = gr.Slider(
|
| 109 |
label="Average Hourly Wage ($)",
|
| 110 |
-
minimum=10,
|
|
|
|
|
|
|
|
|
|
| 111 |
info="Average employee hourly compensation"
|
| 112 |
)
|
| 113 |
|
| 114 |
-
# Preamble Options
|
| 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,
|
|
|
|
|
|
|
|
|
|
| 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="
|
| 130 |
)
|
| 131 |
|
| 132 |
-
# Compliance
|
| 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
|
| 139 |
)
|
| 140 |
|
| 141 |
-
# Build Costs
|
| 142 |
with gr.Tab("π¨ Build Costs"):
|
| 143 |
initial_platform_cost = gr.Number(
|
| 144 |
label="Initial Platform Development Cost ($)",
|
|
@@ -168,7 +230,7 @@ def create_app():
|
|
| 168 |
info="Annual security and compliance expenses"
|
| 169 |
)
|
| 170 |
|
| 171 |
-
#
|
| 172 |
with gr.Tab("π Benefits"):
|
| 173 |
revenue_increase = gr.Number(
|
| 174 |
label="Estimated Annual Revenue Increase ($)",
|
|
@@ -177,22 +239,49 @@ def create_app():
|
|
| 177 |
)
|
| 178 |
|
| 179 |
# Calculate button
|
| 180 |
-
calculate_button = gr.Button(
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
-
#
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
|
|
|
| 190 |
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
# Connect the calculate button
|
| 194 |
calculate_button.click(
|
| 195 |
-
|
| 196 |
inputs=[
|
| 197 |
num_employees, hours_saved_per_week, hourly_wage,
|
| 198 |
initial_platform_cost, num_ai_hires, avg_salary,
|
|
@@ -201,12 +290,17 @@ def create_app():
|
|
| 201 |
preamble_cost_per_user, preamble_deployment, estimated_api_calls,
|
| 202 |
compliance_data
|
| 203 |
],
|
| 204 |
-
outputs=[
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
)
|
| 211 |
|
| 212 |
return roi_app
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
|
|
|
|
| 4 |
CUSTOM_CSS = """
|
| 5 |
.gradio-container {
|
| 6 |
max-width: 1200px !important;
|
| 7 |
+
margin: auto !important;
|
| 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 |
|
|
|
|
| 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
|
|
|
|
| 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 ($)",
|
|
|
|
| 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 ($)",
|
|
|
|
| 239 |
)
|
| 240 |
|
| 241 |
# Calculate button
|
| 242 |
+
calculate_button = gr.Button(
|
| 243 |
+
"Calculate ROI",
|
| 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,
|
|
|
|
| 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
|