File size: 1,224 Bytes
85784d8 |
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
from fastapi.requests import Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from models.Interpretador import Interpretador
from requestsBaseModels.InterpretadorRequestBaseModel import InterpretadorRequestBaseModel
from responsesBaseModels.InterpretadorResponseBaseModel import InterpretadorResponseBaseModel
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
@app.get('/', response_class=HTMLResponse)
async def main(request: Request):
context = {"request": request}
response = templates.TemplateResponse("index.html", context)
return response
@app.post('/', response_model=InterpretadorResponseBaseModel)
async def responder(request: InterpretadorRequestBaseModel):
texto = request.texto
pergunta = request.pergunta
interpretador = Interpretador(texto, pergunta)
resposta = interpretador.resposta
response = InterpretadorResponseBaseModel(resposta=resposta)
return response
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=7860) |