jadehardouin commited on
Commit
9411fc2
1 Parent(s): e4a17ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -13
app.py CHANGED
@@ -10,7 +10,16 @@ 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):
15
  if use_case == "Summarize":
16
  return gr.update(value=500), gr.update(value=200)
@@ -20,6 +29,15 @@ def on_use_case_change(use_case):
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]
@@ -29,15 +47,11 @@ def compare_info(tco1, tco2, dropdown, dropdown2):
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 = []
@@ -120,23 +134,21 @@ with gr.Blocks(theme=style) as demo:
120
 
121
  with gr.Row():
122
  with gr.Accordion("Click here to see the cost/request computation formula", open=False):
123
- with gr.Row():
124
- with gr.Column():
125
- tco_formula = gr.Markdown()
126
- with gr.Column():
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)
 
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
+ formula = r"""
14
+ $CR = \frac{CIT\_1K \times IT + COT\_1K \times OT}{1000}$ <br>
15
+ with: <br>
16
+ CR = Cost per Request <br>
17
+ CIT_1K = Cost per 1000 Input Tokens <br>
18
+ COT_1K = Cost per 1000 Output Tokens <br>
19
+ IT = Input Tokens <br>
20
+ OT = Output Tokens
21
+ """
22
+
23
  def on_use_case_change(use_case):
24
  if use_case == "Summarize":
25
  return gr.update(value=500), gr.update(value=200)
 
29
  return gr.update(value=50), gr.update(value=10)
30
 
31
  def compare_info(tco1, tco2, dropdown, dropdown2):
32
+ #Compute the cost/request ratio
33
+ r = tco1 / tco2
34
+ if r < 1:
35
+ comparison_result = f"""The cost/request of the second {dropdown2} service is <b>{1/r:.5f} times more expensive</b> than the one of the first {dropdown} service."""
36
+ elif r > 1:
37
+ comparison_result = f"""The cost/request of the second {dropdown2} service is <b>{r:.5f} times cheaper</b> than the one of the first {dropdown} service."""
38
+ else:
39
+ comparison_result = f"""Both solutions have the <b>same cost/request</b>."""
40
+
41
  # Create a bar chart
42
  services = [dropdown, dropdown2]
43
  costs_to_compare = [tco1, tco2]
 
47
  plt.xlabel('AI option services', fontsize=10)
48
  plt.ylabel('($) Cost/Request', fontsize=10)
49
  plt.title('Comparison of Cost/Request', fontsize=14)
 
 
 
50
 
 
51
  plt.tight_layout()
52
  plt.savefig('cost_comparison.png') # Save to a file
53
 
54
+ return gr.update(value='cost_comparison.png'), comparison_result
55
 
56
  def create_table(tco1, tco2, labor_cost1, labor_cost2, dropdown, dropdown2, latency, latency2):
57
  list_values = []
 
134
 
135
  with gr.Row():
136
  with gr.Accordion("Click here to see the cost/request computation formula", open=False):
137
+ tco_formula = gr.Markdown(formula)
 
 
 
 
138
 
139
  with gr.Row(variant='panel'):
140
  with gr.Column():
141
  with gr.Row():
142
  table = gr.Markdown()
143
+ with gr.Row():
144
+ info = gr.Markdown(text2)
145
  with gr.Row():
146
  with gr.Column(scale=1):
147
  image = gr.Image()
148
+ ratio = gr.Markdown()
149
  with gr.Column(scale=2):
150
  plot = gr.LinePlot(visible=False)
151
 
152
+ compute_tco_btn.click(page1.compute_cost_per_token, inputs=page1.get_all_components_for_cost_computing() + [dropdown, input_tokens, output_tokens], outputs=[tco1, latency, labor_cost1]).then(page2.compute_cost_per_token, inputs=page2.get_all_components_for_cost_computing() + [dropdown2, input_tokens, output_tokens], outputs=[tco2, 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, ratio]).then(update_plot, inputs=[tco1, tco2, dropdown, dropdown2, labor_cost1, labor_cost2], outputs=plot)
153
 
154
  demo.launch(debug=True)