Skip to content

Upload

upload_file(uploaded_file, id, type_of_analysis, user)

Uploads the file for analysis.

Parameters:

Name Type Description Default
uploaded_file Any

The file object to be uploaded.

required
id str

Unique identifier for the task.

required
type_of_analysis str

The type of analysis to be performed.

required
user str

The username or identifier of the user.

required

Returns:

Name Type Description
dict Dict

The response from the API after the upload request.

Source code in view/streamlit_app/upload.py
 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
def upload_file(uploaded_file: Any, id: str, type_of_analysis: str, user: str) -> Dict:
    """
    Uploads the file for analysis.

    Args:
        uploaded_file (Any): The file object to be uploaded.
        id (str): Unique identifier for the task.
        type_of_analysis (str): The type of analysis to be performed.
        user (str): The username or identifier of the user.

    Returns:
        dict: The response from the API after the upload request.
    """
    headers = {
        'accept': 'application/json',
    }
    files = {
        'file': (
            uploaded_file.name,
            uploaded_file,
            uploaded_file.type,
        ),
    }
    params = {
        'task_id': id,
        'type_of_analysis': type_of_analysis,
        'user': user
    }

    try:
        response_request = upload_endpoint(headers, files, params)
        return response_request
    except Exception as e:
        return {"error": f"File upload failed: {e}"}