Upload app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,7 @@ from langchain_community.chat_models import ChatOllama
|
|
| 11 |
from langchain_groq import ChatGroq
|
| 12 |
import logging
|
| 13 |
from analyzers import DrugInteractionAnalyzer
|
|
|
|
| 14 |
|
| 15 |
# Load environment variables
|
| 16 |
load_dotenv()
|
|
@@ -127,33 +128,111 @@ def create_agent_graph(owl_file_path: str) -> StateGraph:
|
|
| 127 |
return workflow.compile()
|
| 128 |
|
| 129 |
def main():
|
| 130 |
-
st.
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
|
| 140 |
-
if not os.path.exists(owl_file_path):
|
| 141 |
-
logging.error(f"Ontology file not found: {owl_file_path}")
|
| 142 |
-
st.error(f"Ontology file not found: {owl_file_path}")
|
| 143 |
-
return
|
| 144 |
|
| 145 |
-
|
| 146 |
-
with st.spinner("Analyzing drug interactions..."):
|
| 147 |
-
agent_graph = create_agent_graph(owl_file_path)
|
| 148 |
-
result = agent_graph.invoke(GraphState(input=user_input))
|
| 149 |
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
| 152 |
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
if __name__ == "__main__":
|
| 159 |
main()
|
|
|
|
| 11 |
from langchain_groq import ChatGroq
|
| 12 |
import logging
|
| 13 |
from analyzers import DrugInteractionAnalyzer
|
| 14 |
+
import base64
|
| 15 |
|
| 16 |
# Load environment variables
|
| 17 |
load_dotenv()
|
|
|
|
| 128 |
return workflow.compile()
|
| 129 |
|
| 130 |
def main():
|
| 131 |
+
st.set_page_config(page_title="OntoGraph", page_icon="💊", layout="wide")
|
| 132 |
|
| 133 |
+
st.markdown("<h1 style='text-align: center;'>OntoGraph - Drug Interaction Analysis System 🧬</h1>", unsafe_allow_html=True)
|
| 134 |
+
|
| 135 |
+
st.markdown("<p style='text-align: center; color: #c9f9fa;'>This application uses a combination of ontology-based reasoning and language models to analyze drug interactions.</p>", unsafe_allow_html=True)
|
| 136 |
+
st.markdown("<p style='text-align: center; color: #faffb7;'>Analyze potential interactions between different drugs</p>", unsafe_allow_html=True)
|
| 137 |
+
|
| 138 |
+
st.markdown("""
|
| 139 |
+
<style>
|
| 140 |
+
.centered {
|
| 141 |
+
display: flex;
|
| 142 |
+
flex-direction: column;
|
| 143 |
+
align-items: center;
|
| 144 |
+
justify-content: center;
|
| 145 |
+
text-align: center;
|
| 146 |
+
}
|
| 147 |
+
</style>
|
| 148 |
+
<div class="centered">
|
| 149 |
+
""", unsafe_allow_html=True)
|
| 150 |
+
|
| 151 |
+
def get_base64_image(img_path):
|
| 152 |
+
with open(img_path, "rb") as f:
|
| 153 |
+
encoded = base64.b64encode(f.read()).decode()
|
| 154 |
+
return f"data:image/webp;base64,{encoded}"
|
| 155 |
+
|
| 156 |
+
# Generate the image URL
|
| 157 |
+
image_url = get_base64_image("img/header-image.webp")
|
| 158 |
+
|
| 159 |
+
# Load custom CSS with the embedded image
|
| 160 |
+
st.markdown(f"""
|
| 161 |
+
<style>
|
| 162 |
+
.parallax {{
|
| 163 |
+
background-image: url("{image_url}");
|
| 164 |
+
min-height: 200px;
|
| 165 |
+
background-attachment: fixed;
|
| 166 |
+
background-position: center;
|
| 167 |
+
background-repeat: no-repeat;
|
| 168 |
+
background-size: cover;
|
| 169 |
+
}}
|
| 170 |
+
</style>
|
| 171 |
+
""", unsafe_allow_html=True)
|
| 172 |
+
|
| 173 |
+
st.markdown('<div class="parallax"></div>', unsafe_allow_html=True)
|
| 174 |
+
|
| 175 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 176 |
|
| 177 |
+
col1, col2, col3 = st.columns([3, 1, 7])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
+
with col3:
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
+
st.markdown("<h2 style='text-align: left; color: #d46c6c;'>Instructions</h2>", unsafe_allow_html=True)
|
| 182 |
+
st.markdown("<p style='text-align: left; color: white;'>1. Enter the drug names separated by commas. <br> 2. Click on the 'Analyze' button. <br> 3. Wait for the analysis to complete. <br> 4. View the results below.</p>", unsafe_allow_html=True)
|
| 183 |
+
st.markdown("<div class='divider'></div>", unsafe_allow_html=True)
|
| 184 |
+
st.markdown("<hr>", unsafe_allow_html=True)
|
| 185 |
|
| 186 |
+
st.markdown('<h3 class="big-font">Enter drug names separated by commas (e.g., Aspirin, Warfarin):</h3>', unsafe_allow_html=True)
|
| 187 |
+
user_input = st.text_input("", value="", key="drug_input")
|
| 188 |
+
st.markdown('<style>div[data-testid="stTextInput"] input { font-size: 16px;}</style>', unsafe_allow_html=True)
|
| 189 |
+
|
| 190 |
+
if st.button("Analyze"):
|
| 191 |
+
if not user_input.strip():
|
| 192 |
+
st.warning("Please enter at least one drug name.")
|
| 193 |
+
return
|
| 194 |
+
|
| 195 |
+
owl_file_path = os.path.join("ontology", "DrugInteraction.owl")
|
| 196 |
+
if not os.path.exists(owl_file_path):
|
| 197 |
+
logging.error(f"Ontology file not found: {owl_file_path}")
|
| 198 |
+
st.error(f"Ontology file not found: {owl_file_path}")
|
| 199 |
+
return
|
| 200 |
+
|
| 201 |
+
try:
|
| 202 |
+
with st.spinner("Analyzing drug interactions..."):
|
| 203 |
+
agent_graph = create_agent_graph(owl_file_path)
|
| 204 |
+
result = agent_graph.invoke(GraphState(input=user_input))
|
| 205 |
+
|
| 206 |
+
st.subheader("Analysis Results:")
|
| 207 |
+
st.markdown(result["response"])
|
| 208 |
+
|
| 209 |
+
logging.info("Analysis completed and results displayed.")
|
| 210 |
+
except Exception as e:
|
| 211 |
+
logging.error(f"An error occurred: {str(e)}")
|
| 212 |
+
st.error(f"An error occurred: {str(e)}")
|
| 213 |
+
|
| 214 |
+
with col1:
|
| 215 |
+
st.markdown("<h4 style='text-align: center; color: #5ac5c9;'>Comprehensive Drug Analysis</h4>", unsafe_allow_html=True)
|
| 216 |
+
# st.markdown("<img src='https://cdn.dribbble.com/users/228367/screenshots/4603754/chemistryset_dribbble.gif' alt='reaction' width='100%'/>", unsafe_allow_html=True)
|
| 217 |
+
st.markdown("<div class='divider'></div>", unsafe_allow_html=True)
|
| 218 |
+
image_base64 = get_base64_image("img/reaction.gif")
|
| 219 |
+
st.markdown(f"<img src='{image_base64}' width='100%'/>", unsafe_allow_html=True)
|
| 220 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 221 |
+
st.write("""
|
| 222 |
+
- Drug interaction detection
|
| 223 |
+
- Conflict identification
|
| 224 |
+
- Similar drug suggestions
|
| 225 |
+
- Alternative medication recommendations
|
| 226 |
+
""")
|
| 227 |
+
|
| 228 |
|
| 229 |
+
st.markdown("<hr>", unsafe_allow_html=True)
|
| 230 |
+
st.markdown("<p style='text-align: center; color: #faffb7;'></p>", unsafe_allow_html=True)
|
| 231 |
+
st.write("""
|
| 232 |
+
<div style='text-align: center;'>
|
| 233 |
+
<p style='text-align: left; color: #d46c6c;'>Disclaimer: </p><p style='text-align: left; color: #707377;'>This application is intended for informational purposes only and does not replace professional medical advice, diagnosis, or treatment. The analysis provided is based on the data available in the ontology and may not account for all possible drug interactions. Users are strongly advised to consult a licensed healthcare provider before making any decisions based on the analysis results. The creators of this application are not responsible for any decisions made or actions taken based on the information provided.</p>
|
| 234 |
+
</div>
|
| 235 |
+
""", unsafe_allow_html=True)
|
| 236 |
+
|
| 237 |
if __name__ == "__main__":
|
| 238 |
main()
|