File size: 29,515 Bytes
c9117ba
 
 
 
 
66ac827
c9117ba
 
 
 
3efb4a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c9117ba
3efb4a6
c9117ba
3efb4a6
c9117ba
3efb4a6
c9117ba
 
 
3efb4a6
 
 
 
 
 
 
 
 
c9117ba
3efb4a6
c9117ba
3efb4a6
c9117ba
3efb4a6
c9117ba
 
 
3efb4a6
c9117ba
 
3efb4a6
c9117ba
 
 
 
 
 
3efb4a6
 
 
 
 
 
 
 
 
c9117ba
3efb4a6
c9117ba
 
3efb4a6
c9117ba
3efb4a6
 
c9117ba
 
3efb4a6
c9117ba
 
 
 
 
 
 
 
 
 
3efb4a6
c9117ba
 
 
 
 
 
3efb4a6
c9117ba
 
 
3efb4a6
 
 
c9117ba
 
 
 
 
 
3efb4a6
c9117ba
 
 
3efb4a6
c9117ba
 
3efb4a6
c9117ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66ac827
c9117ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66ac827
c9117ba
66ac827
c9117ba
 
 
 
 
 
 
 
 
 
 
 
 
 
66ac827
c9117ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66ac827
c9117ba
66ac827
c9117ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3efb4a6
 
 
c9117ba
 
 
 
 
3efb4a6
c9117ba
 
 
 
 
 
 
 
66ac827
c9117ba
 
 
 
66ac827
c9117ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66ac827
c9117ba
66ac827
c9117ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66ac827
c9117ba
66ac827
c9117ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66ac827
c9117ba
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
import gradio as gr
from src.services.util import (
    REPORT_STATUS_OPTIONS, CONFIDENTIALITY_LEVELS, DATA_USAGE_OPTIONS, DATA_FORMAT,
    DATA_TYPES, DATA_SOURCE,
    ACCURACY_LEVELS, INFRA_TYPES,
    POWER_SUPPLIER_TYPES, POWER_SOURCES, QUALITY_LEVELS
)


def create_dynamic_section(section_name, fields_config, initial_count=1, layout="row"):
    """
    Creates a dynamic section in a Gradio interface where users can add or remove rows of input fields.

    Args:
        section_name (str): The name of the section (e.g., "Algorithms", "Components").
        fields_config (list): A list of dictionaries defining the configuration for each field in the section.
                              Each dictionary should include:
                              - "type": The Gradio component type (e.g., gr.Textbox, gr.Number).
                              - "label": The label for the field.
                              - "info": Additional information or tooltip for the field.
                              - "value" (optional): The default value for the field.
                              - "kwargs" (optional): Additional keyword arguments for the component.
                              - "elem_classes" (optional): CSS classes for styling the field.
        initial_count (int): The initial number of rows to render in the section.
        layout (str): The layout of the fields in each row ("row" or "column").

    Returns:
        tuple: A tuple containing:
            - count_state: A Gradio state object tracking the number of rows.
            - field_states: A list of Gradio state objects, one for each field, to store the values of the fields.
            - add_btn: The "Add" button component for adding new rows.
    """
    # State management
    # Tracks the number of rows in the section.
    count_state = gr.State(value=initial_count+1)
    # Stores the values for each field across all rows.
    field_states = [gr.State([]) for _ in fields_config]
    # A list to store all dynamically generated components.
    all_components = []

    def update_fields(*states_and_values):
        """
        Updates the state of the fields when a value changes.

        Args:
            *states_and_values: A combination of the current states and the new values for the fields.

        Returns:
            tuple: Updated states for all fields.
        """
        # Split states and current values
        # Extract the current states for each field.
        states = list(states_and_values[:len(fields_config)])
        # Extract the new values for the fields.
        current_values = states_and_values[len(fields_config):-1]
        index = states_and_values[-1]  # The index of the row being updated.

        # Update each field's state
        for field_idx, (state, value) in enumerate(zip(states, current_values)):
            # Ensure the state list is long enough to accommodate the current index.
            while len(state) <= index:
                state.append("")
            # Update the value at the specified index.
            state[index] = value if value is not None else ""

        return tuple(states)

    @gr.render(inputs=count_state)
    def render_dynamic_section(count):
        """
        Renders the dynamic section with the current number of rows and their states.

        Args:
            count (int): The number of rows to render.

        Returns:
            list: A list of dynamically generated components for the section.
        """
        nonlocal all_components
        all_components = []  # Reset the list of components for re-rendering.

        for i in range(count):
            # Create a row or column layout for the current row of fields.
            with (gr.Row() if layout == "row" else gr.Column()):
                row_components = []  # Components for the current row.
                field_refs = []  # References to the current row's components.

                for field_idx, config in enumerate(fields_config):
                    # Create a component for the field using its configuration.
                    component = config["type"](
                        label=f"{config['label']} ({section_name}{i + 1})",
                        info=config.get("info", ""),
                        value=config.get("value", ""),
                        **config.get("kwargs", {}),
                        elem_classes=config.get("elem_classes", "")
                    )
                    row_components.append(component)
                    field_refs.append(component)

                    # Create a change event to update the field states when the value changes.
                    component.change(
                        fn=update_fields,
                        inputs=[*field_states, *field_refs, gr.State(i)],
                        outputs=field_states
                    )

                # Add a "Remove" button to delete the current row.
                remove_btn = gr.Button("❌", variant="secondary")
                remove_btn.click(
                    lambda x, idx=i, fs=field_states: (
                        max(0, x - 1),  # Decrease the count of rows.
                        # Remove the row's values.
                        *[fs[i].value[:idx] + fs[i].value[idx + 1:] for i in range(len(fs))]
                    ),
                    inputs=count_state,
                    outputs=[count_state, *field_states]
                )
                row_components.append(remove_btn)

                # Add the row's components to the list of all components.
                all_components.extend(row_components)
        return all_components

    # Initialize the section with the initial count of rows.
    render_dynamic_section(count=initial_count)

    # Create an "Add" button to add new rows to the section.
    add_btn = gr.Button(f"Add {section_name}")
    add_btn.click(lambda x: x + 1, count_state, count_state)

    return (count_state, *field_states, add_btn)


def create_header_tab():
    """Create the header tab components."""
    with gr.Tab("Header"):
        licensing = gr.Textbox(
            label="Licensing", info="(the type of licensing applicable for the sharing of the report)")
        formatVersion = gr.Textbox(
            label="Format Version", info="(the version of the specification of this set of schemas defining the report's fields)")
        formatVersionSpecificationUri = gr.Textbox(
            label="Format Version Specification URI", info="(the URI of the present specification of this set of schemas)")
        reportId = gr.Textbox(
            label="Report ID", info="(the unique identifier of this report, preferably as a uuid4 string)")
        reportDatetime = gr.Textbox(
            label="Report Datetime", info="Required field<br>(the publishing date of this report in format YYYY-MM-DD HH:MM:SS)", elem_classes="mandatory_field")
        reportStatus = gr.Dropdown(value=None,
                                   label="Report Status",
                                   choices=REPORT_STATUS_OPTIONS,
                                   info="(the status of this report)"
                                   )

        with gr.Accordion("Publisher"):
            publisher_name = gr.Textbox(
                label="Name", info="(name of the organization)")
            publisher_division = gr.Textbox(
                label="Division", info="(name of the publishing department within the organization)")
            publisher_projectName = gr.Textbox(
                label="Project Name", info="(name of the publishing project within the organization)")
            publisher_confidentialityLevel = gr.Dropdown(value=None,
                                                         label="Confidentiality Level",
                                                         choices=CONFIDENTIALITY_LEVELS,
                                                         info="Required field<br>(the confidentiality of the report)",
                                                         elem_classes="mandatory_field"
                                                         )
            publisher_publicKey = gr.Textbox(
                label="Public Key", info="(the cryptographic public key to check the identity of the publishing organization)")

        return [
            licensing, formatVersion, formatVersionSpecificationUri, reportId,
            reportDatetime, reportStatus, publisher_name, publisher_division,
            publisher_projectName, publisher_confidentialityLevel, publisher_publicKey
        ]


def create_task_tab():
    """Create the task tab components."""
    with gr.Tab("Task", elem_id="mandatory_part"):
        taskStage = gr.Textbox(
            label="Task Stage", info="Required field<br>(stage of the task, example: datacreation, preprocessing, training, finetuning, inference, retraining..., add a + between stages if several but we do recommand to measure each step independantly)", elem_classes="mandatory_field")
        taskFamily = gr.Textbox(
            label="Task Family", info="Required field<br>(the family of task you are running, e.g. text classification, image generation, speech recognition, robotics navigation...)", elem_classes="mandatory_field")
        nbRequest = gr.Number(
            label="Number of Requests", info="(if inference stage, the number of requests the measure corresponds to, 0 or empty if you're not measuring the inference stage)",
            value=lambda: None, minimum=0)

        with gr.Accordion("Algorithms", elem_id="mandatory_part"):
            _, trainingType, algorithmType, algorithmName, algorithmUri, foundationModelName, foundationModelUri, parametersNumber, framework,  frameworkVersion, classPath, layersNumber, epochsNumber, optimizer, quantization, add_algorithm_btn = create_dynamic_section(
                section_name="algorithm",
                fields_config=[
                    {
                        "type": gr.Textbox,
                        "label": "Type of training",
                        "info": "(if applicable, type of training (if the stage corresponds to a training) : supervisedLearning, unsupervisedLearning, semiSupervisedLearning, reinforcementLearning, transferLearning ...)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Type of algorithm",
                        "info": "(the type of algorithm used, example : embeddings creation, rag, nlp, neural network, llm...)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Algorithm Name",
                        "info": "(the case-sensitive common name of the algorithm, example: randomForest, naive bayes, cnn, rnn, transformers, if you are directly using a foundation model, let it empty and fill the field foundationModelName...)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Algorithm Uri",
                        "info": "(the URI of the model, if publicly available)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Foundation Model Name",
                        "info": "(if a foundation model is used, its case-sensitive common name, example: llama3.1-8b, gpt4-o...)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Foundation Model Uri",
                        "info": "(the URI of the foundation model, if publicly available)",
                    },
                    {
                        "type": gr.Number,
                        "label": "Number of parameters",
                        "info": "(if applicable, number of billions of total parameters of your model, e.g. 8 for llama3.1-8b)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Framework",
                        "info": "(the common name of the software framework implementing the algorithm, if any)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "frameworkVersion",
                        "info": "(the version of the software framework implementing the algorithm, if any)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "classPath",
                        "info": "(the full class path of the algorithm within the framework, with elements separated by dots)",
                    },
                    {
                        "type": gr.Number,
                        "label": "Number of layers in the network",
                        "info": "(if deep learning, precise the number of layers in your network)",
                    },
                    {
                        "type": gr.Number,
                        "label": "Number of epochs",
                        "info": "(if training, the number of complete passes through the training dataset)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "optimizer",
                        "info": "(the algorithm used to optimize the models weights, e.g. gridSearch, lora, adam)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "quantization",
                        "info": "(the type of quantization used : fp32, fp16, b16, int8 ...)",
                    }
                ],
                initial_count=0,
                layout="column"
            )

        with gr.Accordion("Dataset", elem_id="mandatory_part"):
            _, dataUsage, dataType, dataFormat, dataSize, dataQuantity, shape, source, sourceUri,  owner, add_dataset_btn = create_dynamic_section(
                section_name="dataset",
                fields_config=[
                    {
                        "type": gr.Dropdown,
                        "label": "Data Usage",
                        "info": "Required field<br>(the use of the dataset: is it used as model input or output ?)",
                        "value": None,
                        "kwargs": {"choices": DATA_USAGE_OPTIONS},
                        "elem_classes": "mandatory_field",
                    },
                    {
                        "type": gr.Dropdown,
                        "label": "Data Type",
                        "info": "Required field<br>(the nature of the data used)",
                        "value": None,
                        "kwargs": {"choices": DATA_TYPES},
                        "elem_classes": "mandatory_field",
                    },
                    {
                        "type": gr.Dropdown,
                        "label": "Data Format",
                        "info": "(if the data is passed in the form of a file, what format is the data in?)",
                        "value": None,
                        "kwargs": {"choices": DATA_FORMAT}
                    },
                    {
                        "type": gr.Number,
                        "label": "Data Size",
                        "info": "(the size of the dataset (in Go), if small quantity just fill the field quantity)",
                    },
                    {
                        "type": gr.Number,
                        "label": "Data Quantity",
                        "info": "(the number of data in the dataset, e.g. 3 (images, audio or tokens))",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Data shape",
                        "info": "(the shape of your dataset, can be found with X.shape with dataframes, e.g. (12, 1000) for a 2D table with 12 columns and 1000 rows)",
                    },
                    {
                        "type": gr.Dropdown,
                        "label": "Data source",
                        "info": "(the kind of source of the dataset)",
                        "value": None,
                        "kwargs": {"choices": DATA_SOURCE}
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Source Uri",
                        "info": "(the URI of the dataset if available)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Owner",
                        "info": "(the owner of the dataset if available)",
                    }
                ],
                initial_count=0,
                layout="column"
            )

        with gr.Row():
            measuredAccuracy = gr.Number(value=lambda: None,
                                         label="Measured Accuracy", info="(the measured accuracy of your model (between 0 and 1))")
            estimatedAccuracy = gr.Dropdown(value=None,
                                            label="Estimated Accuracy",
                                            choices=ACCURACY_LEVELS,
                                            info="(estimated accuracy assessment)"
                                            )
        with gr.Row():
            taskDescription = gr.Textbox(
                label="Task description", info="(free field, to be fillied in if you have more details to share about your task)")

    return [
        taskFamily, taskStage, nbRequest,
        trainingType, algorithmType, algorithmName, algorithmUri, foundationModelName, foundationModelUri, parametersNumber, framework,  frameworkVersion, classPath, layersNumber, epochsNumber, optimizer, quantization,
        dataUsage, dataType, dataFormat, dataSize, dataQuantity, shape, source, sourceUri,  owner,
        measuredAccuracy, estimatedAccuracy, taskDescription
    ]


def create_measures_tab():
    """Create the measures tab components."""
    with gr.Tab("Measures", elem_id="mandatory_part"):
        with gr.Accordion("Measures"):
            _, measurementMethod, manufacturer, version, cpuTrackingMode, gpuTrackingMode, averageUtilizationCpu, averageUtilizationGpu, powerCalibrationMeasurement,  durationCalibrationMeasurement, powerConsumption, measurementDuration, measurementDateTime, add_measurement_btn = create_dynamic_section(
                section_name="measure",
                fields_config=[
                    {
                        "type": gr.Textbox,
                        "label": "Method of measurement",
                        "info": "Required field<br>(the method used to perform the energy measure, example: codecarbon, carbonai, flops-compute, wattmeter...)",
                        "elem_classes": "mandatory_field",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Manufacturer",
                        "info": "(the builder of the measuring tool, if the measurement method is wattmeter)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Version of the measurement tool",
                        "info": "(the version of the measuring tool, if any)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "CPU tracking mode",
                        "info": "(the method used to track the consumption of the CPU, example: constant, rapl...)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "GPU tracking mode",
                        "info": "(the method used to track the consumption of the GPU, example: constant, nvml...)",
                    },
                    {
                        "type": gr.Number,
                        "label": "Average CPU Utilization",
                        "info": "(the average percentage of use of the CPU during the task, for example: 0.5 if your CPU load was 50% on average)",
                        "minimum": 0,
                        "maximum": 1
                    },
                    {
                        "type": gr.Number,
                        "label": "Average GPU Utilization",
                        "info": "(the average percentage of use of the GPU during the task, for example: 0.8 if your GPU load was 80% on average)",
                        "minimum": 0,
                        "maximum": 1
                    },
                    {
                        "type": gr.Number,
                        "label": "Power calibration measurement",
                        "info": "(the power consumed (in kWh) during the calibration measure if any (to isolate the initial consumption of the hardware))",
                    },
                    {
                        "type": gr.Number,
                        "label": "Duration calibration measurement",
                        "info": "(the duration of the calibration if any (in seconds))",
                    },
                    {
                        "type": gr.Number,
                        "label": "Power consumption",
                        "info": "Required field<br>(the power consumption measure of the computing task (in kWh))",
                        "elem_classes": "mandatory_field",
                    },
                    {
                        "type": gr.Number,
                        "label": "Measurement Duration",
                        "info": "(the duration of the measurement (in seconds))",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Measurement date time",
                        "info": "(the date when the measurement began, in format YYYY-MM-DD HH:MM:SS)",
                    }
                ],
                initial_count=0,
                layout="column"
            )

    return [
        measurementMethod, manufacturer, version, cpuTrackingMode, gpuTrackingMode,
        averageUtilizationCpu, averageUtilizationGpu, powerCalibrationMeasurement,
        durationCalibrationMeasurement, powerConsumption,
        measurementDuration, measurementDateTime
    ]


def create_system_tab():
    """Create the system tab components."""
    with gr.Tab("System"):
        os = gr.Textbox(
            label="OS", info="Required field<br>(name of the operating system)", elem_classes="mandatory_field")
        distribution = gr.Textbox(
            label="Distribution", info="(distribution of the operating system)")
        distributionVersion = gr.Textbox(
            label="Distribution Version", info="(distribution version)")

        return [os, distribution, distributionVersion]


def create_software_tab():
    """Create the software tab components."""
    with gr.Tab("Software"):
        language = gr.Textbox(
            label="Language", info="Required field<br>(name of the programming language used, example : c, java, julia, python...)", elem_classes="mandatory_field")
        version_software = gr.Textbox(
            label="Version", info="(version of the programming language used)")

        return [language, version_software]


def create_infrastructure_tab():
    """Create the infrastructure tab components."""
    with gr.Tab("Infrastructure", elem_id="mandatory_part"):
        infraType = gr.Dropdown(value=None,
                                label="Infrastructure Type",
                                choices=INFRA_TYPES,
                                info="Required field<br>(the type of infrastructure used)",
                                elem_classes="mandatory_field"
                                )
        cloudProvider = gr.Textbox(
            label="Cloud Provider", info="(If you are on the cloud, the name of your cloud provider, for example : aws, azure, google, ovh...)")
        cloudInstance = gr.Textbox(
            label="Cloud Instance", info="(If you are on a cloud vm, the name of your cloud instance, for example : a1.large, dasv4-type2...)")
        cloudService = gr.Textbox(
            label="Cloud Service", info="(If you are using an AI cloud service, the name of your cloud service, for example : openAI service...)")
        with gr.Accordion("Components", elem_id="mandatory_part"):
            _, componentName, componentType, nbComponent, memorySize, manufacturer_infra, family, series, share, add_component_btn = create_dynamic_section(
                section_name="component",
                fields_config=[

                    {
                        "type": gr.Textbox,
                        "label": "Component Name",
                        "info": "(the name of this subsystem part of your infrastructure, example returned by codecarbon: 1 x NVIDIA GeForce GTX 1080 Ti)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Component Type",
                        "info": "Required field<br>(the type of this subsystem part of your infrastructure, example: cpu, gpu, ram, hdd, sdd...)",
                        "elem_classes": "mandatory_field",
                    },
                    {
                        "type": gr.Number,
                        "label": "Number of Components",
                        "info": "Required field<br>(the number of items of this component in your infrastructure, if you have 1 RAM of 32Go, fill 1 here and 32 inside memorySize)",
                        "elem_classes": "mandatory_field",
                    },
                    {
                        "type": gr.Number,
                        "label": "Memory Size",
                        "info": "(the size of the memory of the component in Gbytes, useful to detail the memory associated to ONE of your gpus for example (if we want the total memory, we will multiply the memorySize by nbComponent). If the component is CPU do not fill the RAM size here, create another component for RAM, this field is for the embeded memory of a component.)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Manufacturer",
                        "info": "(the name of the manufacturer, example: nvidia)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Family",
                        "info": "(the family of this component, example: geforce)",
                    },
                    {
                        "type": gr.Textbox,
                        "label": "Series",
                        "info": "(the series of this component, example: gtx1080)",
                    },
                    {
                        "type": gr.Number,
                        "label": "Share",
                        "info": "(the percentage of the physical equipment used by the task, this sharing property should be set to 1 by default (if no share) and otherwise to the correct percentage, e.g. 0.5 if you share half-time.)",
                    }
                ],
                initial_count=0,
                layout="column"
            )

        return [
            infraType, cloudProvider, cloudInstance, cloudService, componentName, componentType,
            nbComponent, memorySize, manufacturer_infra, family,
            series, share
        ]


def create_environment_tab():
    """Create the environment tab components."""
    with gr.Tab("Environment"):
        country = gr.Textbox(
            label="Country", info="Required field", elem_classes="mandatory_field")
        latitude = gr.Number(label="Latitude", value=lambda: None)
        longitude = gr.Number(label="Longitude", value=lambda: None)
        location = gr.Textbox(
            label="Location", info="(more precise location like city, region or datacenter name)")
        powerSupplierType = gr.Dropdown(value=lambda: None,
                                        label="Power Supplier Type",
                                        choices=POWER_SUPPLIER_TYPES,
                                        info="(the type of power supplier)"
                                        )
        powerSource = gr.Dropdown(value=None,
                                  label="Power Source",
                                  choices=POWER_SOURCES,
                                  info="(the source of power)"
                                  )
        powerSourceCarbonIntensity = gr.Number(value=lambda: None,
                                               label="Power Source Carbon Intensity")

        return [
            country, latitude, longitude, location,
            powerSupplierType, powerSource, powerSourceCarbonIntensity
        ]


def create_quality_tab():
    """Create the quality tab components."""
    with gr.Tab("Quality"):
        quality = gr.Dropdown(value=None,
                              label="Quality",
                              choices=QUALITY_LEVELS,
                              info="(the quality of the information you provided, 3 possibilities : high (percentage error +/-10%), medium (percentage error +/-25%), low (percentage error +/-50%))"
                              )

        return [quality]