ZakharZokhar commited on
Commit
2926b0b
1 Parent(s): a12d6fd

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -27
main.py CHANGED
@@ -6,38 +6,18 @@ import os
6
 
7
  app = FastAPI()
8
 
9
- # Директория для временного хранения загруженных файлов
10
- UPLOAD_DIRECTORY = "uploads"
11
- os.makedirs(UPLOAD_DIRECTORY, exist_ok=True)
12
-
13
  # Подключаем шаблоны Jinja2
14
  templates = Jinja2Templates(directory="templates")
15
 
16
 
17
  # Главная страница с текстом "server is running"
18
- @app.get("/", response_class=HTMLResponse)
19
- async def read_root(request: Request):
20
- return templates.TemplateResponse("index.html", {"request": request, "text": "server is running"})
21
-
22
-
23
- @app.post('/update_text/')
24
- async def update_text(data: TextData):
25
- received_text = data.text
26
- return {"received_text": received_text}
27
-
28
-
29
- # Второй POST эндпоинт для приема файла и текстового поля prompt
30
- @app.post("/upload_file/")
31
- async def upload_file(prompt: str, file: UploadFile = File(...)):
32
- # Сохраняем файл в директорию UPLOAD_DIRECTORY
33
- file_location = os.path.join(UPLOAD_DIRECTORY, file.filename)
34
- with open(file_location, "wb") as file_object:
35
- file_object.write(file.file.read())
36
 
37
- # Отправляем запрос на первый эндпоинт с текстом равным имени загруженного файла
38
- response = await update_text(file.filename)
39
 
40
- # Удаляем загруженный файл
41
- os.remove(file_location)
 
 
42
 
43
- return response
 
6
 
7
  app = FastAPI()
8
 
 
 
 
 
9
  # Подключаем шаблоны Jinja2
10
  templates = Jinja2Templates(directory="templates")
11
 
12
 
13
  # Главная страница с текстом "server is running"
14
+ @app.get("/")
15
+ async def read_root():
16
+ return templates.TemplateResponse("index.html", {"text": "server is running"})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
 
 
18
 
19
+ @app.post("/echo")
20
+ def echo_text(text_request: TextRequest = Body(...)):
21
+ # Просто возвращаем поле text из запроса
22
+ return {"echoed_text": text_request.text}
23