|
1 | 1 | from fastapi import FastAPI, UploadFile, File, Form |
2 | 2 | from fastapi.middleware.cors import CORSMiddleware |
| 3 | +import shortuuid |
3 | 4 |
|
| 5 | +from backend.file_utils.files import reset_dir |
4 | 6 | from backend.utils.docker_runner import run_pipeline |
5 | 7 | from backend.utils.data_uploader import handle_upload |
6 | 8 | from backend.utils.methods_handler import Methods |
7 | 9 | from backend.utils.results_sender import send_folder_by_email |
8 | | -from backend.config.paths import RESULTS_DIR, DATASET_FILE, METHODS_TS_FILE |
| 10 | +from backend.config.paths import ( |
| 11 | + RESULTS_DIR, |
| 12 | + DATASET_FILE, |
| 13 | + METHODS_TS_FILE, |
| 14 | + get_process_filepath, BASE_DIR, |
| 15 | +) |
9 | 16 |
|
10 | 17 | dataset_methods = Methods(data_filepath=DATASET_FILE, output_filepath=METHODS_TS_FILE) |
11 | 18 |
|
|
20 | 27 |
|
21 | 28 |
|
22 | 29 | @app.post("/api/upload") |
23 | | -async def upload_file( |
24 | | - file: UploadFile = File(...), |
25 | | - email: str = Form(...), |
26 | | - methods: str = Form(...), |
27 | | - experiment: str = Form(...), |
| 30 | +async def handle_submit( |
| 31 | + file: UploadFile = File(...), |
| 32 | + email: str = Form(...), |
| 33 | + methods: str = Form(...), |
| 34 | + experiment: str = Form(...), |
28 | 35 | ): |
29 | | - handle_upload(file, methods, dataset_methods) |
| 36 | + task_uid = str(shortuuid.uuid()) |
| 37 | + |
| 38 | + handle_upload(task_uid, file, methods, dataset_methods) |
30 | 39 |
|
31 | | - run_pipeline() |
| 40 | + run_pipeline(task_uid) |
32 | 41 |
|
33 | 42 | send_folder_by_email( |
34 | 43 | email, |
35 | | - RESULTS_DIR, |
| 44 | + get_process_filepath(task_uid, RESULTS_DIR), |
36 | 45 | experiment, |
37 | 46 | file.filename, |
38 | 47 | ) |
39 | 48 |
|
| 49 | + reset_dir(BASE_DIR) |
40 | 50 | return { |
41 | 51 | "experiment": experiment, |
42 | 52 | "filename": file.filename, |
|
0 commit comments