Download app.py from Sarah0022/pppp: direct link, hf CLI and curl.
- Browser
- Download file 2.34 kB
-
https://huggingface.co/spaces/Sarah0022/pppp/resolve/main/app.py
- Command line
-
hf download hf://spaces/Sarah0022/pppp/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Sarah0022/pppp/resolve/main/app.py
2.34 kB
| import numpy as np | |
| import streamlit as st | |
| import pickle | |
| # تحميل النموذج | |
| model = pickle.load(open("heart_disease_model.pkl", "rb")) | |
| # واجهة المستخدم | |
| st.title("Heart Disease Prediction App") | |
| age = st.number_input("Enter Age", min_value=0, max_value=120) | |
| sex = st.selectbox("Select Gender", options=["Male", "Female"]) | |
| chest_pain = st.selectbox("Chest Pain Type", options=[1, 2, 3, 4]) | |
| blood_pressure = st.number_input("Enter Blood Pressure", min_value=0) | |
| cholesterol = st.number_input("Enter Cholesterol Level", min_value=0) | |
| blood_sugar = st.selectbox("Blood Sugar > 120 mg/dl?", options=[0, 1]) | |
| electrocardiographic_result = st.selectbox("Electrocardiographic Result", options=[0, 1, 2]) | |
| max_heart_rate = st.number_input("Enter Maximum Heart Rate", min_value=0) | |
| exercise_angina = st.selectbox("Exercise Induced Angina", options=[0, 1]) | |
| oldpeak = st.number_input("Enter Oldpeak", min_value=0.0, max_value=6.0) | |
| slope = st.selectbox("Slope of the Peak Exercise ST Segment", options=[1, 2, 3]) | |
| ca = st.selectbox("Number of Major Vessels Colored by Fluoroscopy", options=[0, 1, 2, 3]) | |
| thalassemia = st.selectbox("Thalassemia", options=[3, 6, 7]) | |
| # عند الضغط على الزر، يتم التنبؤ | |
| if st.button("Predict"): | |
| # تحويل المدخلات للمصفوفة المناسبة للتنبؤ | |
| input_data = [ | |
| age, | |
| 1 if sex == "Male" else 0, # تحويل الجنس إلى رقم (ذكر = 1، أنثى = 0) | |
| chest_pain, | |
| blood_pressure, | |
| cholesterol, | |
| blood_sugar, | |
| electrocardiographic_result, | |
| max_heart_rate, | |
| exercise_angina, | |
| oldpeak, | |
| slope, | |
| ca, | |
| thalassemia | |
| ] | |
| # تحويل البيانات إلى مصفوفة numpy | |
| input_data_as_numpy_array = np.asarray(input_data) | |
| # إعادة تشكيل البيانات لتناسب التنبؤ (1 صف و 13 عمود) | |
| input_data_reshape = input_data_as_numpy_array.reshape(1, -1) | |
| # التنبؤ باستخدام النموذج | |
| prediction = model.predict(input_data_reshape) | |
| # عرض النتيجة | |
| prediction_text = "Heart Disease Detected" if prediction[0] == 1 else "No Heart Disease Detected" | |
| st.write(f"Prediction: {prediction_text}") | |