Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,16 +2,27 @@ import streamlit as st
|
|
2 |
import os
|
3 |
import numpy as np
|
4 |
import matplotlib.pyplot as plt
|
5 |
-
import torch
|
6 |
-
from datetime import datetime, timedelta
|
7 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Set Up Multi-Page Navigation
|
10 |
st.set_page_config(page_title="OncoPlan", page_icon="βοΈ", layout="wide")
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# Sidebar Navigation
|
13 |
st.sidebar.header("π Navigation")
|
14 |
-
page_options = ["π Home", "π Patient Info & Tumor Details", "π Progress Charts", "π€ AI Chatbot"]
|
15 |
|
16 |
if "current_page_index" not in st.session_state:
|
17 |
st.session_state.current_page_index = 0 # Track current page index
|
@@ -22,9 +33,10 @@ def set_page(index):
|
|
22 |
|
23 |
# Cancer Types & Regions
|
24 |
cancer_types = {
|
25 |
-
"Brain Tumors": ["Frontal Lobe", "Parietal Lobe", "Temporal Lobe", "Occipital Lobe", "Cerebellum"],
|
26 |
-
"Breast Cancer": ["Left Breast", "Right Breast", "Ductal Region", "Axillary Lymph Nodes"],
|
27 |
-
"Lung Cancer": ["Left Lung", "Right Lung", "Mediastinum", "Pleura"],
|
|
|
28 |
"Other": ["Custom"]
|
29 |
}
|
30 |
|
@@ -53,6 +65,7 @@ if page == "π Home":
|
|
53 |
|
54 |
### πΉ Features:
|
55 |
- π **Patient & Tumor Data Entry**
|
|
|
56 |
- π **Progress Visualization**
|
57 |
- π€ **AI Chatbot for Medical Guidance**
|
58 |
""")
|
@@ -69,14 +82,22 @@ elif page == "π Patient Info & Tumor Details":
|
|
69 |
st.write(f"### Patient: {st.session_state.get('name', 'Unknown')} ({st.session_state.get('age', 'N/A')} years old)")
|
70 |
|
71 |
# Cancer Type & Region
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
# Tumor Size
|
76 |
-
tumor_size = (
|
77 |
-
|
78 |
-
st.number_input("Tumor
|
79 |
-
st.number_input("Tumor
|
|
|
80 |
)
|
81 |
st.success("Tumor details saved!")
|
82 |
|
@@ -87,9 +108,11 @@ elif page == "π Progress Charts":
|
|
87 |
st.subheader("π Treatment Progress Chart")
|
88 |
treatment_sessions = list(range(1, 31))
|
89 |
total_dose = [i * 2 for i in treatment_sessions]
|
90 |
-
|
|
|
91 |
fig, ax = plt.subplots()
|
92 |
ax.plot(treatment_sessions, total_dose, label="Total Target Dose (Gy)", marker="o")
|
|
|
93 |
ax.set_xlabel("Session #")
|
94 |
ax.set_ylabel("Dose (Gy)")
|
95 |
ax.legend()
|
@@ -101,15 +124,10 @@ elif page == "π Progress Charts":
|
|
101 |
# AI Chatbot
|
102 |
elif page == "π€ AI Chatbot":
|
103 |
st.subheader("π¬ AI Chatbot")
|
104 |
-
|
105 |
-
# Use Hugging Face's OpenAI-compatible API for text generation
|
106 |
user_input = st.text_input("Ask your question:")
|
107 |
-
|
108 |
if user_input:
|
109 |
-
chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1", device="cpu")
|
110 |
response = chatbot(user_input, max_length=100)
|
111 |
st.write("π€ AI Response:", response[0]['generated_text'])
|
112 |
|
113 |
navigation_buttons()
|
114 |
-
|
115 |
-
|
|
|
2 |
import os
|
3 |
import numpy as np
|
4 |
import matplotlib.pyplot as plt
|
|
|
|
|
5 |
from transformers import pipeline
|
6 |
+
from datetime import datetime, timedelta
|
7 |
+
|
8 |
+
# Load API Key securely
|
9 |
+
GEMINI_API_KEY = st.secrets["Gemini_API_Key"] if "Gemini_API_Key" in st.secrets else os.getenv("Gemini_API_Key")
|
10 |
|
11 |
# Set Up Multi-Page Navigation
|
12 |
st.set_page_config(page_title="OncoPlan", page_icon="βοΈ", layout="wide")
|
13 |
|
14 |
+
# Aesthetic Title Section
|
15 |
+
st.markdown(
|
16 |
+
"""
|
17 |
+
# βοΈ OncoPlan
|
18 |
+
### "Where Science Meets Compassion β AI-Powered Personalized Radiotherapy Planning."
|
19 |
+
#### Beyond Technology, Towards a Healthier Tomorrow.
|
20 |
+
""", unsafe_allow_html=True
|
21 |
+
)
|
22 |
+
|
23 |
# Sidebar Navigation
|
24 |
st.sidebar.header("π Navigation")
|
25 |
+
page_options = ["π Home", "π Patient Info & Tumor Details", "π Treatment Plan", "π Progress Charts", "π€ AI Chatbot"]
|
26 |
|
27 |
if "current_page_index" not in st.session_state:
|
28 |
st.session_state.current_page_index = 0 # Track current page index
|
|
|
33 |
|
34 |
# Cancer Types & Regions
|
35 |
cancer_types = {
|
36 |
+
"Brain Tumors": ["Left Cerebral Hemisphere", "Right Cerebral Hemisphere", "Frontal Lobe", "Parietal Lobe", "Temporal Lobe", "Occipital Lobe", "Brainstem", "Cerebellum"],
|
37 |
+
"Breast Cancer": ["Left Breast", "Right Breast", "Ductal Region", "Lobular Region", "Axillary Lymph Nodes"],
|
38 |
+
"Lung Cancer": ["Left Lung - Upper Lobe", "Left Lung - Lower Lobe", "Right Lung - Upper Lobe", "Right Lung - Middle Lobe", "Right Lung - Lower Lobe", "Mediastinum", "Pleura"],
|
39 |
+
"Prostate Cancer": ["Peripheral Zone", "Transitional Zone", "Central Zone", "Seminal Vesicles", "Urethral Region"],
|
40 |
"Other": ["Custom"]
|
41 |
}
|
42 |
|
|
|
65 |
|
66 |
### πΉ Features:
|
67 |
- π **Patient & Tumor Data Entry**
|
68 |
+
- π **AI-Generated Treatment Plans**
|
69 |
- π **Progress Visualization**
|
70 |
- π€ **AI Chatbot for Medical Guidance**
|
71 |
""")
|
|
|
82 |
st.write(f"### Patient: {st.session_state.get('name', 'Unknown')} ({st.session_state.get('age', 'N/A')} years old)")
|
83 |
|
84 |
# Cancer Type & Region
|
85 |
+
cancer_type = st.session_state.get("cancer_type", "Brain Tumors")
|
86 |
+
cancer_region_options = cancer_types[cancer_type]
|
87 |
+
default_region = st.session_state.get("cancer_region", cancer_region_options[0])
|
88 |
+
|
89 |
+
if default_region not in cancer_region_options:
|
90 |
+
default_region = cancer_region_options[0]
|
91 |
+
|
92 |
+
st.session_state["cancer_type"] = st.selectbox("Cancer Type", list(cancer_types.keys()), index=list(cancer_types.keys()).index(cancer_type))
|
93 |
+
st.session_state["cancer_region"] = st.selectbox("Cancer Region", cancer_region_options, index=cancer_region_options.index(default_region))
|
94 |
|
95 |
# Tumor Size
|
96 |
+
tumor_size = st.session_state.get("tumor_size", (10, 10, 10))
|
97 |
+
st.session_state["tumor_size"] = (
|
98 |
+
st.number_input("Tumor Length (mm)", min_value=1, step=1, value=tumor_size[0]),
|
99 |
+
st.number_input("Tumor Width (mm)", min_value=1, step=1, value=tumor_size[1]),
|
100 |
+
st.number_input("Tumor Height (mm)", min_value=1, step=1, value=tumor_size[2])
|
101 |
)
|
102 |
st.success("Tumor details saved!")
|
103 |
|
|
|
108 |
st.subheader("π Treatment Progress Chart")
|
109 |
treatment_sessions = list(range(1, 31))
|
110 |
total_dose = [i * 2 for i in treatment_sessions]
|
111 |
+
skin_dose = [i * 1.5 for i in treatment_sessions]
|
112 |
+
|
113 |
fig, ax = plt.subplots()
|
114 |
ax.plot(treatment_sessions, total_dose, label="Total Target Dose (Gy)", marker="o")
|
115 |
+
ax.plot(treatment_sessions, skin_dose, label="Skin Dose (Gy)", marker="s", linestyle="--")
|
116 |
ax.set_xlabel("Session #")
|
117 |
ax.set_ylabel("Dose (Gy)")
|
118 |
ax.legend()
|
|
|
124 |
# AI Chatbot
|
125 |
elif page == "π€ AI Chatbot":
|
126 |
st.subheader("π¬ AI Chatbot")
|
127 |
+
chatbot = pipeline("text-generation", model="gpt2")
|
|
|
128 |
user_input = st.text_input("Ask your question:")
|
|
|
129 |
if user_input:
|
|
|
130 |
response = chatbot(user_input, max_length=100)
|
131 |
st.write("π€ AI Response:", response[0]['generated_text'])
|
132 |
|
133 |
navigation_buttons()
|
|
|
|