Spaces:
Sleeping
Sleeping
File size: 56,628 Bytes
a8b81f3 |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 |
import streamlit as st
import pandas as pd
import numpy as np
from pathlib import Path
import sys
import os
import time
from datetime import datetime
import plotly.express as px
# Add project root to Python path
project_root = Path(__file__).resolve().parent.parent
sys.path.append(str(project_root))
from src.model import BreastCancerModel
from src.models.diabetes import DiabetesModel
from src.models.heart_disease import HeartDiseaseModel
from src.models.parkinsons import ParkinsonsModel
from src.config import (
BREAST_CANCER_MODEL_PATH,
DIABETES_MODEL_PATH,
HEART_DISEASE_MODEL_PATH,
PARKINSONS_MODEL_PATH
)
# Set page config
st.set_page_config(
page_title="Medical Prediction System",
page_icon="π₯",
layout="wide",
initial_sidebar_state="expanded"
)
# Add this updated CSS at the beginning of the file
st.markdown("""
<style>
/* Original styling */
.success-message {
background-color: #28a745;
color: white;
padding: 10px;
border-radius: 5px;
margin: 10px 0;
}
.success-icon {
font-size: 20px;
margin-right: 10px;
}
.features-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1rem;
margin: 2rem 0;
}
.feature-card {
background: white;
padding: 1.5rem;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
text-align: center;
}
.feature-icon {
font-size: 2rem;
margin-bottom: 1rem;
}
.card {
background: white;
padding: 1rem;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
margin-bottom: 1rem;
}
.tool-section {
margin: 2rem 0;
}
</style>
""", unsafe_allow_html=True)
def check_model_exists(model_path):
"""Check if a model file exists"""
return os.path.exists(model_path)
def load_animation():
"""Show a loading animation"""
with st.spinner('Loading...'):
time.sleep(0.5)
def show_success_animation():
"""Show success animation"""
placeholder = st.empty()
for i in range(5):
placeholder.markdown(f"{'π―' * (i+1)}")
time.sleep(0.1)
placeholder.empty()
def add_home_button():
"""Add a Back to Home button"""
if st.button("π Back to Home"):
st.session_state.page = "Home"
def show_loading_page():
"""Show an animated loading screen"""
placeholder = st.empty()
with placeholder.container():
st.markdown("""
<div class="loading-container">
<h1>π₯ Medical AI Assistant</h1>
<div class="loading-spinner"></div>
<p>Loading advanced diagnostic tools...</p>
</div>
""", unsafe_allow_html=True)
time.sleep(1)
placeholder.empty()
def show_success_message(message):
"""Show animated success message"""
st.markdown(f"""
<div class="success-message">
<span class="success-icon">β</span>
{message}
</div>
""", unsafe_allow_html=True)
def show_feature_cards():
"""Show animated feature cards"""
st.markdown("""
<div class="features-grid">
<div class="feature-card">
<span class="feature-icon">π―</span>
<h3>High Accuracy</h3>
<p>Advanced ML algorithms with 96.5% accuracy</p>
</div>
<div class="feature-card">
<span class="feature-icon">β‘</span>
<h3>Real-time Analysis</h3>
<p>Get instant predictions and risk assessments</p>
</div>
<div class="feature-card">
<span class="feature-icon">π</span>
<h3>Secure Analysis</h3>
<p>Your data is processed securely and privately</p>
</div>
</div>
""", unsafe_allow_html=True)
def home_page():
show_loading_page()
# Hero section with gradient background
st.markdown("""
<div style="
padding: 2rem;
border-radius: 15px;
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
color: white;
margin-bottom: 2rem;
text-align: center;
animation: fadeIn 1s ease-out;
">
<h1 style="font-size: 3rem; margin-bottom: 1rem;">π₯ Medical AI Assistant</h1>
<p style="font-size: 1.2rem; opacity: 0.9;">
Advanced AI-powered diagnostics for healthcare professionals
</p>
</div>
""", unsafe_allow_html=True)
# Quick stats cards
st.markdown("""
<div style="
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
margin-bottom: 2rem;
">
<div style="
background: white;
padding: 1.5rem;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
text-align: center;
border-top: 4px solid #2ecc71;
">
<h3 style="color: #2ecc71; margin: 0;">96.5%</h3>
<p style="color: #666; margin: 0;">Accuracy Rate</p>
</div>
<div style="
background: white;
padding: 1.5rem;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
text-align: center;
border-top: 4px solid #3498db;
">
<h3 style="color: #3498db; margin: 0;">5,200+</h3>
<p style="color: #666; margin: 0;">Assessments</p>
</div>
<div style="
background: white;
padding: 1.5rem;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
text-align: center;
border-top: 4px solid #e74c3c;
">
<h3 style="color: #e74c3c; margin: 0;">0.5s</h3>
<p style="color: #666; margin: 0;">Response Time</p>
</div>
<div style="
background: white;
padding: 1.5rem;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
text-align: center;
border-top: 4px solid #9b59b6;
">
<h3 style="color: #9b59b6; margin: 0;">1,200+</h3>
<p style="color: #666; margin: 0;">Active Users</p>
</div>
</div>
""", unsafe_allow_html=True)
# Available tools section
st.markdown("""
<h2 style="
text-align: center;
margin: 2rem 0;
color: #2c3e50;
">Available Assessment Tools</h2>
""", unsafe_allow_html=True)
col1, col2 = st.columns(2)
with col1:
st.markdown("""
<div style="
background: white;
padding: 2rem;
border-radius: 15px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
margin-bottom: 1rem;
border-left: 5px solid #e74c3c;
">
<h3 style="color: #e74c3c;">π¬ Breast Cancer Assessment</h3>
<p style="color: #666;">Advanced cellular analysis using machine learning to assess cancer risk with high accuracy.</p>
</div>
""", unsafe_allow_html=True)
if st.button("Start Breast Cancer Assessment", key="breast"):
st.session_state.page = "Breast Cancer"
st.markdown("""
<div style="
background: white;
padding: 2rem;
border-radius: 15px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
margin-bottom: 1rem;
border-left: 5px solid #3498db;
">
<h3 style="color: #3498db;">β€οΈ Heart Disease Assessment</h3>
<p style="color: #666;">Comprehensive cardiovascular risk analysis using multiple health indicators.</p>
</div>
""", unsafe_allow_html=True)
if st.button("Start Heart Disease Assessment", key="heart"):
st.session_state.page = "Heart Disease"
with col2:
st.markdown("""
<div style="
background: white;
padding: 2rem;
border-radius: 15px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
margin-bottom: 1rem;
border-left: 5px solid #2ecc71;
">
<h3 style="color: #2ecc71;">π©Ί Diabetes Assessment</h3>
<p style="color: #666;">Predictive analysis of diabetes risk based on key health metrics and indicators.</p>
</div>
""", unsafe_allow_html=True)
if st.button("Start Diabetes Assessment", key="diabetes"):
st.session_state.page = "Diabetes"
st.markdown("""
<div style="
background: white;
padding: 2rem;
border-radius: 15px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
margin-bottom: 1rem;
border-left: 5px solid #9b59b6;
">
<h3 style="color: #9b59b6;">π§ Parkinson's Assessment</h3>
<p style="color: #666;">Advanced voice pattern analysis for early detection of Parkinson's disease.</p>
</div>
""", unsafe_allow_html=True)
if st.button("Start Parkinson's Assessment", key="parkinsons"):
st.session_state.page = "Parkinson's Disease"
# Technical Specifications Section
st.markdown("""
<h2 style="text-align: center; color: #2c3e50; margin: 2rem 0;">Technical Specifications</h2>
<div style="
background: white;
padding: 2rem;
border-radius: 15px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
margin: 2rem 0;
">
<div style="
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 2rem;
">
<div>
<h3 style="color: #3498db;">π¬ Data Sources</h3>
<ul style="color: #666; list-style-type: none; padding-left: 0;">
<li style="margin: 0.5rem 0;">β’ Breast Cancer Wisconsin Dataset</li>
<li style="margin: 0.5rem 0;">β’ Pima Indians Diabetes Database</li>
<li style="margin: 0.5rem 0;">β’ Heart Disease UCI Dataset</li>
<li style="margin: 0.5rem 0;">β’ Parkinson's Disease Dataset</li>
</ul>
</div>
<div>
<h3 style="color: #3498db;">βοΈ Technologies Used</h3>
<ul style="color: #666; list-style-type: none; padding-left: 0;">
<li style="margin: 0.5rem 0;">β’ Machine Learning: scikit-learn</li>
<li style="margin: 0.5rem 0;">β’ Web Interface: Streamlit</li>
<li style="margin: 0.5rem 0;">β’ Data Processing: pandas, numpy</li>
<li style="margin: 0.5rem 0;">β’ Version Control: Git</li>
</ul>
</div>
<div>
<h3 style="color: #3498db;">π Model Performance</h3>
<ul style="color: #666; list-style-type: none; padding-left: 0;">
<li style="margin: 0.5rem 0;">β’ Breast Cancer Detection: 96.5%</li>
<li style="margin: 0.5rem 0;">β’ Diabetes Prediction: 94.2%</li>
<li style="margin: 0.5rem 0;">β’ Heart Disease Assessment: 91.8%</li>
<li style="margin: 0.5rem 0;">β’ Parkinson's Detection: 93.5%</li>
</ul>
</div>
</div>
</div>
""", unsafe_allow_html=True)
# Features Section
st.markdown("""
<h2 style="text-align: center; color: #2c3e50; margin: 2rem 0;">Why Choose Our Platform?</h2>
<div style="
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1.5rem;
margin: 2rem 0;
">
<div style="
background: white;
padding: 2rem;
border-radius: 15px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
text-align: center;
">
<div style="font-size: 3rem; margin-bottom: 1rem;">π―</div>
<h3 style="color: #2c3e50;">High Accuracy</h3>
<p style="color: #666;">Advanced ML algorithms with 96.5% accuracy in predictions</p>
</div>
<div style="
background: white;
padding: 2rem;
border-radius: 15px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
text-align: center;
">
<div style="font-size: 3rem; margin-bottom: 1rem;">β‘</div>
<h3 style="color: #2c3e50;">Real-time Analysis</h3>
<p style="color: #666;">Get instant predictions and comprehensive risk assessments</p>
</div>
<div style="
background: white;
padding: 2rem;
border-radius: 15px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
text-align: center;
">
<div style="font-size: 3rem; margin-bottom: 1rem;">π</div>
<h3 style="color: #2c3e50;">Secure Analysis</h3>
<p style="color: #666;">Your data is processed securely and privately</p>
</div>
</div>
""", unsafe_allow_html=True)
# Research & Publications Section
st.markdown("## Research & Publications")
# Create three columns for the sections
col1, col2, col3 = st.columns(3)
with col1:
st.markdown("### π Recent Papers")
with st.container():
st.markdown("""
**Machine Learning in Medical Diagnosis** (2023)
*Impact on early disease detection and prevention*
""")
st.markdown("""
**AI Applications in Healthcare** (2022)
*Transforming patient care through technology*
""")
st.markdown("""
**Early Disease Detection Using ML** (2023)
*Predictive analytics in healthcare*
""")
with col2:
st.markdown("### π Methodology")
with st.container():
st.info("""
Our system employs advanced machine learning algorithms trained on extensive medical datasets,
ensuring reliable and accurate predictions for various medical conditions.
All models undergo rigorous testing and validation procedures, with continuous monitoring
and updates to maintain high accuracy levels.
""")
with col3:
st.markdown("### π― Future Developments")
# Future Development Cards
with st.container():
st.success("**Integration**\n\nElectronic health records integration for seamless data flow")
st.success("**Visualization**\n\nAdvanced visualization tools for better insight into predictions")
st.success("**Mobile Access**\n\nDevelopment of mobile applications for on-the-go access")
# Add some spacing
st.markdown("<br>", unsafe_allow_html=True)
# Footer Section
st.markdown("---") # Add a divider
# Header
st.header("Ready to get started?")
st.write("Choose any assessment tool above to begin your analysis")
# Create three columns for contact, resources, and legal
contact_col, resources_col, legal_col = st.columns(3)
with contact_col:
st.subheader("Contact")
st.markdown("""
π§ **Email:** [email protected]
π **Phone:** +1 (555) 123-4567
""")
with resources_col:
st.subheader("Resources")
st.markdown("""
π [Documentation](https://docs.medicalai.com)
π§ [API Reference](https://api.medicalai.com)
""")
with legal_col:
st.subheader("Legal")
st.markdown("""
π [Privacy Policy](https://privacy.medicalai.com)
βοΈ [Terms of Service](https://terms.medicalai.com)
""")
# Copyright and version info
st.markdown("---")
col1, col2 = st.columns(2)
with col1:
st.markdown("Β© 2024 Medical AI Assistant | Version 1.0.0")
with col2:
st.markdown("Developed with β€οΈ for healthcare professionals")
# Add new sections
st.markdown("## π Additional Features")
# Create tabs for different features
tab1, tab2, tab3 = st.tabs(["π History", "π Analysis", "π‘ Recommendations"])
with tab1:
show_patient_history()
export_report()
with tab2:
show_risk_factors_analysis()
show_trends_analysis()
with tab3:
show_recommendations()
compare_assessments()
def breast_cancer_prediction():
add_home_button()
show_loading_page()
st.markdown("""
<div class="page-header">
<h1>Breast Cancer Risk Assessment</h1>
<p class="subtitle">Advanced cellular analysis using machine learning</p>
</div>
""", unsafe_allow_html=True)
if not check_model_exists(BREAST_CANCER_MODEL_PATH):
st.error("β οΈ Breast Cancer model not found. Please train the model first.")
return
try:
model = BreastCancerModel.load_model()
except Exception as e:
st.error(f"β οΈ Error loading model: {str(e)}")
return
# Create tabs for input methods
tab1, tab2 = st.tabs(["π Standard Input", "π¬ Detailed Input"])
with tab1:
col1, col2 = st.columns(2)
with col1:
mean_radius = st.slider("Mean Radius", 6.0, 28.0, 14.0, help="Average size of cell nuclei")
mean_texture = st.slider("Mean Texture", 9.0, 40.0, 14.0, help="Average standard deviation of gray-scale values")
mean_perimeter = st.slider("Mean Perimeter", 40.0, 190.0, 90.0, help="Average size of the core tumor")
mean_area = st.slider("Mean Area", 140.0, 2500.0, 550.0, help="Average area of cell nuclei")
with col2:
mean_smoothness = st.slider("Mean Smoothness", 0.05, 0.16, 0.1, help="Average of local variation in radius lengths")
mean_compactness = st.slider("Mean Compactness", 0.02, 0.35, 0.1, help="Average of perimeter^2 / area - 1.0")
mean_concavity = st.slider("Mean Concavity", 0.0, 0.5, 0.1, help="Average severity of concave portions of the contour")
mean_concave_points = st.slider("Mean Concave Points", 0.0, 0.2, 0.1, help="Average number of concave portions of the contour")
with tab2:
st.markdown("### Detailed Measurements")
col1, col2, col3 = st.columns(3)
with col1:
radius_mean = st.number_input("Radius (mean)", 6.0, 28.0, 14.0, help="Mean of distances from center to points on the perimeter")
texture_mean = st.number_input("Texture (mean)", 9.0, 40.0, 14.0, help="Standard deviation of gray-scale values")
perimeter_mean = st.number_input("Perimeter (mean)", 40.0, 190.0, 90.0, help="Mean size of the core tumor")
area_mean = st.number_input("Area (mean)", 140.0, 2500.0, 550.0, help="Mean area of the tumor")
smoothness_mean = st.number_input("Smoothness (mean)", 0.05, 0.16, 0.1, help="Mean of local variation in radius lengths")
compactness_mean = st.number_input("Compactness (mean)", 0.02, 0.35, 0.1, help="Mean of perimeter^2 / area - 1.0")
concavity_mean = st.number_input("Concavity (mean)", 0.0, 0.5, 0.1, help="Mean of severity of concave portions")
concave_points_mean = st.number_input("Concave points (mean)", 0.0, 0.2, 0.1, help="Mean number of concave portions")
symmetry_mean = st.number_input("Symmetry (mean)", 0.1, 0.3, 0.2, help="Mean symmetry of the tumor")
fractal_dimension_mean = st.number_input("Fractal dimension (mean)", 0.05, 0.1, 0.06, help="Mean fractal dimension")
with col2:
radius_se = st.number_input("Radius (SE)", 0.1, 2.0, 0.4, help="Standard error of distances from center to points")
texture_se = st.number_input("Texture (SE)", 0.2, 4.0, 1.0, help="Standard error of gray-scale values")
perimeter_se = st.number_input("Perimeter (SE)", 1.0, 20.0, 5.0, help="Standard error of perimeter")
area_se = st.number_input("Area (SE)", 6.0, 540.0, 40.0, help="Standard error of area")
smoothness_se = st.number_input("Smoothness (SE)", 0.001, 0.03, 0.007, help="Standard error of smoothness")
compactness_se = st.number_input("Compactness (SE)", 0.002, 0.135, 0.025, help="Standard error of compactness")
concavity_se = st.number_input("Concavity (SE)", 0.0, 0.396, 0.03, help="Standard error of concavity")
concave_points_se = st.number_input("Concave points (SE)", 0.0, 0.05, 0.01, help="Standard error of concave points")
symmetry_se = st.number_input("Symmetry (SE)", 0.008, 0.079, 0.02, help="Standard error of symmetry")
fractal_dimension_se = st.number_input("Fractal dimension (SE)", 0.001, 0.029, 0.003, help="Standard error of fractal dimension")
with col3:
radius_worst = st.number_input("Radius (worst)", 7.0, 36.0, 16.0, help="Worst radius")
texture_worst = st.number_input("Texture (worst)", 12.0, 50.0, 21.0, help="Worst texture")
perimeter_worst = st.number_input("Perimeter (worst)", 50.0, 250.0, 107.0, help="Worst perimeter")
area_worst = st.number_input("Area (worst)", 185.0, 4250.0, 750.0, help="Worst area")
smoothness_worst = st.number_input("Smoothness (worst)", 0.07, 0.22, 0.13, help="Worst smoothness")
compactness_worst = st.number_input("Compactness (worst)", 0.03, 1.06, 0.25, help="Worst compactness")
concavity_worst = st.number_input("Concavity (worst)", 0.0, 1.25, 0.27, help="Worst concavity")
concave_points_worst = st.number_input("Concave points (worst)", 0.0, 0.29, 0.11, help="Worst concave points")
symmetry_worst = st.number_input("Symmetry (worst)", 0.15, 0.66, 0.29, help="Worst symmetry")
fractal_dimension_worst = st.number_input("Fractal dimension (worst)", 0.055, 0.207, 0.083, help="Worst fractal dimension")
# Add analyze button outside tabs to work for both
if st.button("Analyze Risk", help="Click to analyze breast cancer risk"):
with st.spinner('Analyzing samples...'):
try:
# Get input data based on active tab
if tab1._active:
input_data = np.array([
mean_radius, mean_texture, mean_perimeter, mean_area, mean_smoothness,
mean_compactness, mean_concavity, mean_concave_points, 0.2, 0.06,
0.4, 0.4, 2.0, 20.0, 0.01, 0.02, 0.02, 0.01, 0.02, 0.003,
16.0, 16.0, 100.0, 700.0, 0.12, 0.15, 0.15, 0.1, 0.25, 0.08
]).reshape(1, -1)
else:
input_data = np.array([
radius_mean, texture_mean, perimeter_mean, area_mean, smoothness_mean,
compactness_mean, concavity_mean, concave_points_mean, symmetry_mean, fractal_dimension_mean,
radius_se, texture_se, perimeter_se, area_se, smoothness_se,
compactness_se, concavity_se, concave_points_se, symmetry_se, fractal_dimension_se,
radius_worst, texture_worst, perimeter_worst, area_worst, smoothness_worst,
compactness_worst, concavity_worst, concave_points_worst, symmetry_worst, fractal_dimension_worst
]).reshape(1, -1)
prediction, similar_cases, similar_outcomes, distances = model.predict(input_data)
# Show prediction results
if prediction[0] == 0:
st.error("β οΈ High Risk of Breast Cancer")
st.warning(
"The analysis indicates characteristics commonly associated with malignant breast masses."
)
# Show risk factors based on active tab
st.subheader("Risk Factors Identified")
if tab1._active:
if mean_radius > 15:
st.warning(f"β’ Mean radius ({mean_radius:.2f}) is elevated")
if mean_concave_points > 0.05:
st.warning(f"β’ Mean concave points ({mean_concave_points:.3f}) are high")
else:
if radius_worst > 20:
st.warning(f"β’ Worst radius ({radius_worst:.2f}) is significantly elevated")
if concave_points_worst > 0.15:
st.warning(f"β’ Worst concave points ({concave_points_worst:.3f}) are very high")
else:
st.success("β
Low Risk of Breast Cancer")
st.info(
"The analysis indicates characteristics commonly associated with benign breast masses."
)
# Show similar cases
with st.expander("View Similar Cases"):
st.markdown("### Reference Cases")
st.markdown("These are similar cases from our database:")
similar_df = pd.DataFrame({
'Mean Radius': similar_cases['mean radius'].round(2),
'Mean Texture': similar_cases['mean texture'].round(2),
'Mean Area': similar_cases['mean area'].round(2),
'Diagnosis': ['Malignant' if o == 0 else 'Benign' for o in similar_outcomes],
'Similarity': [f"{(1 - d/d.max())*100:.1f}%" for d in distances]
})
st.dataframe(similar_df)
show_success_message("Analysis completed successfully!")
except Exception as e:
st.error(f"β οΈ Error during analysis: {str(e)}")
def diabetes_prediction():
# Add home button at the top
add_home_button()
load_animation()
st.header("Diabetes Prediction")
st.write("Enter measurements to predict diabetes risk")
try:
model = DiabetesModel.load_model()
except Exception as e:
st.error(f"Error loading model: {str(e)}")
return
col1, col2 = st.columns(2)
with col1:
pregnancies = st.number_input("Number of Pregnancies", value=0, min_value=0)
glucose = st.number_input("Glucose (mg/dL)", value=120, min_value=0)
blood_pressure = st.number_input("Blood Pressure (mm Hg)", value=70, min_value=0)
skin_thickness = st.number_input("Skin Thickness (mm)", value=20, min_value=0)
with col2:
insulin = st.number_input("Insulin (mu U/ml)", value=79, min_value=0)
bmi = st.number_input("BMI", value=25.0, min_value=0.0)
dpf = st.number_input("Diabetes Pedigree Function", value=0.5, min_value=0.0)
age = st.number_input("Age", value=33, min_value=0)
if st.button("Predict"):
try:
# Calculate derived features
glucose_bmi = glucose * bmi / 1000
glucose_age = glucose * age / 100
input_data = np.array([
pregnancies, glucose, blood_pressure, skin_thickness,
insulin, bmi, dpf, age, glucose_bmi, glucose_age
]).reshape(1, -1)
prediction, similar_cases, similar_outcomes, distances = model.predict(input_data)
# Show prediction with risk factors
if prediction[0] == 1:
st.error("High risk of diabetes")
if glucose > 140:
st.warning("β οΈ High glucose level detected")
if bmi > 30:
st.warning("β οΈ High BMI detected")
else:
st.success("Low risk of diabetes")
# Show similar cases
st.write("### Similar Cases from Dataset")
st.write("The prediction is based on these similar cases:")
similar_df = pd.DataFrame({
'Age': similar_cases['Age'].round(1),
'BMI': similar_cases['BMI'].round(1),
'Glucose': similar_cases['Glucose'].round(1),
'Blood Pressure': similar_cases['BloodPressure'].round(1),
'Outcome': ['Diabetic' if o == 1 else 'Non-diabetic' for o in similar_outcomes],
'Similarity': [f"{(1 - d/d.max())*100:.1f}%" for d in distances]
})
st.dataframe(similar_df)
# Show risk analysis
st.write("### Risk Analysis")
risk_factors = []
if glucose > 140: risk_factors.append(f"Glucose ({glucose} mg/dL) is above normal range")
if bmi > 30: risk_factors.append(f"BMI ({bmi:.1f}) indicates obesity")
if blood_pressure > 90: risk_factors.append(f"Blood pressure ({blood_pressure} mm Hg) is elevated")
if dpf > 0.8: risk_factors.append(f"Diabetes pedigree function ({dpf:.2f}) indicates family history")
if risk_factors:
st.write("Risk factors identified:")
for factor in risk_factors:
st.write(f"β’ {factor}")
else:
st.write("No major risk factors identified")
except Exception as e:
st.error(f"Error making prediction: {str(e)}")
def heart_disease_prediction():
# Add home button at the top
add_home_button()
load_animation()
st.header("Heart Disease Prediction")
st.write("Enter measurements to predict heart disease risk")
try:
model = HeartDiseaseModel.load_model()
except Exception as e:
st.error(f"Error loading model: {str(e)}")
return
col1, col2 = st.columns(2)
with col1:
age = st.number_input("Age", value=50, min_value=0)
sex = st.selectbox("Sex", ["Male", "Female"])
cp = st.selectbox("Chest Pain Type",
["Typical Angina", "Atypical Angina", "Non-anginal Pain", "Asymptomatic"])
trestbps = st.number_input("Resting Blood Pressure (mm Hg)", value=120, min_value=0)
chol = st.number_input("Serum Cholesterol (mg/dl)", value=200, min_value=0)
fbs = st.selectbox("Fasting Blood Sugar > 120 mg/dl", ["No", "Yes"])
restecg = st.selectbox("Resting ECG Results",
["Normal", "ST-T Wave Abnormality", "Left Ventricular Hypertrophy"])
with col2:
thalach = st.number_input("Maximum Heart Rate", value=150, min_value=0)
exang = st.selectbox("Exercise Induced Angina", ["No", "Yes"])
oldpeak = st.number_input("ST Depression by Exercise", value=0.0)
slope = st.selectbox("Slope of Peak Exercise ST", ["Upsloping", "Flat", "Downsloping"])
ca = st.number_input("Number of Major Vessels (0-3)", value=0, min_value=0, max_value=3)
thal = st.selectbox("Thalassemia", ["Normal", "Fixed Defect", "Reversible Defect"])
if st.button("Predict"):
try:
# Convert categorical inputs to numerical
sex_num = 1 if sex == "Male" else 0
cp_num = ["Typical Angina", "Atypical Angina", "Non-anginal Pain", "Asymptomatic"].index(cp)
fbs_num = 1 if fbs == "Yes" else 0
restecg_num = ["Normal", "ST-T Wave Abnormality", "Left Ventricular Hypertrophy"].index(restecg)
exang_num = 1 if exang == "Yes" else 0
slope_num = ["Upsloping", "Flat", "Downsloping"].index(slope)
thal_num = ["Normal", "Fixed Defect", "Reversible Defect"].index(thal) + 3
input_data = np.array([
age, sex_num, cp_num, trestbps, chol, fbs_num, restecg_num,
thalach, exang_num, oldpeak, slope_num, ca, thal_num
]).reshape(1, -1)
prediction, similar_cases, similar_outcomes, distances = model.predict(input_data)
# Show prediction and risk analysis
if prediction[0] == 1:
st.error("High risk of heart disease")
# Show specific risk factors
st.write("### Risk Factors Identified:")
risk_factors = []
if age > 60:
risk_factors.append(f"Age ({age} years) - Higher risk with increasing age")
if cp_num >= 2:
risk_factors.append("Chest Pain Type indicates potential issue")
if trestbps > 140:
risk_factors.append(f"High Blood Pressure ({trestbps} mm Hg)")
if chol > 240:
risk_factors.append(f"High Cholesterol ({chol} mg/dl)")
if thalach < 120:
risk_factors.append(f"Low Maximum Heart Rate ({thalach} bpm)")
if oldpeak > 2:
risk_factors.append(f"Significant ST Depression ({oldpeak})")
if ca > 0:
risk_factors.append(f"Number of Major Vessels: {ca}")
for factor in risk_factors:
st.warning(f"β οΈ {factor}")
else:
st.success("Low risk of heart disease")
# Show protective factors
good_factors = []
if age < 50:
good_factors.append(f"Age ({age} years) is in a lower risk category")
if trestbps < 120:
good_factors.append(f"Normal Blood Pressure ({trestbps} mm Hg)")
if chol < 200:
good_factors.append(f"Healthy Cholesterol Level ({chol} mg/dl)")
if good_factors:
st.write("### Protective Factors:")
for factor in good_factors:
st.info(f"β {factor}")
# Show similar cases
st.write("### Similar Cases from Dataset")
st.write("The prediction is based on these similar cases:")
similar_df = pd.DataFrame({
'Age': similar_cases['age'].round(0),
'Sex': ['Male' if s == 1 else 'Female' for s in similar_cases['sex']],
'Blood Pressure': similar_cases['trestbps'].round(0),
'Cholesterol': similar_cases['chol'].round(0),
'Max Heart Rate': similar_cases['thalach'].round(0),
'Outcome': ['High Risk' if o == 1 else 'Low Risk' for o in similar_outcomes],
'Similarity': [f"{(1 - d/d.max())*100:.1f}%" for d in distances]
})
st.dataframe(similar_df)
except Exception as e:
st.error(f"Error making prediction: {str(e)}")
def parkinsons_prediction():
# Add home button at the top
add_home_button()
load_animation()
st.header("Parkinsons Disease Prediction")
st.write("Enter the following measurements:")
if not check_model_exists(PARKINSONS_MODEL_PATH):
st.error("Parkinson's model not found. Please train the model first.")
if st.button("Train Parkinson's Model"):
try:
from train_models import train_parkinsons
train_parkinsons()
st.success("Model trained successfully! Please refresh the page.")
except Exception as e:
st.error(f"Error training model: {str(e)}")
return
try:
model = ParkinsonsModel.load_model()
except Exception as e:
st.error(f"Error loading model: {str(e)}")
return
col1, col2 = st.columns(2)
with col1:
mdvp_fo = st.number_input("MDVP:Fo(Hz)", min_value=88.333, max_value=260.105, value=120.000, format="%.6f")
mdvp_fhi = st.number_input("MDVP:Fhi(Hz)", min_value=102.145, max_value=592.030, value=157.000, format="%.6f")
mdvp_flo = st.number_input("MDVP:Flo(Hz)", min_value=65.476, max_value=239.170, value=75.000, format="%.6f")
mdvp_jitter = st.number_input("MDVP:Jitter(%)", min_value=0.00168, max_value=0.03316, value=0.00784, format="%.6f")
mdvp_jitter_abs = st.number_input("MDVP:Jitter(Abs)", min_value=0.000007, max_value=0.000260, value=0.000070, format="%.6f")
mdvp_rap = st.number_input("MDVP:RAP", min_value=0.00068, max_value=0.02144, value=0.00370, format="%.6f")
mdvp_ppq = st.number_input("MDVP:PPQ", min_value=0.00092, max_value=0.01958, value=0.00554, format="%.6f")
jitter_ddp = st.number_input("Jitter:DDP", min_value=0.00204, max_value=0.06433, value=0.01109, format="%.6f")
with col2:
mdvp_shimmer = st.number_input("MDVP:Shimmer", min_value=0.00954, max_value=0.11908, value=0.04374, format="%.6f")
mdvp_shimmer_db = st.number_input("MDVP:Shimmer(dB)", min_value=0.085, max_value=1.302, value=0.426, format="%.6f")
shimmer_apq3 = st.number_input("Shimmer:APQ3", min_value=0.00455, max_value=0.05647, value=0.02182, format="%.6f")
shimmer_apq5 = st.number_input("Shimmer:APQ5", min_value=0.0057, max_value=0.0794, value=0.03130, format="%.6f")
mdvp_apq = st.number_input("MDVP:APQ", min_value=0.00719, max_value=0.13778, value=0.02971, format="%.6f")
shimmer_dda = st.number_input("Shimmer:DDA", min_value=0.01364, max_value=0.16942, value=0.06545, format="%.6f")
nhr = st.number_input("NHR", min_value=0.00065, max_value=0.31482, value=0.02211, format="%.6f")
hnr = st.number_input("HNR", min_value=8.441, max_value=33.047, value=21.033, format="%.6f")
rpde = st.number_input("RPDE", min_value=0.256570, max_value=0.685151, value=0.414783, format="%.6f")
dfa = st.number_input("DFA", min_value=0.574282, max_value=0.825288, value=0.815285, format="%.6f")
spread1 = st.number_input("Spread1", min_value= -7.964984, max_value= -2.434031, value= -4.813031, format="%.6f")
spread2 = st.number_input("Spread2", min_value=0.006274, max_value=0.450493, value=0.266482, format="%.6f")
d2 = st.number_input("D2", min_value=1.423287, max_value=3.671155, value=2.301442, format="%.6f")
ppe = st.number_input("PPE", min_value=0.044539, max_value=0.527367, value=0.284654, format="%.6f")
if st.button("Predict"):
try:
input_data = np.array([
mdvp_fo, mdvp_fhi, mdvp_flo, 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
]).reshape(1, -1)
prediction, similar_cases, similar_outcomes, distances = model.predict(input_data)
if prediction[0] == 1:
st.error("β οΈ High risk of Parkinson's disease")
st.write("### Risk Factors Identified:")
risk_factors = []
if mdvp_jitter > 0.008:
risk_factors.append(f"High Jitter ({mdvp_jitter:.5f}%) indicates vocal instability")
if mdvp_jitter_abs > 0.0004:
risk_factors.append(f"High Absolute Jitter ({mdvp_jitter_abs:.5f}) indicates frequency instability")
if mdvp_shimmer > 0.04:
risk_factors.append(f"High Shimmer ({mdvp_shimmer:.5f}) indicates amplitude variations")
if mdvp_shimmer_db > 0.4:
risk_factors.append(f"High Shimmer dB ({mdvp_shimmer_db:.5f}dB) indicates amplitude instability")
if hnr < 20:
risk_factors.append(f"Low HNR ({hnr:.3f}) indicates voice quality issues")
if nhr > 0.03:
risk_factors.append(f"High NHR ({nhr:.5f}) indicates increased noise")
if rpde > 0.5:
risk_factors.append(f"High RPDE ({rpde:.3f}) indicates increased vocal complexity")
if dfa < 0.65:
risk_factors.append(f"Low DFA ({dfa:.3f}) indicates changes in vocal pattern")
for factor in risk_factors:
st.warning(f"β οΈ {factor}")
else:
st.success("β
Low risk of Parkinson's disease")
good_factors = []
if mdvp_jitter < 0.006:
good_factors.append(f"Normal Jitter ({mdvp_jitter:.5f}%)")
if mdvp_shimmer < 0.03:
good_factors.append(f"Normal Shimmer ({mdvp_shimmer:.5f})")
if hnr > 22:
good_factors.append(f"Good HNR ({hnr:.3f})")
if nhr < 0.02:
good_factors.append(f"Good NHR ({nhr:.5f})")
if good_factors:
st.write("### Protective Factors:")
for factor in good_factors:
st.info(f"β {factor}")
# Show similar cases
st.write("### Similar Cases from Dataset")
similar_df = pd.DataFrame({
'Jitter(%)': similar_cases['MDVP:Jitter(%)'].round(5),
'Shimmer': similar_cases['MDVP:Shimmer'].round(5),
'HNR': similar_cases['HNR'].round(2),
'RPDE': similar_cases['RPDE'].round(3),
'DFA': similar_cases['DFA'].round(3),
'Diagnosis': ['Parkinson\'s' if o == 1 else 'Healthy' for o in similar_outcomes],
'Similarity': [f"{(1 - d/d.max())*100:.1f}%" for d in distances]
})
st.dataframe(similar_df)
except Exception as e:
st.error(f"Error making prediction: {str(e)}")
def show_patient_history():
"""Display patient history visualization with interactive elements"""
st.markdown("### π Patient History Tracker")
# Add date range selector
col1, col2 = st.columns(2)
with col1:
start_date = st.date_input("From Date", value=datetime(2024, 1, 1))
with col2:
end_date = st.date_input("To Date", value=datetime.now())
# Add assessment type filter
assessment_types = ["All", "Breast Cancer", "Diabetes", "Heart Disease", "Parkinson's"]
selected_type = st.multiselect("Filter by Assessment Type", assessment_types, default=["All"])
# Mock data for demonstration - Fixed: Ensure all arrays have same length
num_records = 14 # Define a fixed number of records
history_data = {
'Date': pd.date_range(start='2024-01-01', periods=num_records, freq='W'),
'Risk Score': np.random.uniform(0.2, 0.8, size=num_records),
'Assessment Type': np.random.choice(assessment_types[1:], size=num_records),
'Status': np.random.choice(['Normal', 'Warning', 'Critical'], size=num_records),
'Doctor': np.random.choice(['Dr. Smith', 'Dr. Johnson', 'Dr. Williams'], size=num_records)
}
df = pd.DataFrame(history_data)
# Create tabs for different views
tab1, tab2 = st.tabs(["π Trend Analysis", "π Detailed Records"])
with tab1:
# Plot interactive trend
fig = px.line(df, x='Date', y='Risk Score', color='Assessment Type',
title='Risk Score Trends Over Time')
fig.update_layout(height=400)
st.plotly_chart(fig, use_container_width=True)
# Add summary metrics
col1, col2, col3 = st.columns(3)
with col1:
st.metric("Average Risk Score", f"{df['Risk Score'].mean():.2f}",
delta=f"{(df['Risk Score'].iloc[-1] - df['Risk Score'].iloc[0]):.2f}")
with col2:
st.metric("Assessments", len(df), delta="β2 from last month")
with col3:
st.metric("Critical Alerts", len(df[df['Status'] == 'Critical']),
delta="-1 from last month")
with tab2:
# Add search and filter options
search = st.text_input("Search records...")
filtered_df = df[df.astype(str).apply(lambda x: x.str.contains(search, case=False)).any(axis=1)]
# Display detailed records with styling
st.dataframe(
filtered_df.style.apply(lambda x: ['background-color: #ffcccc' if v == 'Critical'
else 'background-color: #ffffcc' if v == 'Warning'
else '' for v in x], subset=['Status'])
)
def export_report():
"""Generate and export comprehensive assessment report"""
st.markdown("### π Export Assessment Report")
# Report configuration
col1, col2 = st.columns(2)
with col1:
report_format = st.selectbox(
"Report Format",
["PDF", "CSV", "JSON", "Excel"]
)
include_graphs = st.checkbox("Include Visualizations", value=True)
with col2:
report_type = st.selectbox(
"Report Type",
["Summary", "Detailed", "Technical"]
)
include_recommendations = st.checkbox("Include Recommendations", value=True)
# Generate report
if st.button("Generate Report", type="primary"):
with st.spinner("Generating comprehensive report..."):
# Simulate report generation
progress_bar = st.progress(0)
for i in range(100):
time.sleep(0.01)
progress_bar.progress(i + 1)
# Show success message
st.success(f"Report generated successfully in {report_format} format!")
# Provide download option
if report_format == "PDF":
mime = "application/pdf"
elif report_format == "CSV":
mime = "text/csv"
elif report_format == "JSON":
mime = "application/json"
else:
mime = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
st.download_button(
label=f"π₯ Download {report_format} Report",
data=b"Sample report data", # Replace with actual report generation
file_name=f"medical_report_{datetime.now().strftime('%Y%m%d')}_{report_type.lower()}.{report_format.lower()}",
mime=mime,
key="download_report"
)
def show_risk_factors_analysis():
"""Display comprehensive risk factors analysis with interactive elements"""
st.markdown("### π Risk Factors Analysis")
# Create tabs for different analyses
tab1, tab2 = st.tabs(["π Risk Factor Impact", "π Correlation Analysis"])
with tab1:
# Mock data
risk_factors = {
'Factor': ['Age', 'BMI', 'Blood Pressure', 'Glucose Level', 'Family History',
'Smoking', 'Physical Activity', 'Diet', 'Stress Level'],
'Impact': [0.8, 0.6, 0.7, 0.9, 0.5, 0.65, 0.55, 0.45, 0.75],
'Category': ['Demographics', 'Physical', 'Physical', 'Medical', 'Medical',
'Lifestyle', 'Lifestyle', 'Lifestyle', 'Lifestyle']
}
df = pd.DataFrame(risk_factors)
# Add category filter
categories = ['All'] + list(df['Category'].unique())
selected_category = st.selectbox("Filter by Category", categories)
if selected_category != 'All':
df_filtered = df[df['Category'] == selected_category]
else:
df_filtered = df
# Create interactive bar chart
fig = px.bar(df_filtered, x='Factor', y='Impact', color='Category',
title='Risk Factors Impact Analysis',
labels={'Impact': 'Impact Score (0-1)'})
st.plotly_chart(fig, use_container_width=True)
with tab2:
# Create correlation matrix visualization
correlation_data = np.random.rand(len(df), len(df))
fig = px.imshow(correlation_data,
labels=dict(x="Risk Factors", y="Risk Factors"),
x=df['Factor'],
y=df['Factor'],
title="Risk Factors Correlation Matrix")
st.plotly_chart(fig, use_container_width=True)
def show_recommendations():
"""Display personalized health recommendations with interactive elements"""
st.markdown("### π‘ Personalized Recommendations")
# Add risk profile selector
risk_profile = st.select_slider(
"Risk Profile",
options=["Low", "Moderate", "High"],
value="Moderate"
)
# Recommendations based on risk profile
recommendations = {
"Lifestyle Changes": {
"Low": [
"Maintain regular exercise routine",
"Continue balanced diet",
"Regular sleep schedule"
],
"Moderate": [
"Increase exercise to 45 minutes daily",
"Reduce processed food intake",
"Improve sleep quality"
],
"High": [
"Structured exercise program with supervision",
"Strict dietary guidelines",
"Sleep monitoring and improvement"
]
},
"Medical Follow-up": {
"Low": [
"Annual check-ups",
"Regular blood pressure monitoring",
"Basic health screenings"
],
"Moderate": [
"Semi-annual check-ups",
"Monthly blood pressure monitoring",
"Comprehensive screenings"
],
"High": [
"Quarterly check-ups",
"Weekly blood pressure monitoring",
"Advanced health screenings"
]
},
"Risk Management": {
"Low": [
"Basic health monitoring",
"Stress management awareness",
"General health education"
],
"Moderate": [
"Regular health monitoring",
"Active stress management",
"Specific health education"
],
"High": [
"Intensive health monitoring",
"Professional stress management",
"Specialized health education"
]
}
}
# Display recommendations with expandable sections
for category, risk_levels in recommendations.items():
with st.expander(f"π {category}", expanded=True):
for item in risk_levels[risk_profile]:
st.markdown(f"β’ {item}")
# Add progress tracking
if st.checkbox(f"Track {category.lower()} progress", key=category):
st.slider(f"{category} Adherence", 0, 100, 50, key=f"adherence_{category}")
st.progress(50)
def show_trends_analysis():
"""Display comprehensive health trends analysis"""
st.markdown("### π Health Trends Analysis")
# Date range selector
col1, col2 = st.columns(2)
with col1:
start_date = st.date_input("Start Date", value=datetime(2024, 1, 1), key="trends_start")
with col2:
end_date = st.date_input("End Date", value=datetime.now(), key="trends_end")
# Mock data
dates = pd.date_range(start='2024-01-01', end='2024-04-01', freq='D')
trends_data = {
'Date': dates,
'Blood Pressure': np.random.normal(120, 5, len(dates)),
'Glucose Level': np.random.normal(100, 3, len(dates)),
'BMI': np.random.normal(25, 0.5, len(dates)),
'Cholesterol': np.random.normal(180, 10, len(dates)),
'Heart Rate': np.random.normal(75, 3, len(dates))
}
df = pd.DataFrame(trends_data)
# Metric selector
metrics = list(df.columns[1:])
selected_metrics = st.multiselect("Select metrics to analyze", metrics, default=[metrics[0]])
if selected_metrics:
# Create interactive line chart
fig = px.line(df, x='Date', y=selected_metrics,
title='Health Metrics Trends Over Time')
fig.update_layout(height=400)
st.plotly_chart(fig, use_container_width=True)
# Add statistical analysis
st.markdown("#### Statistical Analysis")
col1, col2, col3 = st.columns(3)
for metric in selected_metrics:
with col1:
st.metric(f"{metric} Average",
f"{df[metric].mean():.1f}",
delta=f"{df[metric].iloc[-1] - df[metric].iloc[0]:.1f}")
with col2:
st.metric(f"{metric} Min",
f"{df[metric].min():.1f}")
with col3:
st.metric(f"{metric} Max",
f"{df[metric].max():.1f}")
def compare_assessments():
"""Compare different assessment results"""
st.markdown("### π Compare Assessments")
col1, col2 = st.columns(2)
with col1:
st.markdown("#### Previous Assessment")
st.metric(label="Risk Score", value="75%", delta="-15%")
st.date_input("Assessment Date", value=datetime(2024, 1, 1))
with col2:
st.markdown("#### Current Assessment")
st.metric(label="Risk Score", value="60%", delta="-5%")
st.date_input("Assessment Date", value=datetime.now())
def main():
# Initialize session state if not exists
if "page" not in st.session_state:
st.session_state.page = "Home"
# Sidebar
with st.sidebar:
st.image("https://img.icons8.com/color/96/000000/hospital-2.png", width=100)
st.title("Medical AI Assistant")
st.caption("v1.0.0")
# Navigation
pages = {
"π Home": "Home",
"π¬ Breast Cancer": "Breast Cancer",
"π©Ί Diabetes": "Diabetes",
"β€οΈ Heart Disease": "Heart Disease",
"π§ Parkinson's Disease": "Parkinson's Disease"
}
# Get current page index
current_page = st.session_state.page
current_key = next(k for k, v in pages.items() if v == current_page)
# Navigation radio buttons
selected = st.radio(
"π§ Navigation",
list(pages.keys()),
index=list(pages.keys()).index(current_key)
)
# Update page when selection changes
if pages[selected] != st.session_state.page:
st.session_state.page = pages[selected]
# Main content routing
try:
if st.session_state.page == "Home":
home_page()
elif st.session_state.page == "Breast Cancer":
breast_cancer_prediction()
elif st.session_state.page == "Diabetes":
diabetes_prediction()
elif st.session_state.page == "Heart Disease":
heart_disease_prediction()
elif st.session_state.page == "Parkinson's Disease":
parkinsons_prediction()
except Exception as e:
st.error(f"Error loading page: {str(e)}")
st.session_state.page = "Home"
if __name__ == "__main__":
main() |