jadehardouin commited on
Commit
1c2b775
1 Parent(s): 76168c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -59
app.py CHANGED
@@ -2,30 +2,13 @@ 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"
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>
15
- """
16
- markdown = """
17
- <div style="
18
- background-color: #f0ba2d;
19
- color: #050f19;
20
- border-radius: 10px;
21
- padding: 3px;
22
- margin: 0 auto;
23
- width: 150px;
24
- text-align: center;
25
- font-size: 18px;
26
- ">
27
- Comparison
28
- </div>
29
  """
30
 
31
  def on_use_case_change(use_case):
@@ -36,34 +19,25 @@ def on_use_case_change(use_case):
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
-
43
- if r < 1:
44
- 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."
45
- if labor_cost1 > labor_cost2:
46
- meeting_point = (labor_cost2 - labor_cost1) / (tco1 - tco2)
47
- 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}."
48
 
49
- elif r > 1:
50
- comparison_result = f"The cost/request of the second {dropdown2} service is {r:.5f} times cheaper than the one of the first {dropdown} service."
51
- if labor_cost1 < labor_cost2:
52
- meeting_point = (labor_cost2 - labor_cost1) / (tco1 - tco2)
53
- 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}."
54
 
55
- else:
56
- comparison_result = f"Both solutions have the same cost/request."
57
-
58
- info = f"""
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 = []
@@ -79,14 +53,15 @@ def create_table(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2, late
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'})\
83
  .to_html()
 
84
 
85
- return gr.update(value=styled_data)
86
 
87
  def update_plot(tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2):
88
 
89
- request_ranges = [100, 200, 300, 400, 500, 1000, 10000]
90
  costs_tco1 = [(tco1 * req + labour_cost1) for req in request_ranges]
91
  costs_tco2 = [(tco2 * req + labour_cost2) for req in request_ranges]
92
 
@@ -96,7 +71,7 @@ def update_plot(tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2):
96
  "AI model service": ["1)" + " " + dropdown] * len(request_ranges) + ["2)" + " " + dropdown2] * len(request_ranges)
97
  }
98
  )
99
- 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"])
100
 
101
  style = theme.Style()
102
 
@@ -152,13 +127,16 @@ with gr.Blocks(theme=style) as demo:
152
  tco_formula2 = gr.Markdown()
153
 
154
  with gr.Row(variant='panel'):
155
- with gr.Column(scale=2):
156
- table = gr.Markdown()
157
- with gr.Column(scale=3):
158
- info = gr.Markdown()
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)
 
2
  import models
3
  import pandas as pd
4
  import theme
5
+ import matplotlib.pyplot as plt
6
 
7
+ text = "<h1 style='text-align: center; color: #333333; font-size: 40px;'>TCO Comparison Calculator"
8
+ text2 = "Please note that the cost/request only defines the infrastructure cost for deployment. The labor cost must be added for the whole AI model service deployment TCO."
 
 
 
 
9
  description=f"""
10
+ <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>
11
+ <p>Please note that we focus on getting the service up and running, but not the maintenance that follows.</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  """
13
 
14
  def on_use_case_change(use_case):
 
19
  else:
20
  return gr.update(value=50), gr.update(value=10)
21
 
22
+ def compare_info(tco1, tco2, dropdown, dropdown2):
23
+ # Create a bar chart
24
+ services = [dropdown, dropdown2]
25
+ costs_to_compare = [tco1, tco2]
 
 
 
 
 
26
 
27
+ plt.figure(figsize=(6, 4))
28
+ plt.bar(services, costs_to_compare, color=['red', 'green'])
29
+ plt.xlabel('AI option services', fontsize=10)
30
+ plt.ylabel('($) Cost/Request', fontsize=10)
31
+ plt.title('Comparison of Cost/Request', fontsize=14)
32
 
33
+ # Customize x-axis labels
34
+ #plt.xticks(rotation=30, ha='right') # Rotate by 30 degrees and align to the right
35
+
36
+ # Save the plot to a file or display it
37
+ plt.tight_layout()
38
+ plt.savefig('cost_comparison.png') # Save to a file
39
+
40
+ return gr.update(value='cost_comparison.png')
 
 
 
 
41
 
42
  def create_table(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2, latency, latency2):
43
  list_values = []
 
53
  formatted_data["Labor Cost ($/month)"] = formatted_data["Labor Cost ($/month)"].apply('{:.0f}'.format)
54
 
55
  styled_data = formatted_data.style\
56
+ .set_properties(**{'background-color': '#ffffff', 'color': '#000000', 'border-color': '#e0e0e0', 'border-width': '1px', 'border-style': 'solid'})\
57
  .to_html()
58
+ centered_styled_data = f"<center>{styled_data}</center>"
59
 
60
+ return gr.update(value=centered_styled_data)
61
 
62
  def update_plot(tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2):
63
 
64
+ request_ranges = list(range(0, 1001, 100)) + list(range(1000, 10001, 500)) + list(range(10000, 100001, 1000)) + list(range(100000, 2000001, 100000))
65
  costs_tco1 = [(tco1 * req + labour_cost1) for req in request_ranges]
66
  costs_tco2 = [(tco2 * req + labour_cost2) for req in request_ranges]
67
 
 
71
  "AI model service": ["1)" + " " + dropdown] * len(request_ranges) + ["2)" + " " + dropdown2] * len(request_ranges)
72
  }
73
  )
74
+ return gr.LinePlot.update(data, visible=True, x="Number of requests", y="Cost ($)",color="AI model service",color_legend_position="bottom", title="Set-up TCO for one month", height=300, width=500, tooltip=["Number of requests", "Cost ($)", "AI model service"])
75
 
76
  style = theme.Style()
77
 
 
127
  tco_formula2 = gr.Markdown()
128
 
129
  with gr.Row(variant='panel'):
130
+ with gr.Column():
131
+ with gr.Row():
132
+ table = gr.Markdown()
133
+ with gr.Row():
134
+ with gr.Column(scale=1):
135
+ image = gr.Image()
136
+ info = gr.Markdown(text2)
137
+ with gr.Column(scale=2):
138
+ plot = gr.LinePlot(visible=False)
139
 
140
+ 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, dropdown, dropdown2], outputs=image).then(update_plot, inputs=[tco1, tco2, dropdown, dropdown2, labor_cost1, labor_cost2], outputs=plot)
141
 
142
  demo.launch(debug=True)