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2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
3 |
+
|
4 |
+
# Load models
|
5 |
+
models = {
|
6 |
+
"FAWMED": "FawadHaider2/FAWMED",
|
7 |
+
"WADMED": "FawadHaider2/WADMED",
|
8 |
+
"PastelMed": "harishussain12/PastelMed",
|
9 |
+
"LynxMed": "harishussain12/LynxMed"
|
10 |
+
}
|
11 |
+
|
12 |
+
# Disease-specific information
|
13 |
+
diseases_info = {
|
14 |
+
"Cancer": "Cancer is a broad term for a class of diseases characterized by uncontrolled cell growth. It can affect any part of the body and spread to other areas (metastasize). Common types include breast cancer, lung cancer, and colorectal cancer.",
|
15 |
+
"Alzheimer's Disease": "Alzheimer's Disease is a progressive neurodegenerative disorder that causes memory loss, confusion, and changes in behavior. It is the most common cause of dementia, affecting cognitive function and daily activities.",
|
16 |
+
"Parkinson's Disease": "Parkinson's Disease is a progressive neurological disorder that affects movement. It is caused by the death of dopamine-producing cells in the brain, leading to tremors, stiffness, and slow movement."
|
17 |
+
}
|
18 |
+
|
19 |
+
# Function to load selected model
|
20 |
+
def load_model(model_name):
|
21 |
+
tokenizer = AutoTokenizer.from_pretrained(models[model_name])
|
22 |
+
model = AutoModelForCausalLM.from_pretrained(models[model_name])
|
23 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
24 |
+
return pipe
|
25 |
+
|
26 |
+
# Function to generate information based on disease input
|
27 |
+
def generate_information(disease_info, model_name):
|
28 |
+
if not disease_info.strip():
|
29 |
+
return "Please enter disease information!"
|
30 |
+
|
31 |
+
# Load selected model
|
32 |
+
pipe = load_model(model_name)
|
33 |
+
|
34 |
+
# Generate information
|
35 |
+
result = pipe(disease_info, max_length=200, num_return_sequences=1)
|
36 |
+
return result[0]['generated_text']
|
37 |
+
|
38 |
+
# Function to update the disease input based on selected disease
|
39 |
+
def update_disease_info(disease_name):
|
40 |
+
return diseases_info.get(disease_name, "")
|
41 |
+
|
42 |
+
# Create Streamlit Interface with Sidebar
|
43 |
+
def create_interface():
|
44 |
+
# Custom CSS for background color, font, and modern design
|
45 |
+
st.markdown(
|
46 |
+
"""
|
47 |
+
<style>
|
48 |
+
body {
|
49 |
+
background: linear-gradient(135deg, #f2f2f2, #e0e0e0);
|
50 |
+
color: #333;
|
51 |
+
font-family: 'Inter', sans-serif;
|
52 |
+
}
|
53 |
+
|
54 |
+
.css-1d391kg {
|
55 |
+
background-color: #333;
|
56 |
+
color: white;
|
57 |
+
}
|
58 |
+
|
59 |
+
.stButton>button {
|
60 |
+
background-color: #4CAF50;
|
61 |
+
color: white;
|
62 |
+
font-size: 16px;
|
63 |
+
border-radius: 12px;
|
64 |
+
height: 3em;
|
65 |
+
width: 100%;
|
66 |
+
transition: all 0.3s ease;
|
67 |
+
border: none;
|
68 |
+
}
|
69 |
+
|
70 |
+
.stButton>button:hover {
|
71 |
+
background-color: #45a049;
|
72 |
+
cursor: pointer;
|
73 |
+
}
|
74 |
+
|
75 |
+
.stSelectbox>div {
|
76 |
+
background-color: #fff;
|
77 |
+
color: #333;
|
78 |
+
border-radius: 10px;
|
79 |
+
padding: 12px;
|
80 |
+
font-size: 14px;
|
81 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
82 |
+
}
|
83 |
+
|
84 |
+
.stTextArea>textarea {
|
85 |
+
background-color: #fff;
|
86 |
+
color: #333;
|
87 |
+
border-radius: 10px;
|
88 |
+
padding: 12px;
|
89 |
+
font-size: 14px;
|
90 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
91 |
+
}
|
92 |
+
|
93 |
+
.card {
|
94 |
+
background-color: white;
|
95 |
+
border-radius: 15px;
|
96 |
+
padding: 25px;
|
97 |
+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
|
98 |
+
margin: 20px;
|
99 |
+
}
|
100 |
+
|
101 |
+
.card:hover {
|
102 |
+
transform: scale(1.02);
|
103 |
+
transition: all 0.3s ease;
|
104 |
+
}
|
105 |
+
|
106 |
+
h1, h2, h3 {
|
107 |
+
font-family: 'Poppins', sans-serif;
|
108 |
+
color: #333;
|
109 |
+
}
|
110 |
+
|
111 |
+
.navbar {
|
112 |
+
background-color: white;
|
113 |
+
padding: 15px 0;
|
114 |
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
115 |
+
margin-bottom: 40px;
|
116 |
+
text-align: center;
|
117 |
+
}
|
118 |
+
|
119 |
+
.navbar a {
|
120 |
+
color: #333;
|
121 |
+
font-size: 20px;
|
122 |
+
text-decoration: none;
|
123 |
+
padding: 15px 25px;
|
124 |
+
margin: 0 20px;
|
125 |
+
border-radius: 5px;
|
126 |
+
}
|
127 |
+
|
128 |
+
.navbar a:hover {
|
129 |
+
background-color: #f4f4f4;
|
130 |
+
}
|
131 |
+
|
132 |
+
.disease_bar a {
|
133 |
+
padding: 10px 20px;
|
134 |
+
background-color: #f2f2f2;
|
135 |
+
border-radius: 10px;
|
136 |
+
margin: 5px;
|
137 |
+
text-decoration: none;
|
138 |
+
color: #333;
|
139 |
+
font-size: 16px;
|
140 |
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
141 |
+
}
|
142 |
+
|
143 |
+
.disease_bar a:hover {
|
144 |
+
background-color: #d6d6d6;
|
145 |
+
}
|
146 |
+
|
147 |
+
</style>
|
148 |
+
""", unsafe_allow_html=True
|
149 |
+
)
|
150 |
+
|
151 |
+
# Upper Navigation Bar
|
152 |
+
st.markdown('<div class="navbar">', unsafe_allow_html=True)
|
153 |
+
if st.button("Home", key="home_button"):
|
154 |
+
st.session_state.page = "Home"
|
155 |
+
if st.button("About", key="about_button"):
|
156 |
+
st.session_state.page = "About"
|
157 |
+
if st.button("Select Space", key="space_button"):
|
158 |
+
st.session_state.page = "Select Space"
|
159 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
160 |
+
|
161 |
+
# Initialize page state
|
162 |
+
if "page" not in st.session_state:
|
163 |
+
st.session_state.page = "Home"
|
164 |
+
|
165 |
+
# Layout for the main content
|
166 |
+
if st.session_state.page == "Home":
|
167 |
+
st.title("Medical GPT Application")
|
168 |
+
st.markdown("### Select a disease and provide related information.")
|
169 |
+
|
170 |
+
# Disease Selection bar (tabs style)
|
171 |
+
st.markdown('<div class="disease_bar">', unsafe_allow_html=True)
|
172 |
+
disease_selector = st.selectbox("Select Disease", options=list(diseases_info.keys()), index=0, key="disease_select")
|
173 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
174 |
+
|
175 |
+
# Update disease info
|
176 |
+
disease_input = st.text_area("Enter Disease Information", value=diseases_info[disease_selector], height=200)
|
177 |
+
|
178 |
+
# Card container for model selection
|
179 |
+
with st.container():
|
180 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
181 |
+
# Select model dropdown
|
182 |
+
model_selector = st.selectbox("Select Model", options=list(models.keys()), index=0)
|
183 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
184 |
+
|
185 |
+
st.markdown('<br>', unsafe_allow_html=True) # Space between components
|
186 |
+
|
187 |
+
# Button to generate information
|
188 |
+
generate_button = st.button("Generate Information")
|
189 |
+
|
190 |
+
if generate_button:
|
191 |
+
# Generate and display information based on the selected model
|
192 |
+
response = generate_information(disease_input, model_selector)
|
193 |
+
st.text_area("Generated Information", value=response, height=200, disabled=True)
|
194 |
+
|
195 |
+
elif st.session_state.page == "About":
|
196 |
+
st.title("About This Application")
|
197 |
+
st.markdown("""
|
198 |
+
This application uses custom GPT models to generate medical text. It helps to generate medical information based on user-provided disease descriptions.
|
199 |
+
|
200 |
+
### Features:
|
201 |
+
- **Model Selection**: Users can select from multiple medical models, each trained to provide different types of medical information.
|
202 |
+
- **Disease Information**: Predefined disease information is available to help users start with known symptoms or conditions like cancer, Alzheimer's, Parkinson's disease, etc.
|
203 |
+
- **Interactive**: The app generates custom responses from the selected model based on the user's inputs.
|
204 |
+
|
205 |
+
### Models available:
|
206 |
+
- **FAWMED**: A model by Fawad Haider for medical text generation.
|
207 |
+
- **WADMED**: Another medical text generation model by Fawad Haider.
|
208 |
+
- **PastelMed**: A model for general medical information generation.
|
209 |
+
- **LynxMed**: A concise model for generating summarized medical data.
|
210 |
+
|
211 |
+
### About the Creators:
|
212 |
+
This application was created by **SAMEER** and **FAWAD**, two AI enthusiasts who have developed this tool to assist users in generating accurate medical information using state-of-the-art machine learning models.
|
213 |
+
|
214 |
+
""")
|
215 |
+
|
216 |
+
elif st.session_state.page == "Select Space":
|
217 |
+
st.title("Explore Spaces")
|
218 |
+
|
219 |
+
st.markdown("""
|
220 |
+
### What are Spaces?
|
221 |
+
Spaces in this application refer to context-specific environments that help shape the responses based on certain medical perspectives or areas of expertise. Whether you need information from a general perspective or specialized fields like oncology or neurology, selecting a specific space allows the assistant to cater the response accordingly.MY SPACES INCLUDE CANCER, ALZHEIMER'S DIESEASE AND PARKINSONS'S DISEASE.
|
222 |
+
|
223 |
+
### Explore Spaces
|
224 |
+
Choose a specific disease or medical condition and explore responses tailored to your needs.
|
225 |
+
""")
|
226 |
+
|
227 |
+
# Dropdown to choose between different diseases
|
228 |
+
selected_space = st.selectbox("Select Space", options=list(diseases_info.keys()))
|
229 |
+
st.write(f"You selected: {selected_space}")
|
230 |
+
|
231 |
+
# Provide relevant information based on the selected space
|
232 |
+
st.text_area("Information", value=diseases_info[selected_space], height=200, disabled=True)
|
233 |
+
|
234 |
+
|
235 |
+
# Run the Streamlit interface
|
236 |
+
if __name__ == "__main__":
|
237 |
+
create_interface()
|