File size: 1,031 Bytes
e8248b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import os
import mimetypes

API_URL = "http://localhost:8000/api/initiate_pipeline"

def initiate_pipeline_call(files, pipeline_steps):
    """
    Initiate the pipeline with multiple files.
    
    Args:
        files: List of tuples containing file information (name, content, type)
        pipeline_steps: Integer representing selected pipeline steps
    """

    file_data = []
    
    for file in files:
        mime_type = mimetypes.guess_type(file.name)[0] or "application/octet-stream"
        
        # Ensure we send the actual file content
        with open(file.name, "rb") as f:
            file_data.append(("files", (file.name, f.read(), mime_type)))  

    try:
        response = requests.post(
            f"{API_URL}?pipeline_steps={pipeline_steps}", 
            files=file_data
        )
        
        response.raise_for_status()  # Raise exception for bad status codes
        return response.json()
    except requests.exceptions.RequestException as e:
        return f"Error: {str(e)}"