36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Callable, Iterable
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from fastapi import HTTPException
|
|
|
|
from api_server.html5_ai_structure import render_html5_ai_structure_page, render_html5_ai_structure_result
|
|
from api_server.html5_forms import form_value
|
|
|
|
|
|
def html5_ai_structure_page(
|
|
*,
|
|
project_id: str,
|
|
project_summaries: Callable[[], Iterable[object]],
|
|
) -> str:
|
|
return render_html5_ai_structure_page(project_id=project_id, projects=project_summaries())
|
|
|
|
|
|
def html5_ai_structure_run(
|
|
*,
|
|
project_id: str,
|
|
form: dict[str, list[str]],
|
|
prepare: Callable[..., dict[str, Any]],
|
|
) -> str:
|
|
effective_project_id = form_value(form, "project_id") or project_id
|
|
input_path = form_value(form, "input_path")
|
|
output_path = form_value(form, "output_path")
|
|
if not input_path:
|
|
raise HTTPException(status_code=400, detail="input_path is required")
|
|
if not output_path:
|
|
raise HTTPException(status_code=400, detail="output_path is required")
|
|
result = prepare(project_id=effective_project_id, input_path=Path(input_path), output_path=Path(output_path))
|
|
return render_html5_ai_structure_result(result)
|