| import gradio as gr |
| from os import path |
| from src.services.huggingface import init_huggingface, update_dataset |
| from src.services.json_generator import generate_json |
| from src.ui.form_components import ( |
| create_header_tab, |
| create_task_tab, |
| create_measures_tab, |
| create_system_tab, |
| create_software_tab, |
| create_infrastructure_tab, |
| create_environment_tab, |
| create_quality_tab |
| ) |
| css_path = path.join(path.dirname(__file__), "./assets/styles/app.css") |
|
|
| |
| init_huggingface() |
|
|
|
|
| def handle_submit(*inputs): |
| message, file_output, json_output = generate_json(*inputs) |
|
|
| |
| if message.startswith("The following fields are required"): |
| return message, file_output, json_output |
|
|
| publish_button = gr.Button( |
| "Share your data to the public repository", interactive=True, elem_classes="pubbutton") |
|
|
| return "Report sucessefully created", file_output, json_output, publish_button |
|
|
|
|
| def handle_publi(json_output): |
| |
| update_output = update_dataset(json_output) |
| return update_output |
|
|
|
|
| |
| with gr.Blocks(css_paths=css_path) as app: |
| gr.Markdown("## Data Collection Form") |
| gr.Markdown("Welcome to this Huggingface space, where you can create a report on the energy consumption of an AI task in BoAmps format, by filling in a form.<br>" |
| "Parts/fields in bold red are mandatory.") |
|
|
| |
| header_components = create_header_tab() |
| task_components = create_task_tab() |
| measures_components = create_measures_tab() |
| system_components = create_system_tab() |
| software_components = create_software_tab() |
| infrastructure_components = create_infrastructure_tab() |
| environment_components = create_environment_tab() |
| quality_components = create_quality_tab() |
|
|
| |
| submit_button = gr.Button("Submit", elem_classes="subbutton") |
| output = gr.Textbox(label="Output", lines=1) |
| json_output = gr.Textbox(visible=False) |
| file_output = gr.File(label="Downloadable JSON") |
| publish_button = gr.Button( |
| "Share your data to the public repository", interactive=False, elem_classes="pubbutton") |
|
|
| |
| submit_button.click( |
| handle_submit, |
| inputs=[ |
| *header_components, |
| *task_components, |
| *measures_components, |
| *system_components, |
| *software_components, |
| *infrastructure_components, |
| *environment_components, |
| *quality_components, |
| ], |
| outputs=[output, file_output, json_output, publish_button] |
| ) |
| |
| publish_button.click( |
| handle_publi, |
| inputs=[ |
| json_output |
| ], |
| outputs=[output] |
| ) |
|
|
| if __name__ == "__main__": |
| app.launch() |
|
|