import requests
import pandas as pd
from sklearn.metrics import f1_score
from utils import Preprocess
import numpy as np
df = pd.read_excel('dataset.xlsx',engine='openpyxl')
df.drop(['Unnamed: 0', 'visit id'], axis=1, inplace=True)
# df = df[:1000]
json_data = df.to_json(orient='records')
# Send POST request with JSON data
url = "http://127.0.0.1:8000/predict/"
response = requests.post(url, json=json_data)
# Print the response (predictions)
response = response.json()
predictions = response['predictions']
pre = Preprocess(df, 0, 0, 0)
df = pre._mapping(df)
y_pre = np.array(predictions)
y_true = df['target label / yes no'].fillna(0)
y_true = y_true.values.astype(int)
np.unique(y_true,return_counts=True)
f1 = f1_score(y_true, y_pre,average='weighted')
print(f1)