Spaces:
Running
Running
jadehardouin
commited on
Commit
•
564f119
1
Parent(s):
87f2a0e
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,7 @@ text1 = "<h1 style='text-align: center; color: midnightblue; font-size: 25px;'>F
|
|
12 |
text2 = "<h1 style='text-align: center; color: midnightblue; font-size: 25px;'>Second option"
|
13 |
text3 = "<h1 style='text-align: center; color: midnightblue; font-size: 30px;'>Compute and compare TCOs"
|
14 |
description=f"""
|
15 |
-
<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>
|
16 |
<p>First, you'll have to select your use case. Then, select the two model service options you'd like to compare. Depending on the options you chose, you could be able to customize some parameters of the set-up. Eventually, we will provide you with the cost of deployment for the selected model services, as a function of the number of requests. You can compare both solutions to evaluate which one best suits your needs.</p>
|
17 |
"""
|
18 |
|
@@ -26,24 +26,24 @@ def on_use_case_change(use_case):
|
|
26 |
|
27 |
def compare(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2):
|
28 |
r = tco1 / tco2
|
29 |
-
|
30 |
|
31 |
if r < 1:
|
32 |
comparison_result = f"The cost/request of the {dropdown2} service is {1/r:.5f} times more expensive than the one of the {dropdown} service."
|
33 |
-
if
|
34 |
comparison_result2 = f"However, it will cost a lot more to deploy the set-up for the {dropdown} service because the labor cost per month is of ${labor_cost1}, compared to a labor cost per month of ${labor_cost2} for the {dropdown2} solution."
|
35 |
meeting_point = (labor_cost2 - labor_cost1) / (tco1 - tco2)
|
36 |
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}."
|
37 |
-
elif
|
38 |
comparison_result2 = f"Additionally, it will cost a lot more to deploy the set-up for the {dropdown2} service because the labor cost per month is of ${labor_cost2}, compared to a labor cost per month of ${labor_cost1} for the {dropdown} solution."
|
39 |
else:
|
40 |
comparison_result2 = f"Additionally, both services have the same labor cost per month."
|
41 |
|
42 |
elif r > 1:
|
43 |
comparison_result = f"The cost/request of the {dropdown2} service is {r:.5f} times cheaper than the one of the {dropdown} service."
|
44 |
-
if
|
45 |
comparison_result2 = f"Additionally, it will cost a lot more to deploy the set-up for the {dropdown} service because the labor cost per month is of ${labor_cost1}, compared to a labor cost per month of ${labor_cost2} for the {dropdown2} solution."
|
46 |
-
elif
|
47 |
comparison_result2 = f"However, it will cost a lot more to deploy the set-up for the {dropdown2} service because the labor cost per month is of ${labor_cost2}, compared to a labor cost per month of ${labor_cost1} for the {dropdown} solution."
|
48 |
meeting_point = (labor_cost2 - labor_cost1) / (tco1 - tco2)
|
49 |
comparison_result3 = f"The number of requests you need to achieve in a month to have the labor cost of the {dropdown2} service be absorbed and both solution TCOs be equal would be of {meeting_point:.0f}."
|
@@ -52,14 +52,36 @@ def compare(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2):
|
|
52 |
|
53 |
else:
|
54 |
comparison_result = f"Both solutions have the same cost/request."
|
55 |
-
if
|
56 |
comparison_result2 = f"However, it will cost a lot more to deploy the set-up for the {dropdown} service because the labor cost per month is of ${labor_cost1}, compared to a labor cost per month of ${labor_cost2} for the {dropdown2} solution."
|
57 |
-
elif
|
58 |
comparison_result2 = f"However, it will cost a lot more to deploy the set-up for the {dropdown2} service because the labor cost per month is of ${labor_cost2}, compared to a labor cost per month of ${labor_cost1} for the {dropdown} solution."
|
59 |
else:
|
60 |
comparison_result2 = f"Additionally, both services have the same labor cost per month."
|
61 |
|
62 |
-
return comparison_result + "\n" + "\n" + comparison_result2 + "\n" + "\n" + comparison_result3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
def update_plot(tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2):
|
65 |
|
@@ -227,23 +249,25 @@ with gr.Blocks(theme=style) as demo:
|
|
227 |
|
228 |
with gr.Row():
|
229 |
with gr.Column():
|
230 |
-
tco_output = gr.Text("Cost/request 1: ", label=" Cost/request for the first option ", info="This is only the infrastructure cost per request for deployment, the labor cost still has to be added for
|
231 |
latency_info = gr.Markdown()
|
232 |
with gr.Accordion("Click here to see the formula", open=False):
|
233 |
tco_formula = gr.Markdown()
|
234 |
|
235 |
with gr.Column():
|
236 |
-
tco_output2 = gr.Text("Cost/request 2: ", label=" Cost/request for the second option ", info="This is only the infrastructure cost per request for deployment, the labor cost still has to be added for
|
237 |
latency_info2 = gr.Markdown()
|
238 |
with gr.Accordion("Click here to see the formula", open=False):
|
239 |
tco_formula2 = gr.Markdown()
|
240 |
|
241 |
with gr.Row():
|
242 |
with gr.Column(scale=1):
|
243 |
-
|
244 |
-
|
|
|
|
|
245 |
plot = gr.LinePlot()
|
246 |
|
247 |
-
compute_tco_btn.click(page1.compute_cost_per_token, inputs=page1.get_all_components_for_cost_computing() + [dropdown, input_tokens, output_tokens], outputs=[tco_output, tco1, tco_formula, latency_info, labor_cost1]).then(page2.compute_cost_per_token, inputs=page2.get_all_components_for_cost_computing() + [dropdown2, input_tokens, output_tokens], outputs=[tco_output2, tco2, tco_formula2, latency_info2, labor_cost2]).then(compare, inputs=[tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2], outputs=ratio).then(update_plot, inputs=[tco1, tco2, dropdown, dropdown2, labor_cost1, labor_cost2], outputs=plot)
|
248 |
|
249 |
demo.launch(debug=True)
|
|
|
12 |
text2 = "<h1 style='text-align: center; color: midnightblue; font-size: 25px;'>Second option"
|
13 |
text3 = "<h1 style='text-align: center; color: midnightblue; font-size: 30px;'>Compute and compare TCOs"
|
14 |
description=f"""
|
15 |
+
<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. Please note that we focus on getting the service up and running, but not the maintenance that follows.</p>
|
16 |
<p>First, you'll have to select your use case. Then, select the two model service options you'd like to compare. Depending on the options you chose, you could be able to customize some parameters of the set-up. Eventually, we will provide you with the cost of deployment for the selected model services, as a function of the number of requests. You can compare both solutions to evaluate which one best suits your needs.</p>
|
17 |
"""
|
18 |
|
|
|
26 |
|
27 |
def compare(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2):
|
28 |
r = tco1 / tco2
|
29 |
+
comparison_result3 = ""
|
30 |
|
31 |
if r < 1:
|
32 |
comparison_result = f"The cost/request of the {dropdown2} service is {1/r:.5f} times more expensive than the one of the {dropdown} service."
|
33 |
+
if labor_cost1 > labor_cost2:
|
34 |
comparison_result2 = f"However, it will cost a lot more to deploy the set-up for the {dropdown} service because the labor cost per month is of ${labor_cost1}, compared to a labor cost per month of ${labor_cost2} for the {dropdown2} solution."
|
35 |
meeting_point = (labor_cost2 - labor_cost1) / (tco1 - tco2)
|
36 |
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}."
|
37 |
+
elif labor_cost1 < labor_cost2:
|
38 |
comparison_result2 = f"Additionally, it will cost a lot more to deploy the set-up for the {dropdown2} service because the labor cost per month is of ${labor_cost2}, compared to a labor cost per month of ${labor_cost1} for the {dropdown} solution."
|
39 |
else:
|
40 |
comparison_result2 = f"Additionally, both services have the same labor cost per month."
|
41 |
|
42 |
elif r > 1:
|
43 |
comparison_result = f"The cost/request of the {dropdown2} service is {r:.5f} times cheaper than the one of the {dropdown} service."
|
44 |
+
if labor_cost1 > labor_cost2:
|
45 |
comparison_result2 = f"Additionally, it will cost a lot more to deploy the set-up for the {dropdown} service because the labor cost per month is of ${labor_cost1}, compared to a labor cost per month of ${labor_cost2} for the {dropdown2} solution."
|
46 |
+
elif labor_cost1 < labor_cost2:
|
47 |
comparison_result2 = f"However, it will cost a lot more to deploy the set-up for the {dropdown2} service because the labor cost per month is of ${labor_cost2}, compared to a labor cost per month of ${labor_cost1} for the {dropdown} solution."
|
48 |
meeting_point = (labor_cost2 - labor_cost1) / (tco1 - tco2)
|
49 |
comparison_result3 = f"The number of requests you need to achieve in a month to have the labor cost of the {dropdown2} service be absorbed and both solution TCOs be equal would be of {meeting_point:.0f}."
|
|
|
52 |
|
53 |
else:
|
54 |
comparison_result = f"Both solutions have the same cost/request."
|
55 |
+
if labor_cost1 > labor_cost2:
|
56 |
comparison_result2 = f"However, it will cost a lot more to deploy the set-up for the {dropdown} service because the labor cost per month is of ${labor_cost1}, compared to a labor cost per month of ${labor_cost2} for the {dropdown2} solution."
|
57 |
+
elif labor_cost1 < 1:
|
58 |
comparison_result2 = f"However, it will cost a lot more to deploy the set-up for the {dropdown2} service because the labor cost per month is of ${labor_cost2}, compared to a labor cost per month of ${labor_cost1} for the {dropdown} solution."
|
59 |
else:
|
60 |
comparison_result2 = f"Additionally, both services have the same labor cost per month."
|
61 |
|
62 |
+
#return comparison_result + "\n" + "\n" + comparison_result2 + "\n" + "\n" + comparison_result3
|
63 |
+
return gr.update(value=comparison_result), comparison_result3
|
64 |
+
|
65 |
+
def create_table(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2):
|
66 |
+
list_values = []
|
67 |
+
labor_cost1 = round(labor_cost1, 1)
|
68 |
+
labor_cost2 = round(labor_cost2, 1)
|
69 |
+
first_sol = [tco1, labor_cost1]
|
70 |
+
second_sol = [tco2, labor_cost2]
|
71 |
+
list_values.append(first_sol)
|
72 |
+
list_values.append(second_sol)
|
73 |
+
|
74 |
+
data = pd.DataFrame(list_values, index=[dropdown, dropdown2], columns=["Cost/request ($) ", "Labor Cost ($/month)"])
|
75 |
+
|
76 |
+
formatted_data = data.copy()
|
77 |
+
formatted_data["Cost/request ($) "] = formatted_data["Cost/request ($) "].apply('{:.5f}'.format)
|
78 |
+
formatted_data["Labor Cost ($/month)"] = formatted_data["Labor Cost ($/month)"].apply('{:.1f}'.format)
|
79 |
+
|
80 |
+
styled_data = formatted_data.style\
|
81 |
+
.set_properties(**{'background-color': '#050f19', 'color': '#ffffff', 'border-color': '#ffffff', 'border-width': '1px', 'border-style': 'solid'})\
|
82 |
+
.to_html()
|
83 |
+
|
84 |
+
return gr.update(value=styled_data)
|
85 |
|
86 |
def update_plot(tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2):
|
87 |
|
|
|
249 |
|
250 |
with gr.Row():
|
251 |
with gr.Column():
|
252 |
+
tco_output = gr.Text("Cost/request 1: ", label=" Cost/request for the first option ", info="This is only the infrastructure cost per request for deployment, the labor cost still has to be added for the AI model service deployment TCO.")
|
253 |
latency_info = gr.Markdown()
|
254 |
with gr.Accordion("Click here to see the formula", open=False):
|
255 |
tco_formula = gr.Markdown()
|
256 |
|
257 |
with gr.Column():
|
258 |
+
tco_output2 = gr.Text("Cost/request 2: ", label=" Cost/request for the second option ", info="This is only the infrastructure cost per request for deployment, the labor cost still has to be added for the AI model service deployment TCO.")
|
259 |
latency_info2 = gr.Markdown()
|
260 |
with gr.Accordion("Click here to see the formula", open=False):
|
261 |
tco_formula2 = gr.Markdown()
|
262 |
|
263 |
with gr.Row():
|
264 |
with gr.Column(scale=1):
|
265 |
+
info = gr.Text("Click on Compute & Compare to get the results", label=" Comparison of cost/request and TCOs")
|
266 |
+
table = gr.Markdown()
|
267 |
+
ratio = gr.Markdown()
|
268 |
+
with gr.Column(scale=2):
|
269 |
plot = gr.LinePlot()
|
270 |
|
271 |
+
compute_tco_btn.click(page1.compute_cost_per_token, inputs=page1.get_all_components_for_cost_computing() + [dropdown, input_tokens, output_tokens], outputs=[tco_output, tco1, tco_formula, latency_info, labor_cost1]).then(page2.compute_cost_per_token, inputs=page2.get_all_components_for_cost_computing() + [dropdown2, input_tokens, output_tokens], outputs=[tco_output2, tco2, tco_formula2, latency_info2, labor_cost2]).then(create_table, inputs=[tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2], outputs=table).then(compare, inputs=[tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2], outputs=[info, ratio]).then(update_plot, inputs=[tco1, tco2, dropdown, dropdown2, labor_cost1, labor_cost2], outputs=plot)
|
272 |
|
273 |
demo.launch(debug=True)
|