forked from bmwas/generativebrainapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_inference_example.py
More file actions
54 lines (47 loc) · 1.99 KB
/
Copy pathapi_inference_example.py
File metadata and controls
54 lines (47 loc) · 1.99 KB
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
"""
Brief script designed to interface with the Brain Generation API,
requiring essential parameters such as MRI ID, gender, age,
ventricular volume, and brain volume for processing.
Additionally, specifications for the destination S3 bucket and folder,
where NIFTI scans will be deposited, are required.
The script anticipates input in the form of a CSV file containing
the aforementioned data points. For reference, an exemplar CSV file
named "example_brain.csv" is included for guidance.
Benson Mwangi @2024
"""
import csv
import requests
# Function to make API request
def make_api_request(api_url,mriid, gender, age, ventricular_vol, brain_vol, bucket_name, bucket_folder):
payload = {
"mriid": mriid,
"gender": gender,
"age": age,
"ventricular_vol": ventricular_vol,
"brain_vol": brain_vol,
"bucket_name": bucket_name,
"bucket_folder": bucket_folder
}
response = requests.post(api_url, json=payload)
return response.json()
# Function to iterate over CSV and make API requests
def process_csv(filename,api_url):
with open(filename, 'r') as csvfile:
csvreader = csv.DictReader(csvfile)
for row in csvreader:
mriid = row['mriid']
gender = float(row['gender'])
age = float(row['age'])
ventricular_vol = float(row['ventricular_vol'])
brain_vol = float(row['brain_vol'])
bucket_name = row['bucket_name']
bucket_folder = row['bucket_folder']
# Make API request
api_response = make_api_request(api_url,mriid, gender, age, ventricular_vol, brain_vol, bucket_name, bucket_folder)
# Process API response
print(api_response) # You can customize this part to handle the API response as needed
# Example usage:
api_url = "YOUR_API_URL_HERE"
root_dir = "/home/xxxx"
csv_filename = "sample_inference_file.csv" # Provide the path to your CSV file
process_csv(root_dir+csv_filename)