jadehardouin
commited on
Commit
•
80b9501
1
Parent(s):
528e2ea
Update app.py
Browse files
app.py
CHANGED
@@ -4,8 +4,8 @@ import pandas as pd
|
|
4 |
|
5 |
text = "<h1 style='text-align: center; color: midnightblue; font-size: 40px;'>TCO Comparison Calculator"
|
6 |
text0 = "<h1 style='text-align: center; color: midnightblue; font-size: 30px;'>Describe your use case"
|
7 |
-
text1 = "<h1 style='text-align: center; color: midnightblue; font-size:
|
8 |
-
text2 = "<h1 style='text-align: center; color: midnightblue; font-size:
|
9 |
text3 = "<h1 style='text-align: center; color: midnightblue; font-size: 30px;'>Compute and compare TCOs"
|
10 |
description=f"""
|
11 |
<p>In this demo application, we help you compare different AI model services, such as Open source or SaaS solutions.</p>
|
@@ -23,82 +23,82 @@ def on_use_case_change(use_case):
|
|
23 |
def compare(tco1, tco2):
|
24 |
r = tco1 / tco2
|
25 |
if r < 1:
|
26 |
-
comparison_result = f"Second solution is {1/r:.5f} times more expensive than the first"
|
27 |
elif r > 1:
|
28 |
-
comparison_result = f"Second solution is {r:.5f} times cheaper than the first"
|
29 |
else:
|
30 |
comparison_result = "Both solutions will cost the same."
|
31 |
return comparison_result
|
32 |
|
33 |
-
def update_plot(tco1, tco2, dropdown, dropdown2):
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
data = pd.DataFrame(
|
44 |
-
{
|
45 |
-
"Number of requests": [100, 200, 300, 400, 500, 1000, 10000, 100, 200, 300, 400, 500, 1000, 10000],
|
46 |
-
"Cost ($)": [(tco1 * req + salary) for req in [100, 200, 300, 400, 500, 1000, 10000]] + [(tco2 * req + salary2) for req in [100, 200, 300, 400, 500, 1000, 10000]],
|
47 |
-
"AI model service": [dropdown] * 7 + [dropdown2] * 7
|
48 |
}
|
49 |
)
|
50 |
return gr.LinePlot.update(data, x="Number of requests", y="Cost ($)",color="AI model service",color_legend_position="bottom", title="Total Cost of Model Serving for one month", height=300, width=500, tooltip=["Number of requests", "Cost ($)", "AI model service"])
|
51 |
|
52 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
53 |
-
Models: list[models.BaseTCOModel] = [models.OpenAIModel, models.CohereModel, models.OpenSourceLlama2Model
|
54 |
model_names = [Model().get_name() for Model in Models]
|
55 |
gr.Markdown(value=text)
|
56 |
gr.Markdown(value=description)
|
57 |
|
58 |
with gr.Row():
|
59 |
with gr.Column():
|
|
|
|
|
60 |
with gr.Row():
|
61 |
-
gr.
|
62 |
-
with gr.
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
num_users = gr.Number(value="1000", interactive = True, label="Number of users for your service")
|
69 |
|
70 |
use_case.change(on_use_case_change, inputs=use_case, outputs=[input_tokens, output_tokens])
|
71 |
|
72 |
with gr.Row():
|
73 |
with gr.Column():
|
74 |
-
gr.Markdown(value=text1)
|
75 |
page1 = models.ModelPage(Models)
|
76 |
-
dropdown = gr.Dropdown(model_names, interactive=True, label="AI service
|
77 |
-
|
|
|
78 |
|
79 |
with gr.Column():
|
80 |
-
gr.Markdown(value=text2)
|
81 |
page2 = models.ModelPage(Models)
|
82 |
-
dropdown2 = gr.Dropdown(model_names, interactive=True, label="AI service
|
83 |
-
|
|
|
84 |
|
85 |
-
dropdown.change(page1.make_model_visible, inputs=[dropdown, use_case
|
86 |
-
dropdown2.change(page2.make_model_visible, inputs=[dropdown2, use_case
|
87 |
|
88 |
-
gr.Markdown(value=text3)
|
89 |
compute_tco_btn = gr.Button("Compute cost/request and TCOs", size="lg")
|
90 |
tco1 = gr.State()
|
91 |
tco2 = gr.State()
|
|
|
|
|
92 |
|
93 |
with gr.Row():
|
94 |
with gr.Column():
|
95 |
-
tco_output = gr.Text("Output 1: ", label="Cost/request for the first
|
96 |
latency_info = gr.Markdown()
|
97 |
with gr.Accordion("Open to see the formula", open=False):
|
98 |
tco_formula = gr.Markdown()
|
99 |
|
100 |
with gr.Column():
|
101 |
-
tco_output2 = gr.Text("Output 2: ", label="Cost/request for the second
|
102 |
latency_info2 = gr.Markdown()
|
103 |
with gr.Accordion("Open to see the formula", open=False):
|
104 |
tco_formula2 = gr.Markdown()
|
@@ -109,6 +109,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
109 |
with gr.Column(scale=3):
|
110 |
plot = gr.LinePlot()
|
111 |
|
112 |
-
compute_tco_btn.click(page1.compute_cost_per_token, inputs=page1.get_all_components_for_cost_computing() + [dropdown], outputs=[tco_output, tco1, tco_formula, latency_info]).then(page2.compute_cost_per_token, inputs=page2.get_all_components_for_cost_computing() + [dropdown2], outputs=[tco_output2, tco2, tco_formula2, latency_info2]).then(compare, inputs=[tco1, tco2], outputs=ratio).then(update_plot, inputs=[tco1, tco2, dropdown, dropdown2], outputs=plot)
|
113 |
|
114 |
demo.launch(debug=True)
|
|
|
4 |
|
5 |
text = "<h1 style='text-align: center; color: midnightblue; font-size: 40px;'>TCO Comparison Calculator"
|
6 |
text0 = "<h1 style='text-align: center; color: midnightblue; font-size: 30px;'>Describe your use case"
|
7 |
+
text1 = "<h1 style='text-align: center; color: midnightblue; font-size: 25px;'>First option"
|
8 |
+
text2 = "<h1 style='text-align: center; color: midnightblue; font-size: 25px;'>Second option"
|
9 |
text3 = "<h1 style='text-align: center; color: midnightblue; font-size: 30px;'>Compute and compare TCOs"
|
10 |
description=f"""
|
11 |
<p>In this demo application, we help you compare different AI model services, such as Open source or SaaS solutions.</p>
|
|
|
23 |
def compare(tco1, tco2):
|
24 |
r = tco1 / tco2
|
25 |
if r < 1:
|
26 |
+
comparison_result = f"Second solution's cost/request is {1/r:.5f} times more expensive than the first"
|
27 |
elif r > 1:
|
28 |
+
comparison_result = f"Second solution's cost/request is {r:.5f} times cheaper than the first"
|
29 |
else:
|
30 |
comparison_result = "Both solutions will cost the same."
|
31 |
return comparison_result
|
32 |
|
33 |
+
def update_plot(tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2):
|
34 |
+
|
35 |
+
request_ranges = [100, 200, 300, 400, 500, 1000, 10000]
|
36 |
+
costs_tco1 = [(tco1 * req + labour_cost1) for req in request_ranges]
|
37 |
+
costs_tco2 = [(tco2 * req + labour_cost2) for req in request_ranges]
|
38 |
+
|
39 |
+
data = pd.DataFrame({
|
40 |
+
"Number of requests": request_ranges * 2,
|
41 |
+
"Cost ($)": costs_tco1 + costs_tco2,
|
42 |
+
"AI model service": [dropdown] * len(request_ranges) + [dropdown2] * len(request_ranges)
|
|
|
|
|
|
|
|
|
|
|
43 |
}
|
44 |
)
|
45 |
return gr.LinePlot.update(data, x="Number of requests", y="Cost ($)",color="AI model service",color_legend_position="bottom", title="Total Cost of Model Serving for one month", height=300, width=500, tooltip=["Number of requests", "Cost ($)", "AI model service"])
|
46 |
|
47 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
48 |
+
Models: list[models.BaseTCOModel] = [models.OpenAIModel, models.CohereModel, models.OpenSourceLlama2Model]
|
49 |
model_names = [Model().get_name() for Model in Models]
|
50 |
gr.Markdown(value=text)
|
51 |
gr.Markdown(value=description)
|
52 |
|
53 |
with gr.Row():
|
54 |
with gr.Column():
|
55 |
+
# with gr.Row():
|
56 |
+
# gr.Markdown(value=text0)
|
57 |
with gr.Row():
|
58 |
+
use_case = gr.Dropdown(["Summarize", "Question-Answering", "Classification"], value="Question-Answering", label="Describe your use case")
|
59 |
+
with gr.Accordion("Open to customize the number of input and output tokens for your use case", open=False):
|
60 |
+
with gr.Row():
|
61 |
+
input_tokens = gr.Slider(minimum=1, maximum=1000, value=300, step=1, label="Number of input token", info="We put a value that we find best suit your use case choice but feel free to adjust", interactive=True)
|
62 |
+
output_tokens = gr.Slider(minimum=1, maximum=1000, value=300, step=1, label="Number of output token", info="We put a value that we find best suit your use case choice but feel free to adjust", interactive=True)
|
63 |
+
with gr.Row(visible=False):
|
64 |
+
num_users = gr.Number(value="1000", interactive = True, label="Number of users for your service")
|
|
|
65 |
|
66 |
use_case.change(on_use_case_change, inputs=use_case, outputs=[input_tokens, output_tokens])
|
67 |
|
68 |
with gr.Row():
|
69 |
with gr.Column():
|
70 |
+
#gr.Markdown(value=text1)
|
71 |
page1 = models.ModelPage(Models)
|
72 |
+
dropdown = gr.Dropdown(model_names, interactive=True, label="AI service option 1")
|
73 |
+
with gr.Accordion("Open for more information on the computation parameters for your first AI service option", open=False):
|
74 |
+
page1.render()
|
75 |
|
76 |
with gr.Column():
|
77 |
+
#gr.Markdown(value=text2)
|
78 |
page2 = models.ModelPage(Models)
|
79 |
+
dropdown2 = gr.Dropdown(model_names, interactive=True, label="AI service option 2")
|
80 |
+
with gr.Accordion("Open for more information on the computation parameters for your second AI service option", open=False):
|
81 |
+
page2.render()
|
82 |
|
83 |
+
dropdown.change(page1.make_model_visible, inputs=[dropdown, use_case], outputs=page1.get_all_components())
|
84 |
+
dropdown2.change(page2.make_model_visible, inputs=[dropdown2, use_case], outputs=page2.get_all_components())
|
85 |
|
86 |
+
#gr.Markdown(value=text3)
|
87 |
compute_tco_btn = gr.Button("Compute cost/request and TCOs", size="lg")
|
88 |
tco1 = gr.State()
|
89 |
tco2 = gr.State()
|
90 |
+
labour_cost1 = gr.State()
|
91 |
+
labour_cost2 = gr.State()
|
92 |
|
93 |
with gr.Row():
|
94 |
with gr.Column():
|
95 |
+
tco_output = gr.Text("Output 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 a Total Cost of Model Serving")
|
96 |
latency_info = gr.Markdown()
|
97 |
with gr.Accordion("Open to see the formula", open=False):
|
98 |
tco_formula = gr.Markdown()
|
99 |
|
100 |
with gr.Column():
|
101 |
+
tco_output2 = gr.Text("Output 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 a Total Cost of Model Serving")
|
102 |
latency_info2 = gr.Markdown()
|
103 |
with gr.Accordion("Open to see the formula", open=False):
|
104 |
tco_formula2 = gr.Markdown()
|
|
|
109 |
with gr.Column(scale=3):
|
110 |
plot = gr.LinePlot()
|
111 |
|
112 |
+
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, labour_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, labour_cost2]).then(compare, inputs=[tco1, tco2], outputs=ratio).then(update_plot, inputs=[tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2], outputs=plot)
|
113 |
|
114 |
demo.launch(debug=True)
|