| from fasthtml.common import * |
| from agents.extractor import process_data |
| from app.components import PageLayout, HeroSection, ExtractionForm, SuccessDisplay, ErrorDisplay, LoadingIndicator |
| import json |
|
|
| |
| app, rt = fast_app( |
| hdrs=(picolink,) |
| ) |
|
|
| @rt('/') |
| def get(): |
| """Renders the Home Page""" |
| return PageLayout( |
| "Structura | AI Data Architect", |
| [ |
| HeroSection(), |
| ExtractionForm(), |
| LoadingIndicator(), |
| Div(id="result-area") |
| ] |
| ) |
|
|
| @rt('/extract') |
| async def post(text_input: str, schema_type: str): |
| """ |
| Handles the HTMX POST request. |
| Returns ONLY the result component (HTML snippet), not the full page. |
| """ |
| if not text_input: |
| return ErrorDisplay("Please provide input text to analyze.") |
| |
| try: |
| |
| data = await process_data(text_input, schema_type) |
| |
| |
| if isinstance(data, dict) and "error" in data: |
| return ErrorDisplay(f"Agent Error: {data['error']}") |
| |
| |
| |
| if hasattr(data, 'model_dump_json'): |
| json_str = data.model_dump_json(indent=2) |
| else: |
| json_str = json.dumps(data, indent=2) |
| |
| |
| return SuccessDisplay(json_str) |
| |
| except Exception as e: |
| |
| return ErrorDisplay(f"System Critical: {str(e)}") |
|
|
| |
| target = app |
|
|