intents.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from dash import html, dcc
  2. import dash_bootstrap_components as dbc
  3. from utils.file_utils import list_files_in_directory, get_file_metadata
  4. INTENT_DIR = './training/intents/'
  5. def IntentsLayout():
  6. intent_files = list_files_in_directory(INTENT_DIR)
  7. intent_table = generate_intent_table(intent_files)
  8. return html.Div([
  9. html.H2("Intent Management"),
  10. dbc.Button("Add New Intent", id="add-new-intent", color="primary", className="mb-3"),
  11. html.Div(id="new-intent-input"),
  12. intent_table,
  13. html.Div(id="intent-upload-status")
  14. ])
  15. def generate_intent_table(files):
  16. header = [
  17. html.Thead(html.Tr([html.Th("File Name"), html.Th("Length (s)"), html.Th("Size (KB)"), html.Th("Actions")]))
  18. ]
  19. rows = []
  20. for file in files:
  21. length, size = get_file_metadata(f"{INTENT_DIR}/{file}")
  22. rows.append(html.Tr([
  23. html.Td(file),
  24. html.Td(length),
  25. html.Td(size),
  26. html.Td(
  27. dbc.Button("Delete", id={'type': 'delete-button', 'index': file}, color='danger')
  28. )
  29. ]))
  30. return dbc.Table(header + [html.Tbody(rows)], bordered=True, hover=True)