@@ -11,7 +11,7 @@ import {
11
11
InputLabel ,
12
12
FormControl ,
13
13
IconButton ,
14
- Grid ,
14
+ Grid2 as Grid ,
15
15
Accordion ,
16
16
AccordionSummary ,
17
17
AccordionDetails ,
@@ -73,7 +73,7 @@ function App() {
73
73
Azure OpenAI Image Token Calculator
74
74
</ Typography >
75
75
< Grid container spacing = { 4 } >
76
- < Grid item xs = { 12 } md = { 8 } >
76
+ < Grid size = { { xs : 12 , md : 8 } } >
77
77
< form onSubmit = { handleSubmit } >
78
78
< FormControl fullWidth margin = "normal" required >
79
79
< InputLabel id = "model-label" > Model</ InputLabel >
@@ -96,7 +96,7 @@ function App() {
96
96
97
97
{ images . map ( ( image , index ) => (
98
98
< Grid container spacing = { 1 } alignItems = "center" key = { index } >
99
- < Grid item sm = { 4 } >
99
+ < Grid size = { { sm : 4 } } >
100
100
< TextField
101
101
label = "Image Height (px)"
102
102
type = "number"
@@ -109,7 +109,7 @@ function App() {
109
109
fullWidth
110
110
/>
111
111
</ Grid >
112
- < Grid item sm = { 4 } >
112
+ < Grid size = { { sm : 4 } } >
113
113
< TextField
114
114
label = "Image Width (px)"
115
115
type = "number"
@@ -122,7 +122,7 @@ function App() {
122
122
fullWidth
123
123
/>
124
124
</ Grid >
125
- < Grid item sm = { 2 } >
125
+ < Grid size = { { sm : 2 } } >
126
126
< TextField
127
127
label = "Count"
128
128
type = "number"
@@ -135,15 +135,15 @@ function App() {
135
135
fullWidth
136
136
/>
137
137
</ Grid >
138
- < Grid item sm = { 1 } >
138
+ < Grid size = { { sm : 1 } } >
139
139
< IconButton
140
140
onClick = { ( ) => cloneImage ( index ) }
141
141
color = "primary"
142
142
>
143
143
< FileCopy />
144
144
</ IconButton >
145
145
</ Grid >
146
- < Grid item sm = { 1 } >
146
+ < Grid size = { { sm : 1 } } >
147
147
< IconButton
148
148
onClick = { ( ) => removeImage ( index ) }
149
149
color = "secondary"
@@ -175,19 +175,115 @@ function App() {
175
175
</ form >
176
176
177
177
< Box mt = { 2 } >
178
- { totalTokens !== null && (
179
- < Typography gutterBottom >
180
- Token Estimate: { totalTokens }
181
- </ Typography >
178
+ { images . map ( ( image , index ) =>
179
+ image . resizedHeight ? (
180
+ < Box key = { index } sx = { { display : "flex" } } mb = { 2 } >
181
+ < Box sx = { { flex : "1 0 auto" } } >
182
+ < Typography variant = "h6" gutterBottom >
183
+ Image { index + 1 }
184
+ </ Typography >
185
+ < Box
186
+ sx = { {
187
+ display : "flex" ,
188
+ alignItems : "center" ,
189
+ } }
190
+ >
191
+ < Box sx = { { flexGrow : 1 } } >
192
+ < Typography variant = "body2" color = "textSecondary" >
193
+ Resized Size
194
+ </ Typography >
195
+ < Typography variant = "body1" gutterBottom >
196
+ { image . resizedHeight } x { image . resizedWidth }
197
+ </ Typography >
198
+ </ Box >
199
+ < Box sx = { { flexGrow : 1 } } >
200
+ < Typography variant = "body2" color = "textSecondary" >
201
+ Tiles (per image)
202
+ </ Typography >
203
+ < Typography variant = "body1" gutterBottom >
204
+ { image . tilesHigh } x { image . tilesWide }
205
+ </ Typography >
206
+ </ Box >
207
+ < Box sx = { { flexGrow : 1 } } >
208
+ < Typography variant = "body2" color = "textSecondary" >
209
+ Total tiles
210
+ </ Typography >
211
+ < Typography variant = "body1" gutterBottom >
212
+ { image . totalTiles }
213
+ </ Typography >
214
+ </ Box >
215
+ </ Box >
216
+ </ Box >
217
+ </ Box >
218
+ ) : null
182
219
) }
183
- { totalCost !== null && (
184
- < Typography gutterBottom >
185
- Cost Estimate: ${ totalCost }
186
- </ Typography >
220
+
221
+ { totalTokens !== null && (
222
+ < Box sx = { { display : "flex" } } mb = { 2 } >
223
+ < Box sx = { { flex : "1 0 auto" } } >
224
+ < Typography variant = "h6" gutterBottom >
225
+ Result
226
+ </ Typography >
227
+ < Box
228
+ sx = { {
229
+ display : "flex" ,
230
+ alignItems : "center" ,
231
+ } }
232
+ >
233
+ { model && (
234
+ < Box sx = { { flexGrow : 1 } } >
235
+ < Typography variant = "body2" color = "textSecondary" >
236
+ Base tokens
237
+ </ Typography >
238
+ < Typography variant = "body1" gutterBottom >
239
+ { model . baseTokens }
240
+ </ Typography >
241
+ </ Box >
242
+ ) }
243
+
244
+ { model && (
245
+ < Box sx = { { flexGrow : 1 } } >
246
+ < Typography variant = "body2" color = "textSecondary" >
247
+ Tile tokens
248
+ </ Typography >
249
+ < Typography variant = "body1" gutterBottom >
250
+ { model . tokensPerTile } x{ " " }
251
+ { images
252
+ . map ( ( image ) => image . totalTiles ?? 0 )
253
+ . reduce ( ( acc , val ) => acc + val , 0 ) } { " " }
254
+ = { totalTokens - model . baseTokens }
255
+ </ Typography >
256
+ </ Box >
257
+ ) }
258
+
259
+ { totalTokens !== null && (
260
+ < Box sx = { { flexGrow : 1 } } >
261
+ < Typography variant = "body2" color = "textSecondary" >
262
+ Total tokens
263
+ </ Typography >
264
+ < Typography variant = "body1" gutterBottom >
265
+ { totalTokens }
266
+ </ Typography >
267
+ </ Box >
268
+ ) }
269
+
270
+ { totalCost !== null && (
271
+ < Box sx = { { flexGrow : 1 } } >
272
+ < Typography variant = "body2" color = "textSecondary" >
273
+ Total cost
274
+ </ Typography >
275
+ < Typography variant = "body1" gutterBottom >
276
+ ${ totalCost }
277
+ </ Typography >
278
+ </ Box >
279
+ ) }
280
+ </ Box >
281
+ </ Box >
282
+ </ Box >
187
283
) }
188
284
</ Box >
189
285
</ Grid >
190
- < Grid item xs = { 12 } md = { 4 } >
286
+ < Grid size = { { xs : 12 , md : 4 } } >
191
287
< Accordion expanded >
192
288
< AccordionSummary
193
289
aria-controls = "calculation-explanation-content"
@@ -197,35 +293,35 @@ function App() {
197
293
</ AccordionSummary >
198
294
{ model ? (
199
295
< AccordionDetails >
200
- < Typography paragraph >
201
- The calculation involves several steps:
296
+ < Typography >
297
+ < p > The calculation involves several steps:</ p >
202
298
</ Typography >
203
- < Typography paragraph >
299
+ < Typography >
204
300
1. < b > Resizing Images</ b > : Ensure each image is resized to
205
301
fit within the maximum dimension { model . maxImageDimension }
206
302
px, and has at least { model . imageMinSizeLength } px on the
207
303
shortest side, while maintaining its aspect ratio.
208
304
</ Typography >
209
- < Typography paragraph >
305
+ < Typography >
210
306
2. < b > Calculating Tiles</ b > : The resized image is divided
211
307
into tiles based on the model's tile size of{ " " }
212
308
{ model . tileSizeLength } px by { model . tileSizeLength } px.
213
309
</ Typography >
214
- < Typography paragraph >
310
+ < Typography >
215
311
3. < b > Token Calculation</ b > : The total number of tokens is
216
312
calculated by multiplying the number of tiles by the tokens
217
313
per tile ({ model . tokensPerTile } ) and adding an additional
218
- buffer of { model . additionalBuffer } tokens.
314
+ buffer of { model . baseTokens } tokens.
219
315
</ Typography >
220
- < Typography paragraph >
316
+ < Typography >
221
317
4. < b > Cost Calculation</ b > : The total cost is calculated
222
318
based on the total number of tokens and the cost per
223
319
thousand tokens (${ model . costPerThousandTokens } ).
224
320
</ Typography >
225
321
</ AccordionDetails >
226
322
) : (
227
323
< AccordionDetails >
228
- < Typography paragraph >
324
+ < Typography >
229
325
Please select a model to see the calculation explanation.
230
326
</ Typography >
231
327
</ AccordionDetails >
0 commit comments