jadehardouin commited on
Commit
7ebfebe
1 Parent(s): 5919083

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -24
app.py CHANGED
@@ -8,6 +8,7 @@ text0 = "<h1 style='text-align: center; color: midnightblue; font-size: 30px;'>D
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
  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>
@@ -35,7 +36,7 @@ def on_use_case_change(use_case):
35
  else:
36
  return gr.update(value=50), gr.update(value=10)
37
 
38
- def compare(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2):
39
  r = tco1 / tco2
40
  comparison_result3 = ""
41
 
@@ -58,24 +59,24 @@ def compare(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2):
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 = []
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=["1)" + " " + dropdown, "2)" + " " + 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': '#081527', 'color': '#ffffff', 'border-color': '#ffffff', 'border-width': '1px', 'border-style': 'solid'})\
@@ -139,22 +140,16 @@ with gr.Blocks(theme=style) as demo:
139
  tco2 = gr.State()
140
  labor_cost1 = gr.State()
141
  labor_cost2 = gr.State()
 
 
142
 
143
- with gr.Row():
144
- with gr.Column():
145
- 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.")
146
- latency_info = gr.Markdown()
147
- with gr.Accordion("Click here to see the formula", open=False):
148
- tco_formula = gr.Markdown()
149
-
150
- with gr.Column():
151
- 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.")
152
- latency_info2 = gr.Markdown()
153
- with gr.Accordion("Click here to see the formula", open=False):
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):
@@ -164,6 +159,6 @@ with gr.Blocks(theme=style) as demo:
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)
 
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. Please note that we focus on getting the service up and running, but not the maintenance that follows.</p>
14
  <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>
 
36
  else:
37
  return gr.update(value=50), gr.update(value=10)
38
 
39
+ def compare_info(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2):
40
  r = tco1 / tco2
41
  comparison_result3 = ""
42
 
 
59
  <br>
60
  <p> {comparison_result} </p>
61
  <br>
62
+ <p> {text4} </p>
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 = []
70
+ first_sol = [tco1, labor_cost1, latency]
71
+ second_sol = [tco2, labor_cost2, latency2]
 
 
72
  list_values.append(first_sol)
73
  list_values.append(second_sol)
74
 
75
+ data = pd.DataFrame(list_values, index=[dropdown, dropdown2], columns=["Cost/request ($) ", "Labor Cost ($/month)", "Average latency (s)"])
76
 
77
  formatted_data = data.copy()
78
  formatted_data["Cost/request ($) "] = formatted_data["Cost/request ($) "].apply('{:.5f}'.format)
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': '#081527', 'color': '#ffffff', 'border-color': '#ffffff', 'border-width': '1px', 'border-style': 'solid'})\
 
140
  tco2 = gr.State()
141
  labor_cost1 = gr.State()
142
  labor_cost2 = gr.State()
143
+ latency = gr.State()
144
+ latency2 = gr.State()
145
 
146
+ with gr.Row():
147
+ with gr.Accordion("Click here to see the cost/request computation formula", open=False):
148
+ with gr.Row():
149
+ with gr.Column():
150
+ tco_formula = gr.Markdown()
151
+ with gr.Column():
152
+ tco_formula2 = gr.Markdown()
 
 
 
 
 
 
 
 
153
 
154
  with gr.Row(variant='panel'):
155
  with gr.Column(scale=1):
 
159
  with gr.Row():
160
  plot = gr.LinePlot(visible=False)
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, labor_cost1, labor_cost2, dropdown, dropdown2], outputs=info).then(update_plot, inputs=[tco1, tco2, dropdown, dropdown2, labor_cost1, labor_cost2], outputs=plot)
163
 
164
  demo.launch(debug=True)