jadehardouin commited on
Commit
ecaa1ea
1 Parent(s): 7769b47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +106 -18
app.py CHANGED
@@ -1,8 +1,11 @@
1
  import gradio as gr
2
  import models
3
  import pandas as pd
 
 
 
4
 
5
- text = "<h1 style='text-align: center; color: midnightblue; font-size: 40px;'>TCO Comparison Calculator"
6
  text0 = "<h1 style='text-align: center; color: midnightblue; font-size: 30px;'>Describe your use case"
7
  text1 = "<h1 style='text-align: center; color: midnightblue; font-size: 25px;'>First option"
8
  text2 = "<h1 style='text-align: center; color: midnightblue; font-size: 25px;'>Second option"
@@ -43,8 +46,93 @@ def update_plot(tco1, tco2, dropdown, dropdown2, labour_cost1, labour_cost2):
43
  }
44
  )
45
  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"])
46
-
47
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  Models: list[models.BaseTCOModel] = [models.OpenAIModel, models.CohereModel, models.OpenSourceLlama2Model]
49
  model_names = [Model().get_name() for Model in Models]
50
  gr.Markdown(value=text)
@@ -55,13 +143,13 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
55
  # with gr.Row():
56
  # gr.Markdown(value=text0)
57
  with gr.Row():
58
- use_case = gr.Dropdown(["Summarize", "Question-Answering", "Classification"], value="Question-Answering", label="Describe your use case")
59
- with gr.Accordion("Open to customize the number of input and output tokens for your use case", open=False):
60
  with gr.Row():
61
- input_tokens = gr.Slider(minimum=1, maximum=1000, value=300, step=1, label="Number of input token", info="We put a value that we find best suit your use case choice but feel free to adjust", interactive=True)
62
- output_tokens = gr.Slider(minimum=1, maximum=1000, value=300, step=1, label="Number of output token", info="We put a value that we find best suit your use case choice but feel free to adjust", interactive=True)
63
  with gr.Row(visible=False):
64
- num_users = gr.Number(value="1000", interactive = True, label="Number of users for your service")
65
 
66
  use_case.change(on_use_case_change, inputs=use_case, outputs=[input_tokens, output_tokens])
67
 
@@ -69,22 +157,22 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
69
  with gr.Column():
70
  #gr.Markdown(value=text1)
71
  page1 = models.ModelPage(Models)
72
- dropdown = gr.Dropdown(model_names, interactive=True, label="AI service option 1")
73
- with gr.Accordion("Open for more information on the computation parameters for your first AI service option", open=False):
74
  page1.render()
75
 
76
  with gr.Column():
77
  #gr.Markdown(value=text2)
78
  page2 = models.ModelPage(Models)
79
- dropdown2 = gr.Dropdown(model_names, interactive=True, label="AI service option 2")
80
- with gr.Accordion("Open for more information on the computation parameters for your second AI service option", open=False):
81
  page2.render()
82
 
83
  dropdown.change(page1.make_model_visible, inputs=[dropdown, use_case], outputs=page1.get_all_components())
84
  dropdown2.change(page2.make_model_visible, inputs=[dropdown2, use_case], outputs=page2.get_all_components())
85
 
86
  #gr.Markdown(value=text3)
87
- compute_tco_btn = gr.Button("Compute cost/request and TCOs", size="lg")
88
  tco1 = gr.State()
89
  tco2 = gr.State()
90
  labour_cost1 = gr.State()
@@ -92,20 +180,20 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
92
 
93
  with gr.Row():
94
  with gr.Column():
95
- tco_output = gr.Text("Output 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 a Total Cost of Model Serving")
96
  latency_info = gr.Markdown()
97
- with gr.Accordion("Open to see the formula", open=False):
98
  tco_formula = gr.Markdown()
99
 
100
  with gr.Column():
101
- tco_output2 = gr.Text("Output 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 a Total Cost of Model Serving")
102
  latency_info2 = gr.Markdown()
103
- with gr.Accordion("Open to see the formula", open=False):
104
  tco_formula2 = gr.Markdown()
105
 
106
  with gr.Row():
107
  with gr.Column(scale=1):
108
- ratio = gr.Text("Ratio: ", label="Ratio of cost/request for both solutions")
109
  with gr.Column(scale=3):
110
  plot = gr.LinePlot()
111
 
 
1
  import gradio as gr
2
  import models
3
  import pandas as pd
4
+ from gradio.themes.base import Base
5
+ from gradio.themes.utils import colors, fonts, sizes
6
+ from typing import Iterable
7
 
8
+ text = "<h1 style='text-align: center; color: #f0ba2d; font-size: 40px;'>TCO Comparison Calculator"
9
  text0 = "<h1 style='text-align: center; color: midnightblue; font-size: 30px;'>Describe your use case"
10
  text1 = "<h1 style='text-align: center; color: midnightblue; font-size: 25px;'>First option"
11
  text2 = "<h1 style='text-align: center; color: midnightblue; font-size: 25px;'>Second option"
 
46
  }
47
  )
48
  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"])
49
+
50
+ class Style(Base):
51
+ def __init__(
52
+ self,
53
+ *,
54
+ primary_hue: colors.Color | str = colors.neutral,
55
+ secondary_hue: colors.Color | str = colors.neutral,
56
+ neutral_hue: colors.Color | str = colors.neutral,
57
+ spacing_size: sizes.Size | str = sizes.spacing_md,
58
+ radius_size: sizes.Size | str = sizes.radius_md,
59
+ text_size: sizes.Size | str = sizes.text_md,
60
+ font: fonts.Font
61
+ | str
62
+ | Iterable[fonts.Font | str] = (fonts.GoogleFont("Sora")),
63
+ font_mono: fonts.Font
64
+ | str
65
+ | Iterable[fonts.Font | str] = (fonts.GoogleFont("Sora")),
66
+ ):
67
+ super().__init__(
68
+ primary_hue=primary_hue,
69
+ secondary_hue=secondary_hue,
70
+ neutral_hue=neutral_hue,
71
+ spacing_size=spacing_size,
72
+ radius_size=radius_size,
73
+ text_size=text_size,
74
+ font=font,
75
+ font_mono=font_mono,
76
+ )
77
+ super().set(
78
+ background_fill_primary="#050f19", #The color of the background of blocks
79
+ background_fill_secondary="#050f19",
80
+ block_background_fill="#050f19", #The color of the background of blocks
81
+ block_background_fill_dark="#050f19",
82
+
83
+ border_color_primary="#050f19", #The border of a block such as dropdown
84
+ border_color_primary_dark="#050f19",
85
+
86
+ link_text_color="#f0ba2d", #The color for links
87
+ link_text_color_dark="#f0ba2d",
88
+
89
+ block_info_text_color="ffffff",
90
+ block_info_text_color_dark="ffffff",
91
+
92
+ block_border_color="#050f19", #The border color around an item (e.g. Accordion)
93
+ block_border_color_dark="#050f19",
94
+ block_shadow="*shadow_drop_lg",
95
+ #form_gap_width="*spacing_md", #The border gap between form elements, (e.g. consecutive textboxes)
96
+
97
+ input_background_fill="#081527", #The background of an input field
98
+ input_background_fill_dark="#081527",
99
+ input_border_color="#050f19",
100
+ input_border_color_dark="#050f19",
101
+ input_border_width="2px",
102
+
103
+ block_label_background_fill="#f0ba2d",
104
+ block_label_background_fill_dark="#f0ba2d",
105
+ block_label_border_color=None,
106
+ block_label_border_color_dark=None,
107
+ block_label_text_color="#050f19",
108
+ block_label_text_color_dark="#050f19",
109
+
110
+ button_primary_background_fill="#ffffff",
111
+ button_primary_border_color="#ffffff",
112
+ button_primary_text_color="#050f19",
113
+ button_shadow="*shadow_drop_lg",
114
+
115
+ block_title_background_fill="#f0ba2d", #The background of the title of a form element (e.g. textbox).
116
+ block_title_background_fill_dark="#f0ba2d", #The corner radius of the title of a form element (e.g. textbox).
117
+ block_title_radius="*radius_sm",
118
+ block_title_text_color="#050f19", #The text color of the title of a form element (e.g. textbox).
119
+ block_title_text_color_dark="#050f19",
120
+ block_title_text_size="*text_lg",
121
+
122
+ body_background_fill="#050f19",
123
+ body_background_fill_dark="#050f19",
124
+ body_text_color="#ffffff", #The default text color.
125
+ body_text_color_dark="#ffffff",
126
+ body_text_color_subdued="#ffffff",
127
+ body_text_color_subdued_dark="#ffffff",
128
+
129
+ slider_color="*secondary_300",
130
+ slider_color_dark="*secondary_600",
131
+ )
132
+
133
+ style = Style()
134
+
135
+ with gr.Blocks(theme=style) as demo:
136
  Models: list[models.BaseTCOModel] = [models.OpenAIModel, models.CohereModel, models.OpenSourceLlama2Model]
137
  model_names = [Model().get_name() for Model in Models]
138
  gr.Markdown(value=text)
 
143
  # with gr.Row():
144
  # gr.Markdown(value=text0)
145
  with gr.Row():
146
+ use_case = gr.Dropdown(["Summarize", "Question-Answering", "Classification"], value="Question-Answering", label=" Describe your use case ")
147
+ with gr.Accordion("Click here to customize the number of input and output tokens for your use case", open=False):
148
  with gr.Row():
149
+ input_tokens = gr.Slider(minimum=1, maximum=1000, value=300, step=1, label=" Number of input token ", info="We put a value that we find best suit your use case choice but feel free to adjust", interactive=True)
150
+ output_tokens = gr.Slider(minimum=1, maximum=1000, value=300, step=1, label=" Number of output token ", info="We put a value that we find best suit your use case choice but feel free to adjust", interactive=True)
151
  with gr.Row(visible=False):
152
+ num_users = gr.Number(value="1000", interactive = True, label=" Number of users for your service ")
153
 
154
  use_case.change(on_use_case_change, inputs=use_case, outputs=[input_tokens, output_tokens])
155
 
 
157
  with gr.Column():
158
  #gr.Markdown(value=text1)
159
  page1 = models.ModelPage(Models)
160
+ dropdown = gr.Dropdown(model_names, interactive=True, label=" First AI service option ")
161
+ with gr.Accordion("Click here for more information on the computation parameters for your first AI service option", open=False):
162
  page1.render()
163
 
164
  with gr.Column():
165
  #gr.Markdown(value=text2)
166
  page2 = models.ModelPage(Models)
167
+ dropdown2 = gr.Dropdown(model_names, interactive=True, label=" Second AI service option ")
168
+ with gr.Accordion("Click here for more information on the computation parameters for your second AI service option", open=False):
169
  page2.render()
170
 
171
  dropdown.change(page1.make_model_visible, inputs=[dropdown, use_case], outputs=page1.get_all_components())
172
  dropdown2.change(page2.make_model_visible, inputs=[dropdown2, use_case], outputs=page2.get_all_components())
173
 
174
  #gr.Markdown(value=text3)
175
+ compute_tco_btn = gr.Button("Compute cost/request and TCOs", size="lg", variant="primary", scale=1)
176
  tco1 = gr.State()
177
  tco2 = gr.State()
178
  labour_cost1 = gr.State()
 
180
 
181
  with gr.Row():
182
  with gr.Column():
183
+ tco_output = gr.Text("Output 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 a Total Cost of Model Serving")
184
  latency_info = gr.Markdown()
185
+ with gr.Accordion("Click here to see the formula", open=False):
186
  tco_formula = gr.Markdown()
187
 
188
  with gr.Column():
189
+ tco_output2 = gr.Text("Output 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 a Total Cost of Model Serving")
190
  latency_info2 = gr.Markdown()
191
+ with gr.Accordion("Click here to see the formula", open=False):
192
  tco_formula2 = gr.Markdown()
193
 
194
  with gr.Row():
195
  with gr.Column(scale=1):
196
+ ratio = gr.Text("Ratio: ", label=" Ratio of cost/request for both solutions ")
197
  with gr.Column(scale=3):
198
  plot = gr.LinePlot()
199