Spaces:
Sleeping
Sleeping
Commit
•
1299710
1
Parent(s):
14fd956
Update main.py
Browse files
main.py
CHANGED
@@ -5,6 +5,10 @@ import os
|
|
5 |
|
6 |
app = FastAPI()
|
7 |
|
|
|
|
|
|
|
|
|
8 |
# Подключаем шаблоны Jinja2
|
9 |
templates = Jinja2Templates(directory="templates")
|
10 |
|
@@ -14,7 +18,7 @@ templates = Jinja2Templates(directory="templates")
|
|
14 |
async def read_root():
|
15 |
return templates.TemplateResponse("index.html", {"text": "server is running"})
|
16 |
|
17 |
-
|
18 |
@app.post("/echo")
|
19 |
def echo_text(text_request: TextRequest = Body(...)):
|
20 |
# Просто возвращаем поле text из запроса
|
|
|
5 |
|
6 |
app = FastAPI()
|
7 |
|
8 |
+
# Определяем модель данных для запроса
|
9 |
+
class TextRequest(BaseModel):
|
10 |
+
text: str
|
11 |
+
|
12 |
# Подключаем шаблоны Jinja2
|
13 |
templates = Jinja2Templates(directory="templates")
|
14 |
|
|
|
18 |
async def read_root():
|
19 |
return templates.TemplateResponse("index.html", {"text": "server is running"})
|
20 |
|
21 |
+
# Определяем единственный POST endpoint
|
22 |
@app.post("/echo")
|
23 |
def echo_text(text_request: TextRequest = Body(...)):
|
24 |
# Просто возвращаем поле text из запроса
|