OCEANAI / app /event_handlers /calculate_pt_scores_blocks.py
DmitryRyumin's picture
Summary
0ba2e4a
raw
history blame
No virus
2.83 kB
"""
File: clear_blocks.py
Author: Elena Ryumina and Dmitry Ryumin
Description: Event handler for clearing Gradio app blocks and components.
License: MIT License
"""
import gradio as gr
# Importing necessary components for the Gradio app
from app.oceanai_init import b5
from app.config import config_data
from app.practical_tasks import supported_practical_tasks
from app.components import (
html_message,
button,
dataframe,
files_create_ui,
radio_create_ui,
)
def event_handler_calculate_pt_scores_blocks(files, evt_data: gr.EventData):
_ = evt_data.target.__class__.__name__
out = False
b5.get_avt_predictions_gradio(
paths=files, url_accuracy="", accuracy=False, lang="en", out=out
)
b5.df_files_.to_csv(config_data.Filenames_PT_SCORES)
first_practical_task = next(iter(supported_practical_tasks))
df_files = b5.df_files_.copy()
df_files.reset_index(inplace=True)
return (
html_message(config_data.InformationMessages_NOTI_VIDEOS, False, False),
dataframe(
headers=df_files.columns.tolist(),
values=df_files.values.tolist(),
visible=True,
),
files_create_ui(
config_data.Filenames_PT_SCORES,
"single",
[".csv"],
config_data.OtherMessages_EXPORT_PT_SCORES,
True,
False,
True,
"csv-container",
),
gr.Column(visible=True),
radio_create_ui(
first_practical_task,
"Practical tasks",
list(map(str, supported_practical_tasks.keys())),
config_data.InformationMessages_PRACTICAL_TASKS_INFO,
True,
True,
),
radio_create_ui(
supported_practical_tasks[first_practical_task][0],
"Practical subtasks",
supported_practical_tasks[first_practical_task],
config_data.InformationMessages_PRACTICAL_SUBTASKS_INFO,
True,
True,
),
gr.JSON(
value={
str(task): supported_practical_tasks.get(task, [None])[0]
for task in supported_practical_tasks.keys()
},
visible=False,
render=True,
),
button(
config_data.OtherMessages_CALCULATE_PRACTICAL_TASK,
True,
1,
True,
"calculate_practical_task",
),
dataframe(visible=False),
files_create_ui(
None,
"single",
[".csv"],
config_data.OtherMessages_EXPORT_PS,
True,
False,
False,
"csv-container",
),
html_message(config_data.InformationMessages_NOTI_IN_DEV, False, False),
)