jadehardouin commited on
Commit
ea19e17
1 Parent(s): 0680f69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -7
app.py CHANGED
@@ -1,25 +1,72 @@
1
  import gradio as gr
2
  import models
 
 
 
 
 
 
 
 
 
 
3
 
4
- with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  Models: list[models.BaseTCOModel] = [models.OpenAIModel, models.OpenSourceLlama2Model]
6
  model_names = [Model().get_name() for Model in Models]
 
 
 
7
  with gr.Row():
8
  with gr.Column():
 
9
  page1 = models.ModelPage(Models)
10
- dropdown = gr.Dropdown(model_names, interactive=True)
11
  page1.render()
12
 
13
  with gr.Column():
 
14
  page2 = models.ModelPage(Models)
15
- dropdown2 = gr.Dropdown(model_names, interactive=True)
16
  page2.render()
17
 
18
  dropdown.change(page1.make_model_visible, inputs=dropdown, outputs=page1.get_all_components())
19
  dropdown2.change(page2.make_model_visible, inputs=dropdown2, outputs=page2.get_all_components())
20
-
21
- compute_tco_btn = gr.Button("Compute TCO")
22
- tco_output = gr.Text("Output: ")
23
- compute_tco_btn.click(page1.compute_cost_per_token, inputs=page1.get_all_components_for_cost_computing() + [dropdown], outputs=tco_output)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  demo.launch(debug=True)
 
1
  import gradio as gr
2
  import models
3
+ import time
4
+
5
+ text = "<h1 style='text-align: center; color: blue; font-size: 30px;'>TCO Comparison Calculator"
6
+ text1 = "<h1 style='text-align: center; color: blue; font-size: 20px;'>First solution"
7
+ text2 = "<h1 style='text-align: center; color: blue; font-size: 20px;'>Second solution"
8
+ text3 = "<h1 style='text-align: center; color: blue; font-size: 20px;'>Compute and compare TCOs"
9
+ description=f"""
10
+ <p>In this demo application, we help you compare different solutions for your AI incorporation plans, such as OpenSource or SaaS.</p>
11
+ <p>First, you'll have to choose the two solutions you'd like to compare. Then, follow the instructions to select your configurations for each solution and we will compute the cost/token accordingly to them. Eventually, you can compare both solutions to evaluate which one best suits your needs.</p>
12
+ """
13
 
14
+ def compute_ratio(tco1, tco2):
15
+ time.sleep(2)
16
+ try:
17
+ r = tco1 / tco2
18
+
19
+ if r < 1:
20
+ comparison_result = f"First solution is cheaper, with a ratio of {r:.5f}."
21
+ elif r > 1:
22
+ comparison_result = f"Second solution is cheaper, with a ratio of {r:.5f}."
23
+ else:
24
+ comparison_result = "Both solutions will cost the same."
25
+ return comparison_result
26
+
27
+ except ValueError as e:
28
+ return f"Error: {str(e)}"
29
+
30
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
31
  Models: list[models.BaseTCOModel] = [models.OpenAIModel, models.OpenSourceLlama2Model]
32
  model_names = [Model().get_name() for Model in Models]
33
+ gr.Markdown(value=text)
34
+ gr.Markdown(value=description)
35
+
36
  with gr.Row():
37
  with gr.Column():
38
+ gr.Markdown(value=text1)
39
  page1 = models.ModelPage(Models)
40
+ dropdown = gr.Dropdown(model_names, interactive=True, label="First solution")
41
  page1.render()
42
 
43
  with gr.Column():
44
+ gr.Markdown(value=text2)
45
  page2 = models.ModelPage(Models)
46
+ dropdown2 = gr.Dropdown(model_names, interactive=True, label="Second solution")
47
  page2.render()
48
 
49
  dropdown.change(page1.make_model_visible, inputs=dropdown, outputs=page1.get_all_components())
50
  dropdown2.change(page2.make_model_visible, inputs=dropdown2, outputs=page2.get_all_components())
51
+
52
+ gr.Markdown(value=text3)
53
+ compute_tco_btn = gr.Button("Compute TCOs", size="lg")
54
+ tco1 = gr.State()
55
+ tco2 = gr.State()
56
+
57
+ with gr.Row():
58
+ with gr.Column():
59
+ tco_output = gr.Text("Output 1: ", label="TCO for the first solution")
60
+ with gr.Accordion("Open to see the formula", open=False):
61
+ tco_formula = gr.Markdown()
62
+
63
+ with gr.Column():
64
+ tco_output2 = gr.Text("Output 2: ", label="TCO for the second solution")
65
+ with gr.Accordion("Open to see the formula", open=False):
66
+ tco_formula2 = gr.Markdown()
67
+
68
+ ratio = gr.Text("Ratio: ", label="Ratio of cost/token for both solutions")
69
+
70
+ compute_tco_btn.click(page1.compute_cost_per_token, inputs=page1.get_all_components_for_cost_computing() + [dropdown], outputs=[tco_output, tco1, tco_formula]).then(page2.compute_cost_per_token, inputs=page2.get_all_components_for_cost_computing() + [dropdown2], outputs=[tco_output2, tco2, tco_formula2]).then(compute_ratio, inputs=[tco1, tco2], outputs=ratio)
71
 
72
  demo.launch(debug=True)