当前使用 python Streamlit 设计界面和 Firebase 控制台来收集数据,在尝试将输入发送到 Firebase 控制台时出现“登录失败:push() 缺少 1 个必需的位置参数:'数据'”错误。
下面是我的代码片段。
def prediction_model():
global unique_id
# Load the Saved Model
loaded_model = pickle.load(open('C:/Use.....(directory...)', 'rb'))
# Create a Function for Prediction
def hypertensionRiskPrediction(inputData):
inputDataAsNumpyArray = np.asarray(inputData)
inputDataReshaped = inputDataAsNumpyArray.reshape(1, -1)
prediction = loaded_model.predict(inputDataReshaped)
if prediction[0] == 0:
return 'Good Health'
elif prediction[0] == 1:
return 'Mild Risk of Hypertension'
elif prediction[0] == 2:
return 'High Risk of Hypertension'
else:
return 'Error! Verify Input.'
def store_patient_data(unique_id, gender, age, systolic_bp, diastolic_bp, height, weight, bmi, diagnosis):
record_id = db.child("users").child(unique_id).child("medical_data").push().key # Generate a unique record ID
timestamp = datetime.datetime.now().isoformat()
medical_data = {
"gender": gender,
"age": age,
"systolic_bp": systolic_bp,
"diastolic_bp": diastolic_bp,
"height": height,
"weight": weight,
"bmi": bmi,
"diagnosis": diagnosis,
"timestamp": timestamp
}
db.child("users").child(unique_id).child("medical_data").child(record_id).set(medical_data)
gender = st.selectbox('Gender', ['Select', 'Male', 'Female'])
gender = 1 if gender == 'Male' else (0 if gender == 'Female' else 'Select')
age = st.number_input('Age', min_value=0, max_value=120, step=1)
systolic_bp = st.number_input('Systolic BP', min_value=0, max_value=300, step=1)
diastolic_bp = st.number_input('Diastolic BP', min_value=0, max_value=200, step=1)
height = st.number_input('Height (cm)', min_value=0.0, max_value=250.0, step=0.1)
weight = st.number_input('Weight (kg)', min_value=0.0, max_value=200.0, step=0.1)
# Calculate BMI
bmi = weight / (height/100)**2 if height > 0 else 0
st.write(f"Calculated BMI: {bmi:.2f}")
diagnosis = ''
if st.button('PREDICT'):
diagnosis = hypertensionRiskPrediction([gender, age, systolic_bp, diastolic_bp, bmi])
#store_patient_data(unique_id, gender, age, systolic_bp, diastolic_bp, bmi, diagnosis)
gender = 'Male' if gender == 1 else 'Female'
if diagnosis: # Display diagnosis only if it is not empty
st.success(diagnosis)
store_patient_data(unique_id, gender, age, systolic_bp, diastolic_bp, height, weight, bmi, diagnosis)
预期输入将发送到创建的数据库,但事实并非如此,我尝试修改和检查共享代码片段,但仍然无法修复它。
经过 12 天断断续续的尝试不同配方后才发现这一点。可以在评论里分享答案。