Spaces:
Running
Running
jadehardouin
commited on
Commit
•
5919083
1
Parent(s):
37a671b
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import models
|
3 |
import pandas as pd
|
4 |
-
|
5 |
-
from gradio.themes.utils.colors import Color
|
6 |
-
from gradio.themes.utils import colors, fonts, sizes
|
7 |
-
from typing import Iterable
|
8 |
|
9 |
text = "<h1 style='text-align: center; color: #f0ba2d; font-size: 40px;'>TCO Comparison Calculator"
|
10 |
text0 = "<h1 style='text-align: center; color: midnightblue; font-size: 30px;'>Describe your use case"
|
@@ -13,7 +10,21 @@ text2 = "<h1 style='text-align: center; color: midnightblue; font-size: 25px;'>S
|
|
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 |
|
19 |
def on_use_case_change(use_case):
|
@@ -31,36 +42,25 @@ def compare(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2):
|
|
31 |
if r < 1:
|
32 |
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."
|
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 second {dropdown2} service is {r:.5f} times cheaper than the one of the first {dropdown} service."
|
44 |
-
if labor_cost1
|
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}."
|
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 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 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
def create_table(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2):
|
66 |
list_values = []
|
@@ -78,9 +78,9 @@ def create_table(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2):
|
|
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': '#
|
82 |
.to_html()
|
83 |
-
|
84 |
return gr.update(value=styled_data)
|
85 |
|
86 |
def update_plot(tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2):
|
@@ -95,111 +95,9 @@ def update_plot(tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2):
|
|
95 |
"AI model service": ["1)" + " " + dropdown] * len(request_ranges) + ["2)" + " " + dropdown2] * len(request_ranges)
|
96 |
}
|
97 |
)
|
98 |
-
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"])
|
99 |
|
100 |
-
|
101 |
-
name="light_grey",
|
102 |
-
c50="#e0e0e0",
|
103 |
-
c100="#e0e0e0",
|
104 |
-
c200="#e0e0e0",
|
105 |
-
c300="#e0e0e0",
|
106 |
-
c400="#e0e0e0",
|
107 |
-
c500="#e0e0e0",
|
108 |
-
c600="#e0e0e0",
|
109 |
-
c700="#e0e0e0",
|
110 |
-
c800="#e0e0e0",
|
111 |
-
c900="#e0e0e0",
|
112 |
-
c950="#e0e0e0",
|
113 |
-
)
|
114 |
-
|
115 |
-
class Style(Base):
|
116 |
-
def __init__(
|
117 |
-
self,
|
118 |
-
*,
|
119 |
-
primary_hue: colors.Color | str = light_grey,
|
120 |
-
secondary_hue: colors.Color | str = light_grey,
|
121 |
-
neutral_hue: colors.Color | str = light_grey,
|
122 |
-
spacing_size: sizes.Size | str = sizes.spacing_md,
|
123 |
-
radius_size: sizes.Size | str = sizes.radius_md,
|
124 |
-
text_size: sizes.Size | str = sizes.text_md,
|
125 |
-
font: fonts.Font
|
126 |
-
| str
|
127 |
-
| Iterable[fonts.Font | str] = (fonts.GoogleFont("Sora")),
|
128 |
-
font_mono: fonts.Font
|
129 |
-
| str
|
130 |
-
| Iterable[fonts.Font | str] = (fonts.GoogleFont("Sora")),
|
131 |
-
):
|
132 |
-
super().__init__(
|
133 |
-
primary_hue=primary_hue,
|
134 |
-
secondary_hue=secondary_hue,
|
135 |
-
neutral_hue=neutral_hue,
|
136 |
-
spacing_size=spacing_size,
|
137 |
-
radius_size=radius_size,
|
138 |
-
text_size=text_size,
|
139 |
-
font=font,
|
140 |
-
font_mono=font_mono,
|
141 |
-
)
|
142 |
-
super().set(
|
143 |
-
background_fill_primary="#050f19", #The color of the background of blocks
|
144 |
-
background_fill_secondary="#050f19",
|
145 |
-
block_background_fill="#050f19", #The color of the background of blocks
|
146 |
-
block_background_fill_dark="#050f19",
|
147 |
-
|
148 |
-
border_color_primary="#050f19", #The border of a block such as dropdown
|
149 |
-
border_color_primary_dark="#050f19",
|
150 |
-
|
151 |
-
link_text_color="#f0ba2d", #The color for links
|
152 |
-
link_text_color_dark="#f0ba2d",
|
153 |
-
|
154 |
-
block_info_text_color="ffffff",
|
155 |
-
block_info_text_color_dark="ffffff",
|
156 |
-
|
157 |
-
block_border_color="#050f19", #The border color around an item (e.g. Accordion)
|
158 |
-
block_border_color_dark="#050f19",
|
159 |
-
block_shadow="*shadow_drop_lg",
|
160 |
-
#form_gap_width="*spacing_md", #The border gap between form elements, (e.g. consecutive textboxes)
|
161 |
-
|
162 |
-
input_background_fill="#081527", #The background of an input field
|
163 |
-
input_background_fill_dark="#081527",
|
164 |
-
input_border_color="#050f19",
|
165 |
-
input_border_color_dark="#050f19",
|
166 |
-
input_border_width="2px",
|
167 |
-
|
168 |
-
block_label_background_fill="#f0ba2d",
|
169 |
-
block_label_background_fill_dark="#f0ba2d",
|
170 |
-
block_label_border_color=None,
|
171 |
-
block_label_border_color_dark=None,
|
172 |
-
block_label_text_color="#050f19",
|
173 |
-
block_label_text_color_dark="#050f19",
|
174 |
-
|
175 |
-
button_primary_background_fill="#ffffff",
|
176 |
-
button_primary_border_color="#ffffff",
|
177 |
-
button_primary_text_color="#050f19",
|
178 |
-
button_shadow="*shadow_drop_lg",
|
179 |
-
|
180 |
-
block_title_background_fill="#f0ba2d", #The background of the title of a form element (e.g. textbox).
|
181 |
-
block_title_background_fill_dark="#f0ba2d",
|
182 |
-
block_title_radius="*radius_sm",#The corner radius of the title of a form element (e.g. textbox).
|
183 |
-
block_title_text_color="#050f19", #The text color of the title of a form element (e.g. textbox).
|
184 |
-
block_title_text_color_dark="#050f19",
|
185 |
-
block_title_text_size="*text_lg",
|
186 |
-
block_title_border_width="2px", #The border around the title of a form element (e.g. textbox)
|
187 |
-
block_title_border_width_dark="2px",
|
188 |
-
block_title_border_color="#f0ba2d",
|
189 |
-
block_title_border_color_dark="#f0ba2d",
|
190 |
-
|
191 |
-
body_background_fill="#050f19",
|
192 |
-
body_background_fill_dark="#050f19",
|
193 |
-
body_text_color="#ffffff", #The default text color.
|
194 |
-
body_text_color_dark="#ffffff",
|
195 |
-
body_text_color_subdued="#ffffff",
|
196 |
-
body_text_color_subdued_dark="#ffffff",
|
197 |
-
|
198 |
-
slider_color="*secondary_300",
|
199 |
-
slider_color_dark="*secondary_600",
|
200 |
-
)
|
201 |
-
|
202 |
-
style = Style()
|
203 |
|
204 |
with gr.Blocks(theme=style) as demo:
|
205 |
Models: list[models.BaseTCOModel] = [models.OpenAIModel, models.CohereModel, models.OpenSourceLlama2Model]
|
@@ -209,8 +107,6 @@ with gr.Blocks(theme=style) as demo:
|
|
209 |
|
210 |
with gr.Row():
|
211 |
with gr.Column():
|
212 |
-
# with gr.Row():
|
213 |
-
# gr.Markdown(value=text0)
|
214 |
with gr.Row():
|
215 |
use_case = gr.Dropdown(["Summarize", "Question-Answering", "Classification"], value="Question-Answering", label=" Describe your use case ")
|
216 |
with gr.Accordion("Click here if you want to customize the number of input and output tokens per request", open=False):
|
@@ -224,14 +120,12 @@ with gr.Blocks(theme=style) as demo:
|
|
224 |
|
225 |
with gr.Row():
|
226 |
with gr.Column():
|
227 |
-
#gr.Markdown(value=text1)
|
228 |
page1 = models.ModelPage(Models)
|
229 |
dropdown = gr.Dropdown(model_names, interactive=True, label=" First AI service option ")
|
230 |
with gr.Accordion("Click here for more information on the computation parameters for your first AI service option", open=False):
|
231 |
page1.render()
|
232 |
|
233 |
with gr.Column():
|
234 |
-
#gr.Markdown(value=text2)
|
235 |
page2 = models.ModelPage(Models)
|
236 |
dropdown2 = gr.Dropdown(model_names, interactive=True, label=" Second AI service option ")
|
237 |
with gr.Accordion("Click here for more information on the computation parameters for your second AI service option", open=False):
|
@@ -240,7 +134,6 @@ with gr.Blocks(theme=style) as demo:
|
|
240 |
dropdown.change(page1.make_model_visible, inputs=[dropdown, use_case], outputs=page1.get_all_components())
|
241 |
dropdown2.change(page2.make_model_visible, inputs=[dropdown2, use_case], outputs=page2.get_all_components())
|
242 |
|
243 |
-
#gr.Markdown(value=text3)
|
244 |
compute_tco_btn = gr.Button("Compute & Compare", size="lg", variant="primary", scale=1)
|
245 |
tco1 = gr.State()
|
246 |
tco2 = gr.State()
|
@@ -261,13 +154,16 @@ with gr.Blocks(theme=style) as demo:
|
|
261 |
tco_formula2 = gr.Markdown()
|
262 |
|
263 |
with gr.Row():
|
264 |
-
|
265 |
-
|
|
|
|
|
266 |
table = gr.Markdown()
|
267 |
-
ratio = gr.Markdown()
|
268 |
with gr.Column(scale=2):
|
269 |
-
|
|
|
|
|
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=
|
272 |
|
273 |
demo.launch(debug=True)
|
|
|
1 |
import gradio as gr
|
2 |
import models
|
3 |
import pandas as pd
|
4 |
+
import theme
|
|
|
|
|
|
|
5 |
|
6 |
text = "<h1 style='text-align: center; color: #f0ba2d; font-size: 40px;'>TCO Comparison Calculator"
|
7 |
text0 = "<h1 style='text-align: center; color: midnightblue; font-size: 30px;'>Describe your use case"
|
|
|
10 |
text3 = "<h1 style='text-align: center; color: midnightblue; font-size: 30px;'>Compute and compare TCOs"
|
11 |
description=f"""
|
12 |
<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>
|
13 |
+
<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 experienced by your service. You can compare both solutions to evaluate which one best suits your needs.</p>
|
14 |
+
"""
|
15 |
+
markdown = """
|
16 |
+
<div style="
|
17 |
+
background-color: #f0ba2d;
|
18 |
+
color: #050f19;
|
19 |
+
border-radius: 10px;
|
20 |
+
padding: 3px;
|
21 |
+
margin: 0 auto;
|
22 |
+
width: 150px;
|
23 |
+
text-align: center;
|
24 |
+
font-size: 18px;
|
25 |
+
">
|
26 |
+
Comparison
|
27 |
+
</div>
|
28 |
"""
|
29 |
|
30 |
def on_use_case_change(use_case):
|
|
|
42 |
if r < 1:
|
43 |
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."
|
44 |
if labor_cost1 > labor_cost2:
|
|
|
45 |
meeting_point = (labor_cost2 - labor_cost1) / (tco1 - tco2)
|
46 |
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}."
|
|
|
|
|
|
|
|
|
47 |
|
48 |
elif r > 1:
|
49 |
comparison_result = f"The cost/request of the second {dropdown2} service is {r:.5f} times cheaper than the one of the first {dropdown} service."
|
50 |
+
if labor_cost1 < labor_cost2:
|
|
|
|
|
|
|
51 |
meeting_point = (labor_cost2 - labor_cost1) / (tco1 - tco2)
|
52 |
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}."
|
|
|
|
|
53 |
|
54 |
else:
|
55 |
comparison_result = f"Both solutions have the same cost/request."
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
info = f"""
|
58 |
+
<br>
|
59 |
+
<p> {comparison_result} </p>
|
60 |
+
<br>
|
61 |
+
<p> {comparison_result3} </p>
|
62 |
+
"""
|
63 |
+
return info
|
64 |
|
65 |
def create_table(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2):
|
66 |
list_values = []
|
|
|
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': '#081527', '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):
|
|
|
95 |
"AI model service": ["1)" + " " + dropdown] * len(request_ranges) + ["2)" + " " + dropdown2] * len(request_ranges)
|
96 |
}
|
97 |
)
|
98 |
+
return gr.LinePlot.update(data, visible=True, 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"])
|
99 |
|
100 |
+
style = theme.Style()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
with gr.Blocks(theme=style) as demo:
|
103 |
Models: list[models.BaseTCOModel] = [models.OpenAIModel, models.CohereModel, models.OpenSourceLlama2Model]
|
|
|
107 |
|
108 |
with gr.Row():
|
109 |
with gr.Column():
|
|
|
|
|
110 |
with gr.Row():
|
111 |
use_case = gr.Dropdown(["Summarize", "Question-Answering", "Classification"], value="Question-Answering", label=" Describe your use case ")
|
112 |
with gr.Accordion("Click here if you want to customize the number of input and output tokens per request", open=False):
|
|
|
120 |
|
121 |
with gr.Row():
|
122 |
with gr.Column():
|
|
|
123 |
page1 = models.ModelPage(Models)
|
124 |
dropdown = gr.Dropdown(model_names, interactive=True, label=" First AI service option ")
|
125 |
with gr.Accordion("Click here for more information on the computation parameters for your first AI service option", open=False):
|
126 |
page1.render()
|
127 |
|
128 |
with gr.Column():
|
|
|
129 |
page2 = models.ModelPage(Models)
|
130 |
dropdown2 = gr.Dropdown(model_names, interactive=True, label=" Second AI service option ")
|
131 |
with gr.Accordion("Click here for more information on the computation parameters for your second AI service option", open=False):
|
|
|
134 |
dropdown.change(page1.make_model_visible, inputs=[dropdown, use_case], outputs=page1.get_all_components())
|
135 |
dropdown2.change(page2.make_model_visible, inputs=[dropdown2, use_case], outputs=page2.get_all_components())
|
136 |
|
|
|
137 |
compute_tco_btn = gr.Button("Compute & Compare", size="lg", variant="primary", scale=1)
|
138 |
tco1 = gr.State()
|
139 |
tco2 = gr.State()
|
|
|
154 |
tco_formula2 = gr.Markdown()
|
155 |
|
156 |
with gr.Row():
|
157 |
+
gr.Markdown(markdown)
|
158 |
+
|
159 |
+
with gr.Row(variant='panel'):
|
160 |
+
with gr.Column(scale=1):
|
161 |
table = gr.Markdown()
|
|
|
162 |
with gr.Column(scale=2):
|
163 |
+
info = gr.Markdown()
|
164 |
+
with gr.Row():
|
165 |
+
plot = gr.LinePlot(visible=False)
|
166 |
|
167 |
+
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).then(update_plot, inputs=[tco1, tco2, dropdown, dropdown2, labor_cost1, labor_cost2], outputs=plot)
|
168 |
|
169 |
demo.launch(debug=True)
|