Spaces:
Runtime error
Runtime error
Commit
·
1c2b775
1
Parent(s):
76168c9
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,30 +2,13 @@ import gradio as gr
|
|
| 2 |
import models
|
| 3 |
import pandas as pd
|
| 4 |
import theme
|
|
|
|
| 5 |
|
| 6 |
-
text = "<h1 style='text-align: center; color: #
|
| 7 |
-
|
| 8 |
-
text1 = "<h1 style='text-align: center; color: midnightblue; font-size: 25px;'>First option"
|
| 9 |
-
text2 = "<h1 style='text-align: center; color: midnightblue; font-size: 25px;'>Second option"
|
| 10 |
-
text3 = "<h1 style='text-align: center; color: midnightblue; font-size: 30px;'>Compute and compare TCOs"
|
| 11 |
-
text4 = "The cost/request only defines the infrastructure cost for deployment. The labor cost must be added for the whole AI model service deployment TCO."
|
| 12 |
description=f"""
|
| 13 |
-
<p>In this demo application, we help you compare different AI model services, such as Open source or SaaS solutions, based on the Total Cost of Ownership for their deployment
|
| 14 |
-
<p>
|
| 15 |
-
"""
|
| 16 |
-
markdown = """
|
| 17 |
-
<div style="
|
| 18 |
-
background-color: #f0ba2d;
|
| 19 |
-
color: #050f19;
|
| 20 |
-
border-radius: 10px;
|
| 21 |
-
padding: 3px;
|
| 22 |
-
margin: 0 auto;
|
| 23 |
-
width: 150px;
|
| 24 |
-
text-align: center;
|
| 25 |
-
font-size: 18px;
|
| 26 |
-
">
|
| 27 |
-
Comparison
|
| 28 |
-
</div>
|
| 29 |
"""
|
| 30 |
|
| 31 |
def on_use_case_change(use_case):
|
|
@@ -36,34 +19,25 @@ def on_use_case_change(use_case):
|
|
| 36 |
else:
|
| 37 |
return gr.update(value=50), gr.update(value=10)
|
| 38 |
|
| 39 |
-
def compare_info(tco1, tco2,
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
if r < 1:
|
| 44 |
-
comparison_result = f"The cost/request of the second {dropdown2} service is {1/r:.5f} times more expensive than the one of the first {dropdown} service."
|
| 45 |
-
if labor_cost1 > labor_cost2:
|
| 46 |
-
meeting_point = (labor_cost2 - labor_cost1) / (tco1 - tco2)
|
| 47 |
-
comparison_result3 = f"The number of requests you need to achieve in a month to have the labor cost of the {dropdown} service be absorbed and both solution TCOs be equal would be of {meeting_point:.0f}."
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
<br>
|
| 64 |
-
<p> {comparison_result3} </p>
|
| 65 |
-
"""
|
| 66 |
-
return info
|
| 67 |
|
| 68 |
def create_table(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2, latency, latency2):
|
| 69 |
list_values = []
|
|
@@ -79,14 +53,15 @@ def create_table(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2, late
|
|
| 79 |
formatted_data["Labor Cost ($/month)"] = formatted_data["Labor Cost ($/month)"].apply('{:.0f}'.format)
|
| 80 |
|
| 81 |
styled_data = formatted_data.style\
|
| 82 |
-
.set_properties(**{'background-color': '#
|
| 83 |
.to_html()
|
|
|
|
| 84 |
|
| 85 |
-
return gr.update(value=
|
| 86 |
|
| 87 |
def update_plot(tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2):
|
| 88 |
|
| 89 |
-
request_ranges =
|
| 90 |
costs_tco1 = [(tco1 * req + labour_cost1) for req in request_ranges]
|
| 91 |
costs_tco2 = [(tco2 * req + labour_cost2) for req in request_ranges]
|
| 92 |
|
|
@@ -96,7 +71,7 @@ def update_plot(tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2):
|
|
| 96 |
"AI model service": ["1)" + " " + dropdown] * len(request_ranges) + ["2)" + " " + dropdown2] * len(request_ranges)
|
| 97 |
}
|
| 98 |
)
|
| 99 |
-
return gr.LinePlot.update(data, visible=True, x="Number of requests", y="Cost ($)",color="AI model service",color_legend_position="bottom", title="
|
| 100 |
|
| 101 |
style = theme.Style()
|
| 102 |
|
|
@@ -152,13 +127,16 @@ with gr.Blocks(theme=style) as demo:
|
|
| 152 |
tco_formula2 = gr.Markdown()
|
| 153 |
|
| 154 |
with gr.Row(variant='panel'):
|
| 155 |
-
with gr.Column(
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
-
compute_tco_btn.click(page1.compute_cost_per_token, inputs=page1.get_all_components_for_cost_computing() + [dropdown, input_tokens, output_tokens], outputs=[tco1, tco_formula, latency, labor_cost1]).then(page2.compute_cost_per_token, inputs=page2.get_all_components_for_cost_computing() + [dropdown2, input_tokens, output_tokens], outputs=[tco2, tco_formula2, latency2, labor_cost2]).then(create_table, inputs=[tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2, latency, latency2], outputs=table).then(compare_info, inputs=[tco1, tco2,
|
| 163 |
|
| 164 |
demo.launch(debug=True)
|
|
|
|
| 2 |
import models
|
| 3 |
import pandas as pd
|
| 4 |
import theme
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
|
| 7 |
+
text = "<h1 style='text-align: center; color: #333333; font-size: 40px;'>TCO Comparison Calculator"
|
| 8 |
+
text2 = "Please note that the cost/request only defines the infrastructure cost for deployment. The labor cost must be added for the whole AI model service deployment TCO."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
description=f"""
|
| 10 |
+
<p>In this demo application, we help you compare different AI model services, such as Open source or SaaS solutions, based on the Total Cost of Ownership for their deployment.</p>
|
| 11 |
+
<p>Please note that we focus on getting the service up and running, but not the maintenance that follows.</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
"""
|
| 13 |
|
| 14 |
def on_use_case_change(use_case):
|
|
|
|
| 19 |
else:
|
| 20 |
return gr.update(value=50), gr.update(value=10)
|
| 21 |
|
| 22 |
+
def compare_info(tco1, tco2, dropdown, dropdown2):
|
| 23 |
+
# Create a bar chart
|
| 24 |
+
services = [dropdown, dropdown2]
|
| 25 |
+
costs_to_compare = [tco1, tco2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
plt.figure(figsize=(6, 4))
|
| 28 |
+
plt.bar(services, costs_to_compare, color=['red', 'green'])
|
| 29 |
+
plt.xlabel('AI option services', fontsize=10)
|
| 30 |
+
plt.ylabel('($) Cost/Request', fontsize=10)
|
| 31 |
+
plt.title('Comparison of Cost/Request', fontsize=14)
|
| 32 |
|
| 33 |
+
# Customize x-axis labels
|
| 34 |
+
#plt.xticks(rotation=30, ha='right') # Rotate by 30 degrees and align to the right
|
| 35 |
+
|
| 36 |
+
# Save the plot to a file or display it
|
| 37 |
+
plt.tight_layout()
|
| 38 |
+
plt.savefig('cost_comparison.png') # Save to a file
|
| 39 |
+
|
| 40 |
+
return gr.update(value='cost_comparison.png')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
def create_table(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2, latency, latency2):
|
| 43 |
list_values = []
|
|
|
|
| 53 |
formatted_data["Labor Cost ($/month)"] = formatted_data["Labor Cost ($/month)"].apply('{:.0f}'.format)
|
| 54 |
|
| 55 |
styled_data = formatted_data.style\
|
| 56 |
+
.set_properties(**{'background-color': '#ffffff', 'color': '#000000', 'border-color': '#e0e0e0', 'border-width': '1px', 'border-style': 'solid'})\
|
| 57 |
.to_html()
|
| 58 |
+
centered_styled_data = f"<center>{styled_data}</center>"
|
| 59 |
|
| 60 |
+
return gr.update(value=centered_styled_data)
|
| 61 |
|
| 62 |
def update_plot(tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2):
|
| 63 |
|
| 64 |
+
request_ranges = list(range(0, 1001, 100)) + list(range(1000, 10001, 500)) + list(range(10000, 100001, 1000)) + list(range(100000, 2000001, 100000))
|
| 65 |
costs_tco1 = [(tco1 * req + labour_cost1) for req in request_ranges]
|
| 66 |
costs_tco2 = [(tco2 * req + labour_cost2) for req in request_ranges]
|
| 67 |
|
|
|
|
| 71 |
"AI model service": ["1)" + " " + dropdown] * len(request_ranges) + ["2)" + " " + dropdown2] * len(request_ranges)
|
| 72 |
}
|
| 73 |
)
|
| 74 |
+
return gr.LinePlot.update(data, visible=True, x="Number of requests", y="Cost ($)",color="AI model service",color_legend_position="bottom", title="Set-up TCO for one month", height=300, width=500, tooltip=["Number of requests", "Cost ($)", "AI model service"])
|
| 75 |
|
| 76 |
style = theme.Style()
|
| 77 |
|
|
|
|
| 127 |
tco_formula2 = gr.Markdown()
|
| 128 |
|
| 129 |
with gr.Row(variant='panel'):
|
| 130 |
+
with gr.Column():
|
| 131 |
+
with gr.Row():
|
| 132 |
+
table = gr.Markdown()
|
| 133 |
+
with gr.Row():
|
| 134 |
+
with gr.Column(scale=1):
|
| 135 |
+
image = gr.Image()
|
| 136 |
+
info = gr.Markdown(text2)
|
| 137 |
+
with gr.Column(scale=2):
|
| 138 |
+
plot = gr.LinePlot(visible=False)
|
| 139 |
|
| 140 |
+
compute_tco_btn.click(page1.compute_cost_per_token, inputs=page1.get_all_components_for_cost_computing() + [dropdown, input_tokens, output_tokens], outputs=[tco1, tco_formula, latency, labor_cost1]).then(page2.compute_cost_per_token, inputs=page2.get_all_components_for_cost_computing() + [dropdown2, input_tokens, output_tokens], outputs=[tco2, tco_formula2, latency2, labor_cost2]).then(create_table, inputs=[tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2, latency, latency2], outputs=table).then(compare_info, inputs=[tco1, tco2, dropdown, dropdown2], outputs=image).then(update_plot, inputs=[tco1, tco2, dropdown, dropdown2, labor_cost1, labor_cost2], outputs=plot)
|
| 141 |
|
| 142 |
demo.launch(debug=True)
|