soury commited on
Commit
3efb4a6
·
1 Parent(s): c9117ba

repair deployment & doc

Browse files
src/app.py → app.py RENAMED
@@ -13,7 +13,7 @@ from src.ui.form_components import (
13
  create_quality_tab,
14
  create_hash_tab
15
  )
16
- css_path = path.join(path.dirname(__file__), "../assets/styles/app.css")
17
 
18
  # Initialize Hugging Face
19
  init_huggingface()
@@ -71,3 +71,6 @@ with gr.Blocks(css_paths=css_path) as app:
71
  ],
72
  outputs=[output, file_output, json_output]
73
  )
 
 
 
 
13
  create_quality_tab,
14
  create_hash_tab
15
  )
16
+ css_path = path.join(path.dirname(__file__), "./assets/styles/app.css")
17
 
18
  # Initialize Hugging Face
19
  init_huggingface()
 
71
  ],
72
  outputs=[output, file_output, json_output]
73
  )
74
+
75
+ if __name__ == "__main__":
76
+ app.launch()
main.py DELETED
@@ -1,4 +0,0 @@
1
- from src.app import app
2
-
3
- print("Launching BoAmps form")
4
- app.launch()
 
 
 
 
 
src/services/huggingface.py CHANGED
@@ -42,163 +42,19 @@ def update_dataset(json_data):
42
 
43
 
44
  def create_flattened_data(data):
45
- """Create a flattened data structure for the dataset."""
46
-
47
- # Handle inference properties
48
- inference_props = data.get("task", {}).get(
49
- "dataset", {}).get("inferenceProperties", [])
50
-
51
- # Process inference properties
52
- inference_data = []
53
- for props in inference_props:
54
- if props:
55
- inference_data.append({
56
- "nbRequest": props.get("nbRequest"),
57
- "nbTokensInput": props.get("nbTokensInput"),
58
- "nbWordsInput": props.get("nbWordsInput"),
59
- "nbTokensOutput": props.get("nbTokensOutput"),
60
- "nbWordsOutput": props.get("nbWordsOutput"),
61
- "contextWindowSize": props.get("contextWindowSize"),
62
- "cache": props.get("cache")
63
- })
64
-
65
- nbRequest_str = ", ".join([str(p["nbRequest"]) for p in inference_data if p.get(
66
- "nbRequest")]) if inference_data else None
67
- nbTokensInput_str = ", ".join([str(p["nbTokensInput"]) for p in inference_data if p.get(
68
- "nbTokensInput")]) if inference_data else None
69
- nbWordsInput_str = ", ".join([str(p["nbWordsInput"]) for p in inference_data if p.get(
70
- "nbWordsInput")]) if inference_data else None
71
- nbTokensOutput_str = ", ".join([str(p["nbTokensOutput"]) for p in inference_data if p.get(
72
- "nbTokensOutput")]) if inference_data else None
73
- nbWordsOutput_str = ", ".join([str(p["nbWordsOutput"]) for p in inference_data if p.get(
74
- "nbWordsOutput")]) if inference_data else None
75
- contextWindowSize_str = ", ".join([str(p["contextWindowSize"]) for p in inference_data if p.get(
76
- "contextWindowSize")]) if inference_data else None
77
- cache_str = ", ".join([str(p["cache"]) for p in inference_data if p.get(
78
- "cache")]) if inference_data else None
79
-
80
- # Handle components
81
- components = data.get("infrastructure", {}).get("components", [])
82
- component_data = []
83
- for comp in components:
84
- if comp:
85
- component_data.append({
86
- "componentName": comp.get("componentName"),
87
- "nbComponent": comp.get("nbComponent"),
88
- "memorySize": comp.get("memorySize"),
89
- "manufacturer": comp.get("manufacturer"),
90
- "family": comp.get("family"),
91
- "series": comp.get("series"),
92
- "share": comp.get("share")
93
- })
94
-
95
- componentName_str = ", ".join([str(p["componentName"]) for p in component_data if p.get(
96
- "componentName")]) if component_data else None
97
- nbComponent_str = ", ".join([str(p["nbComponent"]) for p in component_data if p.get(
98
- "nbComponent")]) if component_data else None
99
- memorySize_str = ", ".join([str(p["memorySize"]) for p in component_data if p.get(
100
- "memorySize")]) if component_data else None
101
- manufacturer_infra_str = ", ".join([str(p["manufacturer"]) for p in component_data if p.get(
102
- "manufacturer")]) if component_data else None
103
- family_str = ", ".join([str(p["family"]) for p in component_data if p.get(
104
- "family")]) if component_data else None
105
- series_str = ", ".join([str(p["series"]) for p in component_data if p.get(
106
- "series")]) if component_data else None
107
- share_str = ", ".join([str(p["share"]) for p in component_data if p.get(
108
- "share")]) if component_data else None
109
-
110
- return {
111
- # Header
112
- "licensing": [data["header"]["licensing"]],
113
- "formatVersion": [data["header"]["formatVersion"]],
114
- "formatVersionSpecificationUri": [data["header"]["formatVersionSpecificationUri"]],
115
- "reportId": [data["header"]["reportId"]],
116
- "reportDatetime": [data["header"]["reportDatetime"]],
117
- "reportStatus": [data["header"]["reportStatus"]],
118
- "publisher_name": [data["header"]["publisher"]["name"]],
119
- "publisher_division": [data["header"]["publisher"]["division"]],
120
- "publisher_projectName": [data["header"]["publisher"]["projectName"]],
121
- "publisher_confidentialityLevel": [data["header"]["publisher"]["confidentialityLevel"]],
122
- "publisher_publicKey": [data["header"]["publisher"]["publicKey"]],
123
-
124
- # Task
125
- "taskFamily": [data["task"]["taskFamily"]],
126
- "taskStage": [data["task"]["taskStage"]],
127
- "algorithmName": [data["task"]["algorithms"][0]["algorithmName"]],
128
- "framework": [data["task"]["algorithms"][0]["framework"]],
129
- "frameworkVersion": [data["task"]["algorithms"][0]["frameworkVersion"]],
130
- "classPath": [data["task"]["algorithms"][0]["classPath"]],
131
- "quantization": [data["task"]["algorithms"][0]["quantization"]],
132
- "dataType": [data["task"]["dataset"][0]["dataType"]],
133
- "fileType": [data["task"]["dataset"][0]["fileType"]],
134
- "volume": [data["task"]["dataset"][0]["volume"]],
135
- "volumeUnit": [data["task"]["dataset"][0]["volumeUnit"]],
136
- "items": [data["task"]["dataset"][0]["items"]],
137
- "shape_item": [data["task"]["dataset"][0]["shape"][0]["item"]],
138
- "nbRequest": [nbRequest_str],
139
- "nbTokensInput": [nbTokensInput_str],
140
- "nbWordsInput": [nbWordsInput_str],
141
- "nbTokensOutput": [nbTokensOutput_str],
142
- "nbWordsOutput": [nbWordsOutput_str],
143
- "contextWindowSize": [contextWindowSize_str],
144
- "cache": [cache_str],
145
- "source": [data["task"]["dataset"][0]["source"]],
146
- "sourceUri": [data["task"]["dataset"][0]["sourceUri"]],
147
- "owner": [data["task"]["dataset"][0]["owner"]],
148
- "measuredAccuracy": [data["task"]["measuredAccuracy"]],
149
- "estimatedAccuracy": [data["task"]["estimatedAccuracy"]],
150
-
151
- # Measures
152
- "measurementMethod": [data["measures"][0]["measurementMethod"]],
153
- "manufacturer": [data["measures"][0]["manufacturer"]],
154
- "version": [data["measures"][0]["version"]],
155
- "cpuTrackingMode": [data["measures"][0]["cpuTrackingMode"]],
156
- "gpuTrackingMode": [data["measures"][0]["gpuTrackingMode"]],
157
- "averageUtilizationCpu": [data["measures"][0]["averageUtilizationCpu"]],
158
- "averageUtilizationGpu": [data["measures"][0]["averageUtilizationGpu"]],
159
- "serverSideInference": [data["measures"][0]["serverSideInference"]],
160
- "unit": [data["measures"][0]["unit"]],
161
- "powerCalibrationMeasurement": [data["measures"][0]["powerCalibrationMeasurement"]],
162
- "durationCalibrationMeasurement": [data["measures"][0]["durationCalibrationMeasurement"]],
163
- "powerConsumption": [data["measures"][0]["powerConsumption"]],
164
- "measurementDuration": [data["measures"][0]["measurementDuration"]],
165
- "measurementDateTime": [data["measures"][0]["measurementDateTime"]],
166
-
167
- # System
168
- "os": [data["system"]["os"]],
169
- "distribution": [data["system"]["distribution"]],
170
- "distributionVersion": [data["system"]["distributionVersion"]],
171
-
172
- # Software
173
- "language": [data["software"]["language"]],
174
- "version_software": [data["software"]["version"]],
175
-
176
- # Infrastructure
177
- "infraType": [data["infrastructure"]["infraType"]],
178
- "cloudProvider": [data["infrastructure"]["cloudProvider"]],
179
- "cloudInstance": [data["infrastructure"]["cloudInstance"]],
180
- "componentName": [componentName_str],
181
- "nbComponent": [nbComponent_str],
182
- "memorySize": [memorySize_str],
183
- "manufacturer_infra": [manufacturer_infra_str],
184
- "family": [family_str],
185
- "series": [series_str],
186
- "share": [share_str],
187
-
188
- # Environment
189
- "country": [data["environment"]["country"]],
190
- "latitude": [data["environment"]["latitude"]],
191
- "longitude": [data["environment"]["longitude"]],
192
- "location": [data["environment"]["location"]],
193
- "powerSupplierType": [data["environment"]["powerSupplierType"]],
194
- "powerSource": [data["environment"]["powerSource"]],
195
- "powerSourceCarbonIntensity": [data["environment"]["powerSourceCarbonIntensity"]],
196
-
197
- # Quality
198
- "quality": [data["quality"]],
199
-
200
- # Hash
201
- "hashAlgorithm": [data["$hash"]["hashAlgorithm"]],
202
- "cryptographicAlgorithm": [data["$hash"]["cryptographicAlgorithm"]],
203
- "value": [data["$hash"]["ecryptedValue"]]
204
- }
 
42
 
43
 
44
  def create_flattened_data(data):
45
+ out = {}
46
+
47
+ def flatten(x, name=''):
48
+ if type(x) is dict:
49
+ for a in x:
50
+ flatten(x[a], name + a + '_')
51
+ elif type(x) is list:
52
+ i = 0
53
+ for a in x:
54
+ flatten(a, name + str(i) + '_')
55
+ i += 1
56
+ else:
57
+ out[name[:-1]] = x
58
+
59
+ flatten(data)
60
+ return out
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/services/json_generator.py CHANGED
@@ -13,7 +13,7 @@ def generate_json(
13
  taskFamily, taskStage, nbRequest,
14
  trainingType, algorithmType, algorithmName, algorithmUri, foundationModelName, foundationModelUri, parametersNumber, framework, frameworkVersion, classPath, layersNumber, epochsNumber, optimizer, quantization,
15
  dataUsage, dataType, dataFormat, dataSize, dataQuantity, shape, source, sourceUri, owner,
16
- measuredAccuracy, estimatedAccuracy,
17
  # Measures
18
  measurementMethod, manufacturer, version, cpuTrackingMode, gpuTrackingMode,
19
  averageUtilizationCpu, averageUtilizationGpu, powerCalibrationMeasurement,
@@ -148,6 +148,8 @@ def generate_json(
148
  task["measuredAccuracy"] = measuredAccuracy
149
  if estimatedAccuracy:
150
  task["estimatedAccuracy"] = estimatedAccuracy
 
 
151
  report["task"] = task
152
 
153
  # proceed measures
 
13
  taskFamily, taskStage, nbRequest,
14
  trainingType, algorithmType, algorithmName, algorithmUri, foundationModelName, foundationModelUri, parametersNumber, framework, frameworkVersion, classPath, layersNumber, epochsNumber, optimizer, quantization,
15
  dataUsage, dataType, dataFormat, dataSize, dataQuantity, shape, source, sourceUri, owner,
16
+ measuredAccuracy, estimatedAccuracy, taskDescription,
17
  # Measures
18
  measurementMethod, manufacturer, version, cpuTrackingMode, gpuTrackingMode,
19
  averageUtilizationCpu, averageUtilizationGpu, powerCalibrationMeasurement,
 
148
  task["measuredAccuracy"] = measuredAccuracy
149
  if estimatedAccuracy:
150
  task["estimatedAccuracy"] = estimatedAccuracy
151
+ if taskDescription:
152
+ task["taskDescription"] = taskDescription
153
  report["task"] = task
154
 
155
  # proceed measures
src/ui/form_components.py CHANGED
@@ -9,39 +9,85 @@ from src.services.util import (
9
 
10
 
11
  def create_dynamic_section(section_name, fields_config, initial_count=1, layout="row"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # State management
 
13
  count_state = gr.State(value=initial_count+1)
 
14
  field_states = [gr.State([]) for _ in fields_config]
 
15
  all_components = []
16
 
17
  def update_fields(*states_and_values):
18
- """Generic update function for multiple fields"""
 
 
 
 
 
 
 
 
19
  # Split states and current values
 
20
  states = list(states_and_values[:len(fields_config)])
 
21
  current_values = states_and_values[len(fields_config):-1]
22
- index = states_and_values[-1]
23
 
24
  # Update each field's state
25
  for field_idx, (state, value) in enumerate(zip(states, current_values)):
26
- # Ensure state list is long enough
27
  while len(state) <= index:
28
  state.append("")
29
- # Update the value at the correct index
30
  state[index] = value if value is not None else ""
31
 
32
  return tuple(states)
33
 
34
  @gr.render(inputs=count_state)
35
  def render_dynamic_section(count):
 
 
 
 
 
 
 
 
 
36
  nonlocal all_components
37
- all_components = []
38
 
39
  for i in range(count):
 
40
  with (gr.Row() if layout == "row" else gr.Column()):
41
- row_components = []
42
- field_refs = [] # To store references to current row's components
43
 
44
  for field_idx, config in enumerate(fields_config):
 
45
  component = config["type"](
46
  label=f"{config['label']} ({section_name}{i + 1})",
47
  info=config.get("info", ""),
@@ -52,31 +98,34 @@ def create_dynamic_section(section_name, fields_config, initial_count=1, layout=
52
  row_components.append(component)
53
  field_refs.append(component)
54
 
55
- # Create change event with ALL current field values
56
  component.change(
57
  fn=update_fields,
58
  inputs=[*field_states, *field_refs, gr.State(i)],
59
  outputs=field_states
60
  )
61
 
62
- # Remove button
63
  remove_btn = gr.Button("❌", variant="secondary")
64
  remove_btn.click(
65
  lambda x, idx=i, fs=field_states: (
66
- max(0, x-1),
67
- *[fs[i].value[:idx] + fs[i].value[idx+1:] for i in range(len(fs))]
 
68
  ),
69
  inputs=count_state,
70
  outputs=[count_state, *field_states]
71
  )
72
  row_components.append(remove_btn)
73
 
 
74
  all_components.extend(row_components)
75
  return all_components
76
 
77
- # Initialize with initial count
78
  render_dynamic_section(count=initial_count)
79
 
 
80
  add_btn = gr.Button(f"Add {section_name}")
81
  add_btn.click(lambda x: x + 1, count_state, count_state)
82
 
@@ -287,12 +336,15 @@ def create_task_tab():
287
  choices=ACCURACY_LEVELS,
288
  info="(estimated accuracy assessment)"
289
  )
 
 
 
290
 
291
  return [
292
  taskFamily, taskStage, nbRequest,
293
  trainingType, algorithmType, algorithmName, algorithmUri, foundationModelName, foundationModelUri, parametersNumber, framework, frameworkVersion, classPath, layersNumber, epochsNumber, optimizer, quantization,
294
  dataUsage, dataType, dataFormat, dataSize, dataQuantity, shape, source, sourceUri, owner,
295
- measuredAccuracy, estimatedAccuracy
296
  ]
297
 
298
 
 
9
 
10
 
11
  def create_dynamic_section(section_name, fields_config, initial_count=1, layout="row"):
12
+ """
13
+ Creates a dynamic section in a Gradio interface where users can add or remove rows of input fields.
14
+
15
+ Args:
16
+ section_name (str): The name of the section (e.g., "Algorithms", "Components").
17
+ fields_config (list): A list of dictionaries defining the configuration for each field in the section.
18
+ Each dictionary should include:
19
+ - "type": The Gradio component type (e.g., gr.Textbox, gr.Number).
20
+ - "label": The label for the field.
21
+ - "info": Additional information or tooltip for the field.
22
+ - "value" (optional): The default value for the field.
23
+ - "kwargs" (optional): Additional keyword arguments for the component.
24
+ - "elem_classes" (optional): CSS classes for styling the field.
25
+ initial_count (int): The initial number of rows to render in the section.
26
+ layout (str): The layout of the fields in each row ("row" or "column").
27
+
28
+ Returns:
29
+ tuple: A tuple containing:
30
+ - count_state: A Gradio state object tracking the number of rows.
31
+ - field_states: A list of Gradio state objects, one for each field, to store the values of the fields.
32
+ - add_btn: The "Add" button component for adding new rows.
33
+ """
34
  # State management
35
+ # Tracks the number of rows in the section.
36
  count_state = gr.State(value=initial_count+1)
37
+ # Stores the values for each field across all rows.
38
  field_states = [gr.State([]) for _ in fields_config]
39
+ # A list to store all dynamically generated components.
40
  all_components = []
41
 
42
  def update_fields(*states_and_values):
43
+ """
44
+ Updates the state of the fields when a value changes.
45
+
46
+ Args:
47
+ *states_and_values: A combination of the current states and the new values for the fields.
48
+
49
+ Returns:
50
+ tuple: Updated states for all fields.
51
+ """
52
  # Split states and current values
53
+ # Extract the current states for each field.
54
  states = list(states_and_values[:len(fields_config)])
55
+ # Extract the new values for the fields.
56
  current_values = states_and_values[len(fields_config):-1]
57
+ index = states_and_values[-1] # The index of the row being updated.
58
 
59
  # Update each field's state
60
  for field_idx, (state, value) in enumerate(zip(states, current_values)):
61
+ # Ensure the state list is long enough to accommodate the current index.
62
  while len(state) <= index:
63
  state.append("")
64
+ # Update the value at the specified index.
65
  state[index] = value if value is not None else ""
66
 
67
  return tuple(states)
68
 
69
  @gr.render(inputs=count_state)
70
  def render_dynamic_section(count):
71
+ """
72
+ Renders the dynamic section with the current number of rows and their states.
73
+
74
+ Args:
75
+ count (int): The number of rows to render.
76
+
77
+ Returns:
78
+ list: A list of dynamically generated components for the section.
79
+ """
80
  nonlocal all_components
81
+ all_components = [] # Reset the list of components for re-rendering.
82
 
83
  for i in range(count):
84
+ # Create a row or column layout for the current row of fields.
85
  with (gr.Row() if layout == "row" else gr.Column()):
86
+ row_components = [] # Components for the current row.
87
+ field_refs = [] # References to the current row's components.
88
 
89
  for field_idx, config in enumerate(fields_config):
90
+ # Create a component for the field using its configuration.
91
  component = config["type"](
92
  label=f"{config['label']} ({section_name}{i + 1})",
93
  info=config.get("info", ""),
 
98
  row_components.append(component)
99
  field_refs.append(component)
100
 
101
+ # Create a change event to update the field states when the value changes.
102
  component.change(
103
  fn=update_fields,
104
  inputs=[*field_states, *field_refs, gr.State(i)],
105
  outputs=field_states
106
  )
107
 
108
+ # Add a "Remove" button to delete the current row.
109
  remove_btn = gr.Button("❌", variant="secondary")
110
  remove_btn.click(
111
  lambda x, idx=i, fs=field_states: (
112
+ max(0, x - 1), # Decrease the count of rows.
113
+ # Remove the row's values.
114
+ *[fs[i].value[:idx] + fs[i].value[idx + 1:] for i in range(len(fs))]
115
  ),
116
  inputs=count_state,
117
  outputs=[count_state, *field_states]
118
  )
119
  row_components.append(remove_btn)
120
 
121
+ # Add the row's components to the list of all components.
122
  all_components.extend(row_components)
123
  return all_components
124
 
125
+ # Initialize the section with the initial count of rows.
126
  render_dynamic_section(count=initial_count)
127
 
128
+ # Create an "Add" button to add new rows to the section.
129
  add_btn = gr.Button(f"Add {section_name}")
130
  add_btn.click(lambda x: x + 1, count_state, count_state)
131
 
 
336
  choices=ACCURACY_LEVELS,
337
  info="(estimated accuracy assessment)"
338
  )
339
+ with gr.Row():
340
+ taskDescription = gr.Textbox(
341
+ label="Task description", info="(free field, to be fillied in if you have more details to share about your task)")
342
 
343
  return [
344
  taskFamily, taskStage, nbRequest,
345
  trainingType, algorithmType, algorithmName, algorithmUri, foundationModelName, foundationModelUri, parametersNumber, framework, frameworkVersion, classPath, layersNumber, epochsNumber, optimizer, quantization,
346
  dataUsage, dataType, dataFormat, dataSize, dataQuantity, shape, source, sourceUri, owner,
347
+ measuredAccuracy, estimatedAccuracy, taskDescription
348
  ]
349
 
350