Spaces:
Sleeping
Sleeping
File size: 819 Bytes
c73e7bc 14fd956 dce9570 b916cdf 1299710 dce9570 2926b0b c73e7bc 2926b0b dce9570 1299710 2926b0b 2d683a3 2926b0b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from fastapi import FastAPI, HTTPException, Body, Request
from pydantic import BaseModel
from fastapi.templating import Jinja2Templates
app = FastAPI()
# Определяем модель данных для запроса
class TextRequest(BaseModel):
text: str
# Подключаем шаблоны Jinja2
templates = Jinja2Templates(directory="templates")
# Главная страница с текстом "server is running"
@app.get("/")
async def read_root(request: Request):
return templates.TemplateResponse("index.html", {"text": "server is running"})
# Определяем единственный POST endpoint
@app.post("/echo")
def echo_text(text_request: TextRequest):
# Просто возвращаем поле text из запроса
return {"echoed_text": text_request.text}
|