File size: 773 Bytes
1bacad4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from typing import Optional



from pydantic import BaseModel


app = FastAPI()
templates = Jinja2Templates(directory="templates")


# Create a Pydantic model for the form data
class DatasetForm(BaseModel):
    dataset_name: str
    


@app.get("/", response_class=HTMLResponse)
async def read_form(request: Request):
    # Render the form.html template
    return templates.TemplateResponse("form.html", {"request": request})


@app.post("/submit_form")
async def form_post(form_data: DatasetForm):
    # Do something with form_data
    print(form_data.dict())
    return {"message": "Form data received!", "received_data": form_data.dict()}