Spaces:
Sleeping
Sleeping
| # -*- coding: utf-8 -*- | |
| """app.py | |
| Automatically generated by Colab. | |
| Original file is located at | |
| https://colab.research.google.com/drive/1U0-duve9jKnGXp7YuMutUmUjIuadAj-C | |
| """ | |
| !pip install streamlit | |
| !pip install pyngrok | |
| import streamlit as st | |
| import numpy as np | |
| import pickle | |
| # --- Load models --- | |
| diabetes_model = pickle.load(open("diabetes_model.pkl", "rb")) | |
| heart_model = pickle.load(open("heart_model.pkl", "rb")) | |
| parkinsons_model = pickle.load(open("parkinsons_model.pkl", "rb")) | |
| # --- Set page config --- | |
| st.set_page_config(page_title="π©Ί Multi-Disease Predictor", layout="centered") | |
| # --- CSS for styling --- | |
| st.markdown(""" | |
| <style> | |
| body { | |
| background-color: #f0f8ff; | |
| } | |
| .main { | |
| background: linear-gradient(to right, #cbe8f7, #e0f7fa); | |
| padding: 2rem; | |
| border-radius: 20px; | |
| box-shadow: 0 0 15px rgba(0,0,0,0.1); | |
| font-family: 'Segoe UI', sans-serif; | |
| } | |
| h1, h3 { | |
| text-align: center; | |
| color: #0b5394; | |
| } | |
| .stButton > button { | |
| background-color: #007acc; | |
| color: white; | |
| font-weight: bold; | |
| padding: 10px 20px; | |
| border-radius: 8px; | |
| } | |
| .stNumberInput label { | |
| font-weight: 600; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # --- App header --- | |
| st.markdown("<div class='main'>", unsafe_allow_html=True) | |
| st.markdown("<h1>π Multi-Disease Prediction App</h1>", unsafe_allow_html=True) | |
| st.markdown("<p style='text-align:center;'>AI-Powered Health Screening for Diabetes, Heart, and Parkinson's</p>", unsafe_allow_html=True) | |
| # --- Disease selector --- | |
| disease = st.selectbox("π Select a disease to predict", ["Diabetes", "Heart Disease", "Parkinson's"]) | |
| # --- Inputs for each disease --- | |
| if disease == "Diabetes": | |
| st.subheader("π©Ί Diabetes Patient Details") | |
| pregnancies = st.number_input("Pregnancies", min_value=0) | |
| glucose = st.number_input("Glucose") | |
| bp = st.number_input("Blood Pressure") | |
| skin_thickness = st.number_input("Skin Thickness") | |
| insulin = st.number_input("Insulin") | |
| bmi = st.number_input("BMI") | |
| dpf = st.number_input("Diabetes Pedigree Function") | |
| age = st.number_input("Age", min_value=1) | |
| if st.button("π Predict Diabetes"): | |
| input_data = np.array([[pregnancies, glucose, bp, skin_thickness, insulin, bmi, dpf, age]]) | |
| prediction = diabetes_model.predict(input_data)[0] | |
| if prediction == 1: | |
| st.success("β οΈ Diabetic") | |
| else: | |
| st.success("β Not Diabetic") | |
| elif disease == "Heart Disease": | |
| st.subheader("β€οΈ Heart Patient Details") | |
| age = st.number_input("Age", min_value=1) | |
| sex = st.selectbox("Sex", [1, 0]) | |
| cp = st.number_input("Chest Pain Type") | |
| trestbps = st.number_input("Resting Blood Pressure") | |
| chol = st.number_input("Cholesterol") | |
| fbs = st.selectbox("Fasting Blood Sugar > 120", [1, 0]) | |
| restecg = st.number_input("Rest ECG") | |
| thalach = st.number_input("Max Heart Rate") | |
| exang = st.selectbox("Exercise Induced Angina", [1, 0]) | |
| oldpeak = st.number_input("Oldpeak") | |
| slope = st.number_input("ST Slope") | |
| ca = st.number_input("Major Vessels") | |
| thal = st.number_input("Thal") | |
| if st.button("π Predict Heart Disease"): | |
| input_data = np.array([[age, sex, cp, trestbps, chol, fbs, restecg, | |
| thalach, exang, oldpeak, slope, ca, thal]]) | |
| prediction = heart_model.predict(input_data)[0] | |
| if prediction == 1: | |
| st.error("β€οΈ Heart Disease Detected") | |
| else: | |
| st.success("π No Heart Disease") | |
| elif disease == "Parkinson's": | |
| st.subheader("π§ Parkinson's Patient Details") | |
| features = [ | |
| "MDVP:Fo(Hz)", "MDVP:Fhi(Hz)", "MDVP:Flo(Hz)", "MDVP:Jitter(%)", | |
| "MDVP:Jitter(Abs)", "MDVP:RAP", "MDVP:PPQ", "Jitter:DDP", | |
| "MDVP:Shimmer", "MDVP:Shimmer(dB)", "Shimmer:APQ3", | |
| "Shimmer:APQ5", "MDVP:APQ", "Shimmer:DDA", "NHR", | |
| "HNR", "RPDE", "DFA", "spread1", "spread2", "D2", "PPE" | |
| ] | |
| values = [st.number_input(f) for f in features] | |
| if st.button("π Predict Parkinson's"): | |
| input_data = np.array([values]) | |
| prediction = parkinsons_model.predict(input_data)[0] | |
| if prediction == 1: | |
| st.error("π§ Parkinson's Detected") | |
| else: | |
| st.success("π No Parkinson's") | |
| st.markdown("</div>", unsafe_allow_html=True) | |
| !pip install streamlit pyngrok | |
| from pyngrok import ngrok | |
| import os | |
| import threading | |
| # π Set your Ngrok AuthToken here | |
| ngrok.set_auth_token("2zDIrjnvLNcwDKvW0lZsNSyzfzH_2oNc7ao3DYMuoJx2CX5jy") # <-- REPLACE with your token | |
| # β Run streamlit app in background | |
| def run(): | |
| os.system("streamlit run app.py --server.headless true") | |
| threading.Thread(target=run).start() | |
| # β Use HTTP tunnel explicitly (new format) | |
| public_url = ngrok.connect(addr="http://localhost:8501") | |
| print("π Public URL:", public_url) | |