jadehardouin
commited on
Commit
•
f4c03fc
1
Parent(s):
649c4c8
Update app.py
Browse files
app.py
CHANGED
@@ -12,8 +12,8 @@ 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.</p>
|
16 |
-
<p>First, you'll have to
|
17 |
"""
|
18 |
|
19 |
def on_use_case_change(use_case):
|
@@ -24,15 +24,42 @@ def on_use_case_change(use_case):
|
|
24 |
else:
|
25 |
return gr.update(value=50), gr.update(value=10)
|
26 |
|
27 |
-
def compare(tco1, tco2):
|
28 |
r = tco1 / tco2
|
|
|
|
|
29 |
if r < 1:
|
30 |
-
comparison_result = f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
elif r > 1:
|
32 |
-
comparison_result = f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
else:
|
34 |
-
comparison_result = "Both solutions
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
def update_plot(tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2):
|
38 |
|
@@ -129,8 +156,8 @@ class Style(Base):
|
|
129 |
button_shadow="*shadow_drop_lg",
|
130 |
|
131 |
block_title_background_fill="#f0ba2d", #The background of the title of a form element (e.g. textbox).
|
132 |
-
block_title_background_fill_dark="#f0ba2d",
|
133 |
-
block_title_radius="*radius_sm"
|
134 |
block_title_text_color="#050f19", #The text color of the title of a form element (e.g. textbox).
|
135 |
block_title_text_color_dark="#050f19",
|
136 |
block_title_text_size="*text_lg",
|
@@ -164,10 +191,10 @@ with gr.Blocks(theme=style) as demo:
|
|
164 |
# gr.Markdown(value=text0)
|
165 |
with gr.Row():
|
166 |
use_case = gr.Dropdown(["Summarize", "Question-Answering", "Classification"], value="Question-Answering", label=" Describe your use case ")
|
167 |
-
with gr.Accordion("Click here to customize the number of input and output tokens
|
168 |
with gr.Row():
|
169 |
-
input_tokens = gr.Slider(minimum=1, maximum=1000, value=300, step=1, label="
|
170 |
-
output_tokens = gr.Slider(minimum=1, maximum=1000, value=300, step=1, label="
|
171 |
with gr.Row(visible=False):
|
172 |
num_users = gr.Number(value="1000", interactive = True, label=" Number of users for your service ")
|
173 |
|
@@ -192,31 +219,31 @@ with gr.Blocks(theme=style) as demo:
|
|
192 |
dropdown2.change(page2.make_model_visible, inputs=[dropdown2, use_case], outputs=page2.get_all_components())
|
193 |
|
194 |
#gr.Markdown(value=text3)
|
195 |
-
compute_tco_btn = gr.Button("Compute
|
196 |
tco1 = gr.State()
|
197 |
tco2 = gr.State()
|
198 |
-
|
199 |
-
|
200 |
|
201 |
with gr.Row():
|
202 |
with gr.Column():
|
203 |
-
tco_output = gr.Text("
|
204 |
latency_info = gr.Markdown()
|
205 |
with gr.Accordion("Click here to see the formula", open=False):
|
206 |
tco_formula = gr.Markdown()
|
207 |
|
208 |
with gr.Column():
|
209 |
-
tco_output2 = gr.Text("
|
210 |
latency_info2 = gr.Markdown()
|
211 |
with gr.Accordion("Click here to see the formula", open=False):
|
212 |
tco_formula2 = gr.Markdown()
|
213 |
|
214 |
with gr.Row():
|
215 |
with gr.Column(scale=1):
|
216 |
-
ratio = gr.Text("
|
217 |
with gr.Column(scale=3):
|
218 |
plot = gr.LinePlot()
|
219 |
|
220 |
-
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,
|
221 |
|
222 |
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.</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 |
|
19 |
def on_use_case_change(use_case):
|
|
|
24 |
else:
|
25 |
return gr.update(value=50), gr.update(value=10)
|
26 |
|
27 |
+
def compare(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2):
|
28 |
r = tco1 / tco2
|
29 |
+
r2 = labor_cost1 / labor_cost2
|
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 r2 > 1:
|
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 r2 < 1:
|
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 r2 > 1:
|
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 r2 < 1:
|
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}."
|
50 |
+
else:
|
51 |
+
comparison_result2 = f"Additionally, both services have the same labor cost per month."
|
52 |
+
|
53 |
else:
|
54 |
+
comparison_result = f"Both solutions have the same cost/request."
|
55 |
+
if r2 > 1:
|
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 r2 < 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 |
|
64 |
def update_plot(tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2):
|
65 |
|
|
|
156 |
button_shadow="*shadow_drop_lg",
|
157 |
|
158 |
block_title_background_fill="#f0ba2d", #The background of the title of a form element (e.g. textbox).
|
159 |
+
block_title_background_fill_dark="#f0ba2d",
|
160 |
+
block_title_radius="*radius_sm",#The corner radius of the title of a form element (e.g. textbox).
|
161 |
block_title_text_color="#050f19", #The text color of the title of a form element (e.g. textbox).
|
162 |
block_title_text_color_dark="#050f19",
|
163 |
block_title_text_size="*text_lg",
|
|
|
191 |
# gr.Markdown(value=text0)
|
192 |
with gr.Row():
|
193 |
use_case = gr.Dropdown(["Summarize", "Question-Answering", "Classification"], value="Question-Answering", label=" Describe your use case ")
|
194 |
+
with gr.Accordion("Click here if you want to customize the number of input and output tokens per request", open=False):
|
195 |
with gr.Row():
|
196 |
+
input_tokens = gr.Slider(minimum=1, maximum=1000, value=300, step=1, label=" Input tokens per request", info="We suggest a value that we believe best suit your use case choice but feel free to adjust", interactive=True)
|
197 |
+
output_tokens = gr.Slider(minimum=1, maximum=1000, value=300, step=1, label=" Output tokens per request", info="We suggest a value that we believe best suit your use case choice but feel free to adjust", interactive=True)
|
198 |
with gr.Row(visible=False):
|
199 |
num_users = gr.Number(value="1000", interactive = True, label=" Number of users for your service ")
|
200 |
|
|
|
219 |
dropdown2.change(page2.make_model_visible, inputs=[dropdown2, use_case], outputs=page2.get_all_components())
|
220 |
|
221 |
#gr.Markdown(value=text3)
|
222 |
+
compute_tco_btn = gr.Button("Compute & Compare", size="lg", variant="primary", scale=1)
|
223 |
tco1 = gr.State()
|
224 |
tco2 = gr.State()
|
225 |
+
labor_cost1 = gr.State()
|
226 |
+
labor_cost2 = gr.State()
|
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 a Total Cost of Model Serving")
|
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 a Total Cost of Model Serving")
|
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 |
+
ratio = gr.Text("Comparison: ", label=" Comparison of cost/request and TCOs")
|
244 |
with gr.Column(scale=3):
|
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)
|