mohitrajdeo
commited on
Commit
Β·
40aa75e
1
Parent(s):
352e088
refactor(app.py): remove commented-out code and unused sections for cleaner codebase
Browse files- app.py +2 -226
- discarded.txt +228 -0
app.py
CHANGED
@@ -126,56 +126,6 @@ if selected == 'Home':
|
|
126 |
However, this tool has **not undergone clinical validation** and should be used **for informational and educational purposes only**. It is not intended to serve as a substitute for professional medical diagnosis or treatment. Always consult a qualified healthcare provider for medical advice.
|
127 |
""")
|
128 |
|
129 |
-
# st.markdown("""
|
130 |
-
# ## Welcome to the **Early Prediction of Health & Lifestyle Diseases**!
|
131 |
-
# This tool provides **early prediction and analysis** for various health conditions using **Machine Learning & NLP**.
|
132 |
-
|
133 |
-
# ### π₯ Available Features:
|
134 |
-
# - **π©Έ Disease Predictors**:
|
135 |
-
# - Diabetes Prediction
|
136 |
-
# - Hypertension Prediction
|
137 |
-
# - Cardiovascular Disease Prediction
|
138 |
-
# - Stroke Prediction
|
139 |
-
# - Asthma Prediction
|
140 |
-
# - Sleep Health Analysis
|
141 |
-
# # - **β
Checkbox-based Lifestyle Disease Predictor** using **BiomedNLP-PubMedBERT**
|
142 |
-
# - **π€ Medical Consultant** (Ask health-related questions)
|
143 |
-
# # - **π§ Mental Health Assessment**
|
144 |
-
# - **π Data Visualizer** (Analyze trends in health conditions)
|
145 |
-
|
146 |
-
# π Select an option from the sidebar to proceed!
|
147 |
-
# """)
|
148 |
-
|
149 |
-
# with st.expander("π Quick Start Guide"):
|
150 |
-
# st.write("""
|
151 |
-
# 1. Select a **health prediction model** from the sidebar.
|
152 |
-
# 2. Enter your details in the input fields.
|
153 |
-
# 3. Click **Predict** to get your result.
|
154 |
-
# 4. View personalized **health insights & recommendations**.
|
155 |
-
# """)
|
156 |
-
|
157 |
-
|
158 |
-
# # Disclaimer Section
|
159 |
-
# st.markdown("---")
|
160 |
-
# # st.markdown("""
|
161 |
-
# # **β οΈ Disclaimer:** This application has been developed using **real-world healthcare datasets** sourced from Kaggle:
|
162 |
-
|
163 |
-
# # - [Stroke Prediction Dataset](http://kaggle.com/code/chanchal24/stroke-prediction-using-python/input?select=healthcare-dataset-stroke-data.csv)
|
164 |
-
# # - [Asthma Analysis & Prediction](https://www.kaggle.com/code/bryamblasrimac/asthma-eda-prediction-f2score-85/input)
|
165 |
-
# # - [Diabetes Dataset](https://www.kaggle.com/datasets/mathchi/diabetes-data-set)
|
166 |
-
# # - [Cardiovascular Disease Dataset](https://www.kaggle.com/datasets/sulianova/cardiovascular-disease-dataset)
|
167 |
-
# # - [Sentiment Analysis for Mental Health](https://www.kaggle.com/datasets/suchintikasarkar/sentiment-analysis-for-mental-health)
|
168 |
-
# # - [Sleep Health Analysis](https://www.kaggle.com/datasets/uom190346a/sleep-health-and-lifestyle-dataset)
|
169 |
-
# # \
|
170 |
-
|
171 |
-
|
172 |
-
# st.markdown("""
|
173 |
-
# The predictions are generated using **machine learning models** trained on these datasets, incorporating **evaluation metrics and graphical insights** to enhance interpretability.
|
174 |
-
|
175 |
-
# However, this tool has **not undergone clinical validation** and should be used **for informational and educational purposes only**. It is not intended to serve as a substitute for professional medical diagnosis or treatment. Always consult a qualified healthcare provider for medical advice.
|
176 |
-
# """)
|
177 |
-
|
178 |
-
|
179 |
if selected == 'Diabetes Prediction':
|
180 |
st.title('π©Έ Diabetes Prediction using ML (SVC)')
|
181 |
st.image("https://cdn-icons-png.flaticon.com/512/2919/2919950.png", width=100)
|
@@ -492,182 +442,8 @@ if selected == 'Data Visualization':
|
|
492 |
st.pyplot(fig)
|
493 |
|
494 |
|
495 |
-
|
496 |
-
|
497 |
-
# st.markdown("### Discuss Your Health Concerns with Our AI-powered Chatbot")
|
498 |
-
# st.write("Ask about **Diabetes, Asthma, Stroke, Cardiovascular Disease, or Mental Health.**")
|
499 |
-
|
500 |
-
# genai.configure(api_key="AIzaSyAwyi9c5OdvLoWrv5lFi1jZDEYwuprQAKE")
|
501 |
-
|
502 |
-
# # Custom Styling
|
503 |
-
# st.markdown("""
|
504 |
-
# <style>
|
505 |
-
# .prompt-box {
|
506 |
-
# background-color: #000000;
|
507 |
-
# padding: 12px;
|
508 |
-
# border-radius: 8px;
|
509 |
-
# font-size: 14px;
|
510 |
-
# font-family: sans-serif;
|
511 |
-
# margin-bottom: 10px;
|
512 |
-
# border: 1px solid #dee2e6;
|
513 |
-
# text-align: center;
|
514 |
-
# }
|
515 |
-
# </style>
|
516 |
-
# """, unsafe_allow_html=True)
|
517 |
-
|
518 |
-
# st.markdown("#### π‘ Common Health Queries")
|
519 |
-
|
520 |
-
# prompt_options = [
|
521 |
-
# ("Diabetes β Diet", "What foods should I eat if I have diabetes?"),
|
522 |
-
# ("Diabetes β Exercise", "What type of workouts help control blood sugar levels?"),
|
523 |
-
# ("Asthma β Triggers", "What are common asthma triggers?"),
|
524 |
-
# ("Asthma β Treatment", "What are the best medications for asthma?"),
|
525 |
-
# ("Stroke β Symptoms", "What are the early warning signs of a stroke?"),
|
526 |
-
# ("Stroke β Prevention", "How can I reduce my risk of stroke?"),
|
527 |
-
# ("Cardiovascular β Heart Health", "How can I reduce my risk of heart disease?"),
|
528 |
-
# ("Cardiovascular β Blood Pressure", "What lifestyle changes can lower high blood pressure?"),
|
529 |
-
# ("Mental Health β Stress Management", "How can I manage stress effectively?"),
|
530 |
-
# ("Mental Health β Sleep Disorders", "What are the causes and treatments for sleep disorders?")
|
531 |
-
# ]
|
532 |
-
|
533 |
-
# # Display prompts in two columns (2 prompts per row)
|
534 |
-
# cols = st.columns(2)
|
535 |
-
# for i in range(0, len(prompt_options), 2):
|
536 |
-
# with cols[0]:
|
537 |
-
# if i < len(prompt_options):
|
538 |
-
# label, prompt = prompt_options[i]
|
539 |
-
# st.markdown(f"""<div class="prompt-box"><strong>{label}</strong><br>{prompt}</div>""", unsafe_allow_html=True)
|
540 |
-
|
541 |
-
# with cols[1]:
|
542 |
-
# if i+1 < len(prompt_options):
|
543 |
-
# label, prompt = prompt_options[i+1]
|
544 |
-
# st.markdown(f"""<div class="prompt-box"><strong>{label}</strong><br>{prompt}</div>""", unsafe_allow_html=True)
|
545 |
-
|
546 |
-
# # Initialize chat history if not present
|
547 |
-
# if "chat_history" not in st.session_state:
|
548 |
-
# st.session_state.chat_history = []
|
549 |
-
|
550 |
-
# # Display previous chat history
|
551 |
-
# for message in st.session_state.chat_history:
|
552 |
-
# with st.chat_message(message["role"]):
|
553 |
-
# st.markdown(message["content"])
|
554 |
-
|
555 |
-
# # User input field
|
556 |
-
# user_prompt = st.chat_input("Ask about Diabetes, Asthma, Stroke, Cardiovascular Disease, or Mental Health...")
|
557 |
-
|
558 |
-
# # List of allowed topics
|
559 |
-
# allowed_keywords = ["diabetes", "asthma", "stroke", "cardiovascular", "heart", "blood pressure",
|
560 |
-
# "mental health", "depression", "stress", "cholesterol", "sleep disorders"]
|
561 |
-
|
562 |
-
# if user_prompt:
|
563 |
-
# # Display user message
|
564 |
-
# st.chat_message("user").markdown(user_prompt)
|
565 |
-
# st.session_state.chat_history.append({"role": "user", "content": user_prompt})
|
566 |
-
|
567 |
-
# # Restriction: Only process if related to health topics
|
568 |
-
# if any(keyword in user_prompt.lower() for keyword in allowed_keywords):
|
569 |
-
# model = genai.GenerativeModel("gemini-2.0-flash")
|
570 |
-
# response = model.generate_content(user_prompt)
|
571 |
-
|
572 |
-
# if response and hasattr(response, "text"):
|
573 |
-
# assistant_response = response.text
|
574 |
-
# else:
|
575 |
-
# assistant_response = "I'm sorry, I couldn't generate a response."
|
576 |
-
|
577 |
-
# st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
|
578 |
-
|
579 |
-
# # Display assistant's response
|
580 |
-
# with st.chat_message("assistant"):
|
581 |
-
# st.markdown(assistant_response)
|
582 |
-
# else:
|
583 |
-
# # Restriction message
|
584 |
-
# restriction_msg = "**β οΈ This chatbot only responds to health-related topics.**\nPlease ask about Diabetes, Asthma, Stroke, Cardiovascular Disease, or Mental Health."
|
585 |
-
# st.session_state.chat_history.append({"role": "assistant", "content": restriction_msg})
|
586 |
-
|
587 |
-
# with st.chat_message("assistant"):
|
588 |
-
# st.markdown(restriction_msg)
|
589 |
-
|
590 |
-
|
591 |
-
# if selected == 'Checkbox-to-disease-predictor':
|
592 |
-
# # Load transformer model
|
593 |
-
# classifier = pipeline("zero-shot-classification", model="microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract")
|
594 |
-
# # Use a pipeline as a high-level helper
|
595 |
-
|
596 |
-
# # from transformers import pipeline
|
597 |
-
|
598 |
-
# # pipe = pipeline("fill-mask", model="microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract-fulltext")
|
599 |
-
|
600 |
-
|
601 |
-
# # Define symptoms for each disease
|
602 |
-
# diseases = {
|
603 |
-
# "Diabetes": ["Frequent urination", "Increased thirst", "Unexplained weight loss", "Fatigue", "Blurred vision"],
|
604 |
-
# "Hypertension": ["Headache", "Dizziness", "Chest pain", "Shortness of breath", "Nosebleeds"],
|
605 |
-
# "Obesity": ["Excess body fat", "Breathlessness", "Joint pain", "Increased sweating", "Low energy levels"],
|
606 |
-
# "Cardiovascular Disease": ["Chest pain", "Shortness of breath", "Dizziness", "Irregular heartbeat", "Fatigue"],
|
607 |
-
# "COPD": ["Chronic cough", "Shortness of breath", "Wheezing", "Chest tightness", "Frequent respiratory infections"],
|
608 |
-
# "Liver Disease": ["Jaundice", "Abdominal pain", "Swelling in legs", "Chronic fatigue", "Nausea"],
|
609 |
-
# "Kidney Disease": ["Swelling in legs", "Fatigue", "Loss of appetite", "Changes in urination", "Muscle cramps"],
|
610 |
-
# "Metabolic Syndrome": ["High blood sugar", "High blood pressure", "Increased waist size", "High cholesterol", "Fatigue"],
|
611 |
-
# "Osteoarthritis": ["Joint pain", "Stiffness", "Swelling", "Reduced flexibility", "Bone spurs"],
|
612 |
-
# "Gastroesophageal Reflux Disease": ["Heartburn", "Acid reflux", "Difficulty swallowing", "Chronic cough", "Sore throat"],
|
613 |
-
# "Depression": ["Persistent sadness", "Loss of interest", "Sleep disturbances", "Fatigue", "Difficulty concentrating"],
|
614 |
-
# "Sleep Apnea": ["Loud snoring", "Pauses in breathing", "Daytime drowsiness", "Morning headaches", "Irritability"],
|
615 |
-
# }
|
616 |
-
|
617 |
-
# # Streamlit UI
|
618 |
-
# st.title("π©Ί Hybrid Symptom Checker")
|
619 |
-
# st.write("Select your symptoms and get AI-powered predictions!")
|
620 |
-
|
621 |
-
# selected_symptoms = []
|
622 |
-
|
623 |
-
# # Create symptom selection with markdown separation and three columns
|
624 |
-
# disease_keys = list(diseases.keys())
|
625 |
-
|
626 |
-
# for i in range(0, len(disease_keys), 3):
|
627 |
-
# cols = st.columns(3)
|
628 |
-
# for j in range(3):
|
629 |
-
# if i + j < len(disease_keys):
|
630 |
-
# disease = disease_keys[i + j]
|
631 |
-
# with cols[j]:
|
632 |
-
# st.markdown(f"### {disease}")
|
633 |
-
# for symptom in diseases[disease]:
|
634 |
-
# if st.checkbox(symptom, key=f"{disease}_{symptom}"):
|
635 |
-
# selected_symptoms.append(symptom)
|
636 |
-
|
637 |
-
# if st.button("π Predict Disease"):
|
638 |
-
# if selected_symptoms:
|
639 |
-
# user_input = ", ".join(selected_symptoms) # Convert symptoms to text
|
640 |
-
|
641 |
-
# # 1οΈβ£ Custom Symptom Matching Approach
|
642 |
-
# disease_scores = {disease: 0 for disease in diseases.keys()}
|
643 |
-
# for disease, symptoms in diseases.items():
|
644 |
-
# matches = sum(symptom in selected_symptoms for symptom in symptoms)
|
645 |
-
# disease_scores[disease] = matches / len(symptoms) # Normalize by symptom count
|
646 |
-
|
647 |
-
# # Normalize to percentage
|
648 |
-
# symptom_match_scores = {d: round(score * 100, 2) for d, score in disease_scores.items()}
|
649 |
-
|
650 |
-
# # 2οΈβ£ AI Model Prediction
|
651 |
-
# ai_results = classifier(user_input, list(diseases.keys()))
|
652 |
-
# ai_scores = {ai_results["labels"][i]: round(ai_results["scores"][i] * 100, 2) for i in range(len(ai_results["labels"]))}
|
653 |
-
|
654 |
-
# # 3οΈβ£ Hybrid Score Calculation (Average of Both Scores)
|
655 |
-
# final_scores = {}
|
656 |
-
# for disease in diseases.keys():
|
657 |
-
# symptom_score = symptom_match_scores.get(disease, 0)
|
658 |
-
# ai_score = ai_scores.get(disease, 0)
|
659 |
-
# final_scores[disease] = round((symptom_score + ai_score) / 2, 2) # Averaging
|
660 |
-
|
661 |
-
# # Sort by final score
|
662 |
-
# sorted_final_scores = sorted(final_scores.items(), key=lambda x: x[1], reverse=True)
|
663 |
-
|
664 |
-
# # Display results
|
665 |
-
# st.write("### π¬ Possible Conditions (Hybrid Model Prediction):")
|
666 |
-
# for disease, score in sorted_final_scores:
|
667 |
-
# if score > 0:
|
668 |
-
# st.write(f"π©Ί {disease}: {score}% match")
|
669 |
-
# else:
|
670 |
-
# st.write("β οΈ Please select at least one symptom.")
|
671 |
|
672 |
|
673 |
import torch
|
|
|
126 |
However, this tool has **not undergone clinical validation** and should be used **for informational and educational purposes only**. It is not intended to serve as a substitute for professional medical diagnosis or treatment. Always consult a qualified healthcare provider for medical advice.
|
127 |
""")
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
if selected == 'Diabetes Prediction':
|
130 |
st.title('π©Έ Diabetes Prediction using ML (SVC)')
|
131 |
st.image("https://cdn-icons-png.flaticon.com/512/2919/2919950.png", width=100)
|
|
|
442 |
st.pyplot(fig)
|
443 |
|
444 |
|
445 |
+
|
446 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
|
448 |
|
449 |
import torch
|
discarded.txt
ADDED
@@ -0,0 +1,228 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# st.markdown("""
|
2 |
+
# ## Welcome to the **Early Prediction of Health & Lifestyle Diseases**!
|
3 |
+
# This tool provides **early prediction and analysis** for various health conditions using **Machine Learning & NLP**.
|
4 |
+
|
5 |
+
# ### π₯ Available Features:
|
6 |
+
# - **π©Έ Disease Predictors**:
|
7 |
+
# - Diabetes Prediction
|
8 |
+
# - Hypertension Prediction
|
9 |
+
# - Cardiovascular Disease Prediction
|
10 |
+
# - Stroke Prediction
|
11 |
+
# - Asthma Prediction
|
12 |
+
# - Sleep Health Analysis
|
13 |
+
# # - **β
Checkbox-based Lifestyle Disease Predictor** using **BiomedNLP-PubMedBERT**
|
14 |
+
# - **π€ Medical Consultant** (Ask health-related questions)
|
15 |
+
# # - **π§ Mental Health Assessment**
|
16 |
+
# - **π Data Visualizer** (Analyze trends in health conditions)
|
17 |
+
|
18 |
+
# π Select an option from the sidebar to proceed!
|
19 |
+
# """)
|
20 |
+
|
21 |
+
# with st.expander("π Quick Start Guide"):
|
22 |
+
# st.write("""
|
23 |
+
# 1. Select a **health prediction model** from the sidebar.
|
24 |
+
# 2. Enter your details in the input fields.
|
25 |
+
# 3. Click **Predict** to get your result.
|
26 |
+
# 4. View personalized **health insights & recommendations**.
|
27 |
+
# """)
|
28 |
+
|
29 |
+
|
30 |
+
# # Disclaimer Section
|
31 |
+
# st.markdown("---")
|
32 |
+
# # st.markdown("""
|
33 |
+
# # **β οΈ Disclaimer:** This application has been developed using **real-world healthcare datasets** sourced from Kaggle:
|
34 |
+
|
35 |
+
# # - [Stroke Prediction Dataset](http://kaggle.com/code/chanchal24/stroke-prediction-using-python/input?select=healthcare-dataset-stroke-data.csv)
|
36 |
+
# # - [Asthma Analysis & Prediction](https://www.kaggle.com/code/bryamblasrimac/asthma-eda-prediction-f2score-85/input)
|
37 |
+
# # - [Diabetes Dataset](https://www.kaggle.com/datasets/mathchi/diabetes-data-set)
|
38 |
+
# # - [Cardiovascular Disease Dataset](https://www.kaggle.com/datasets/sulianova/cardiovascular-disease-dataset)
|
39 |
+
# # - [Sentiment Analysis for Mental Health](https://www.kaggle.com/datasets/suchintikasarkar/sentiment-analysis-for-mental-health)
|
40 |
+
# # - [Sleep Health Analysis](https://www.kaggle.com/datasets/uom190346a/sleep-health-and-lifestyle-dataset)
|
41 |
+
# # \
|
42 |
+
|
43 |
+
|
44 |
+
# st.markdown("""
|
45 |
+
# The predictions are generated using **machine learning models** trained on these datasets, incorporating **evaluation metrics and graphical insights** to enhance interpretability.
|
46 |
+
|
47 |
+
# However, this tool has **not undergone clinical validation** and should be used **for informational and educational purposes only**. It is not intended to serve as a substitute for professional medical diagnosis or treatment. Always consult a qualified healthcare provider for medical advice.
|
48 |
+
# """)
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
# if selected == 'Medical Consultant':
|
53 |
+
# st.title("π©Ί Medical Consultant Chatbot")
|
54 |
+
# st.markdown("### Discuss Your Health Concerns with Our AI-powered Chatbot")
|
55 |
+
# st.write("Ask about **Diabetes, Asthma, Stroke, Cardiovascular Disease, or Mental Health.**")
|
56 |
+
|
57 |
+
# genai.configure(api_key="AIzaSyAwyi9c5OdvLoWrv5lFi1jZDEYwuprQAKE")
|
58 |
+
|
59 |
+
# # Custom Styling
|
60 |
+
# st.markdown("""
|
61 |
+
# <style>
|
62 |
+
# .prompt-box {
|
63 |
+
# background-color: #000000;
|
64 |
+
# padding: 12px;
|
65 |
+
# border-radius: 8px;
|
66 |
+
# font-size: 14px;
|
67 |
+
# font-family: sans-serif;
|
68 |
+
# margin-bottom: 10px;
|
69 |
+
# border: 1px solid #dee2e6;
|
70 |
+
# text-align: center;
|
71 |
+
# }
|
72 |
+
# </style>
|
73 |
+
# """, unsafe_allow_html=True)
|
74 |
+
|
75 |
+
# st.markdown("#### π‘ Common Health Queries")
|
76 |
+
|
77 |
+
# prompt_options = [
|
78 |
+
# ("Diabetes β Diet", "What foods should I eat if I have diabetes?"),
|
79 |
+
# ("Diabetes β Exercise", "What type of workouts help control blood sugar levels?"),
|
80 |
+
# ("Asthma β Triggers", "What are common asthma triggers?"),
|
81 |
+
# ("Asthma β Treatment", "What are the best medications for asthma?"),
|
82 |
+
# ("Stroke β Symptoms", "What are the early warning signs of a stroke?"),
|
83 |
+
# ("Stroke β Prevention", "How can I reduce my risk of stroke?"),
|
84 |
+
# ("Cardiovascular β Heart Health", "How can I reduce my risk of heart disease?"),
|
85 |
+
# ("Cardiovascular β Blood Pressure", "What lifestyle changes can lower high blood pressure?"),
|
86 |
+
# ("Mental Health β Stress Management", "How can I manage stress effectively?"),
|
87 |
+
# ("Mental Health β Sleep Disorders", "What are the causes and treatments for sleep disorders?")
|
88 |
+
# ]
|
89 |
+
|
90 |
+
# # Display prompts in two columns (2 prompts per row)
|
91 |
+
# cols = st.columns(2)
|
92 |
+
# for i in range(0, len(prompt_options), 2):
|
93 |
+
# with cols[0]:
|
94 |
+
# if i < len(prompt_options):
|
95 |
+
# label, prompt = prompt_options[i]
|
96 |
+
# st.markdown(f"""<div class="prompt-box"><strong>{label}</strong><br>{prompt}</div>""", unsafe_allow_html=True)
|
97 |
+
|
98 |
+
# with cols[1]:
|
99 |
+
# if i+1 < len(prompt_options):
|
100 |
+
# label, prompt = prompt_options[i+1]
|
101 |
+
# st.markdown(f"""<div class="prompt-box"><strong>{label}</strong><br>{prompt}</div>""", unsafe_allow_html=True)
|
102 |
+
|
103 |
+
# # Initialize chat history if not present
|
104 |
+
# if "chat_history" not in st.session_state:
|
105 |
+
# st.session_state.chat_history = []
|
106 |
+
|
107 |
+
# # Display previous chat history
|
108 |
+
# for message in st.session_state.chat_history:
|
109 |
+
# with st.chat_message(message["role"]):
|
110 |
+
# st.markdown(message["content"])
|
111 |
+
|
112 |
+
# # User input field
|
113 |
+
# user_prompt = st.chat_input("Ask about Diabetes, Asthma, Stroke, Cardiovascular Disease, or Mental Health...")
|
114 |
+
|
115 |
+
# # List of allowed topics
|
116 |
+
# allowed_keywords = ["diabetes", "asthma", "stroke", "cardiovascular", "heart", "blood pressure",
|
117 |
+
# "mental health", "depression", "stress", "cholesterol", "sleep disorders"]
|
118 |
+
|
119 |
+
# if user_prompt:
|
120 |
+
# # Display user message
|
121 |
+
# st.chat_message("user").markdown(user_prompt)
|
122 |
+
# st.session_state.chat_history.append({"role": "user", "content": user_prompt})
|
123 |
+
|
124 |
+
# # Restriction: Only process if related to health topics
|
125 |
+
# if any(keyword in user_prompt.lower() for keyword in allowed_keywords):
|
126 |
+
# model = genai.GenerativeModel("gemini-2.0-flash")
|
127 |
+
# response = model.generate_content(user_prompt)
|
128 |
+
|
129 |
+
# if response and hasattr(response, "text"):
|
130 |
+
# assistant_response = response.text
|
131 |
+
# else:
|
132 |
+
# assistant_response = "I'm sorry, I couldn't generate a response."
|
133 |
+
|
134 |
+
# st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
|
135 |
+
|
136 |
+
# # Display assistant's response
|
137 |
+
# with st.chat_message("assistant"):
|
138 |
+
# st.markdown(assistant_response)
|
139 |
+
# else:
|
140 |
+
# # Restriction message
|
141 |
+
# restriction_msg = "**β οΈ This chatbot only responds to health-related topics.**\nPlease ask about Diabetes, Asthma, Stroke, Cardiovascular Disease, or Mental Health."
|
142 |
+
# st.session_state.chat_history.append({"role": "assistant", "content": restriction_msg})
|
143 |
+
|
144 |
+
# with st.chat_message("assistant"):
|
145 |
+
# st.markdown(restriction_msg)
|
146 |
+
|
147 |
+
|
148 |
+
|
149 |
+
# if selected == 'Checkbox-to-disease-predictor':
|
150 |
+
# # Load transformer model
|
151 |
+
# classifier = pipeline("zero-shot-classification", model="microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract")
|
152 |
+
# # Use a pipeline as a high-level helper
|
153 |
+
|
154 |
+
# # from transformers import pipeline
|
155 |
+
|
156 |
+
# # pipe = pipeline("fill-mask", model="microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract-fulltext")
|
157 |
+
|
158 |
+
|
159 |
+
# # Define symptoms for each disease
|
160 |
+
# diseases = {
|
161 |
+
# "Diabetes": ["Frequent urination", "Increased thirst", "Unexplained weight loss", "Fatigue", "Blurred vision"],
|
162 |
+
# "Hypertension": ["Headache", "Dizziness", "Chest pain", "Shortness of breath", "Nosebleeds"],
|
163 |
+
# "Obesity": ["Excess body fat", "Breathlessness", "Joint pain", "Increased sweating", "Low energy levels"],
|
164 |
+
# "Cardiovascular Disease": ["Chest pain", "Shortness of breath", "Dizziness", "Irregular heartbeat", "Fatigue"],
|
165 |
+
# "COPD": ["Chronic cough", "Shortness of breath", "Wheezing", "Chest tightness", "Frequent respiratory infections"],
|
166 |
+
# "Liver Disease": ["Jaundice", "Abdominal pain", "Swelling in legs", "Chronic fatigue", "Nausea"],
|
167 |
+
# "Kidney Disease": ["Swelling in legs", "Fatigue", "Loss of appetite", "Changes in urination", "Muscle cramps"],
|
168 |
+
# "Metabolic Syndrome": ["High blood sugar", "High blood pressure", "Increased waist size", "High cholesterol", "Fatigue"],
|
169 |
+
# "Osteoarthritis": ["Joint pain", "Stiffness", "Swelling", "Reduced flexibility", "Bone spurs"],
|
170 |
+
# "Gastroesophageal Reflux Disease": ["Heartburn", "Acid reflux", "Difficulty swallowing", "Chronic cough", "Sore throat"],
|
171 |
+
# "Depression": ["Persistent sadness", "Loss of interest", "Sleep disturbances", "Fatigue", "Difficulty concentrating"],
|
172 |
+
# "Sleep Apnea": ["Loud snoring", "Pauses in breathing", "Daytime drowsiness", "Morning headaches", "Irritability"],
|
173 |
+
# }
|
174 |
+
|
175 |
+
# # Streamlit UI
|
176 |
+
# st.title("π©Ί Hybrid Symptom Checker")
|
177 |
+
# st.write("Select your symptoms and get AI-powered predictions!")
|
178 |
+
|
179 |
+
# selected_symptoms = []
|
180 |
+
|
181 |
+
# # Create symptom selection with markdown separation and three columns
|
182 |
+
# disease_keys = list(diseases.keys())
|
183 |
+
|
184 |
+
# for i in range(0, len(disease_keys), 3):
|
185 |
+
# cols = st.columns(3)
|
186 |
+
# for j in range(3):
|
187 |
+
# if i + j < len(disease_keys):
|
188 |
+
# disease = disease_keys[i + j]
|
189 |
+
# with cols[j]:
|
190 |
+
# st.markdown(f"### {disease}")
|
191 |
+
# for symptom in diseases[disease]:
|
192 |
+
# if st.checkbox(symptom, key=f"{disease}_{symptom}"):
|
193 |
+
# selected_symptoms.append(symptom)
|
194 |
+
|
195 |
+
# if st.button("π Predict Disease"):
|
196 |
+
# if selected_symptoms:
|
197 |
+
# user_input = ", ".join(selected_symptoms) # Convert symptoms to text
|
198 |
+
|
199 |
+
# # 1οΈβ£ Custom Symptom Matching Approach
|
200 |
+
# disease_scores = {disease: 0 for disease in diseases.keys()}
|
201 |
+
# for disease, symptoms in diseases.items():
|
202 |
+
# matches = sum(symptom in selected_symptoms for symptom in symptoms)
|
203 |
+
# disease_scores[disease] = matches / len(symptoms) # Normalize by symptom count
|
204 |
+
|
205 |
+
# # Normalize to percentage
|
206 |
+
# symptom_match_scores = {d: round(score * 100, 2) for d, score in disease_scores.items()}
|
207 |
+
|
208 |
+
# # 2οΈβ£ AI Model Prediction
|
209 |
+
# ai_results = classifier(user_input, list(diseases.keys()))
|
210 |
+
# ai_scores = {ai_results["labels"][i]: round(ai_results["scores"][i] * 100, 2) for i in range(len(ai_results["labels"]))}
|
211 |
+
|
212 |
+
# # 3οΈβ£ Hybrid Score Calculation (Average of Both Scores)
|
213 |
+
# final_scores = {}
|
214 |
+
# for disease in diseases.keys():
|
215 |
+
# symptom_score = symptom_match_scores.get(disease, 0)
|
216 |
+
# ai_score = ai_scores.get(disease, 0)
|
217 |
+
# final_scores[disease] = round((symptom_score + ai_score) / 2, 2) # Averaging
|
218 |
+
|
219 |
+
# # Sort by final score
|
220 |
+
# sorted_final_scores = sorted(final_scores.items(), key=lambda x: x[1], reverse=True)
|
221 |
+
|
222 |
+
# # Display results
|
223 |
+
# st.write("### π¬ Possible Conditions (Hybrid Model Prediction):")
|
224 |
+
# for disease, score in sorted_final_scores:
|
225 |
+
# if score > 0:
|
226 |
+
# st.write(f"π©Ί {disease}: {score}% match")
|
227 |
+
# else:
|
228 |
+
# st.write("β οΈ Please select at least one symptom.")
|