Spaces:
Sleeping
Sleeping
from fastapi import FastAPI, HTTPException, Body | |
from pydantic import BaseModel | |
from fastapi.templating import Jinja2Templates | |
import os | |
app = FastAPI() | |
# Определяем модель данных для запроса | |
class TextRequest(BaseModel): | |
text: str | |
# Подключаем шаблоны Jinja2 | |
templates = Jinja2Templates(directory="templates") | |
# Главная страница с текстом "server is running" | |
async def read_root(): | |
return templates.TemplateResponse("index.html", {"text": "server is running"}) | |
# Определяем единственный POST endpoint | |
def echo_text(text_request: TextRequest = Body(...)): | |
# Просто возвращаем поле text из запроса | |
return {"echoed_text": text_request.text} | |