File size: 2,350 Bytes
b1fb35d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from fastapi import APIRouter, UploadFile, File, Depends, Form, Request, HTTPException
from fastapi.responses import FileResponse, JSONResponse
from client.dependencies import inference_service
from client.services import InferenceService
from PIL import Image
from io import BytesIO
from fastapi import Form

from PIL import Image
from io import BytesIO
import numpy as np
import os
import tempfile
import logging
from typing import List

router = APIRouter(tags=["Client"])


@router.get(path="/")
def login() -> FileResponse:
    return FileResponse(path="client/static/login.html")


@router.get(path="/index")
def static_index() -> FileResponse:
    return FileResponse(path="client/static/index.html")


@router.get(path="/createAccount")
def create_account(request: Request) -> FileResponse:
    return FileResponse(path="client/static/createAccount.html")


@router.post("/get_image")
async def get_image(
    image: UploadFile = File(...),
    inference_service: InferenceService = Depends(inference_service),
) -> JSONResponse:
    # Read the contents of the file
    contents = await image.read()

    # Get the size of the image
    size = len(contents)

    # Return a confirmation message with the size of the image
    return JSONResponse(
        content={
            "message": "Image received successfully",
            "filename": image.filename,
            "size": size,
        }
    )


@router.post("/submitAccount")
async def submit_account(
    video: UploadFile = File(...),
    email: str = Form(...),
    i_service: InferenceService = Depends(inference_service),
):
    """
    This function processes the create account form, reads the uploaded video,
    extracts some of the frames and saves them in a temporary directory.
    """
    # Log video file details
    logging.info(
        f"Received video: filename={video.filename}, content_type={video.content_type}"
    )
    logging.info(f"Received email: {email}")

    video_content: bytes = await video.read()
    i_service.save_video(video_content=video_content, user_id=email)
    frames_path: str = i_service.save_frames(user_id=email)
    model_path: str = i_service.train_model(frames_path=frames_path, user_id=email)
    i_service.push_model(model_path=model_path, user_id=email)
    return JSONResponse(content={"message": "Account created successfully"})