from fastapi import FastAPI, Form, Request from fastapi.responses import HTMLResponse, FileResponse from fastapi.templating import Jinja2Templates import os app = FastAPI() templates = Jinja2Templates(directory=os.path.dirname(__file__)) @app.get("/", response_class=HTMLResponse) async def read_form(request: Request): return templates.TemplateResponse("index.html", {"request": request}) @app.post("/predict") async def predict(input_text: str = Form(...)): # Example of processing input output_text = "This is the output based on input: " + input_text return {"output": output_text} if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)