-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
67 lines (54 loc) · 2.56 KB
/
Copy pathapp.py
File metadata and controls
67 lines (54 loc) · 2.56 KB
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
import asyncio
import os
import streamlit as st
from dotenv import load_dotenv
from pipeline import CDSSPipeline
# Load environment variables
load_dotenv()
api_key = os.getenv("GROQ_API_KEY")
# Initialize pipeline only once per session
@st.cache_resource
def get_pipeline():
if not api_key:
st.error("GROQ_API_KEY not found in .env file. Please add it.")
st.stop()
return CDSSPipeline(groq_api_key=api_key)
st.set_page_config(page_title="PharmaRAG CDSS", page_icon="💊", layout="wide")
st.title("💊 Clinical Decision Support System (PharmaRAG)")
st.markdown("""
Enter a clinical scenario in natural language below. The system will extract the proposed medication,
current medications, and patient conditions, then check OpenFDA and RxNorm for interactions and side effects.
""")
pipeline = get_pipeline()
query = st.text_area("Doctor's Clinical Query:", height=150,
placeholder="e.g., I have a 68-year-old patient with atrial fibrillation currently on warfarin. I'm considering prescribing ibuprofen...")
if st.button("Generate Alert", type="primary"):
if not query.strip():
st.warning("Please enter a query.")
else:
with st.spinner("Analyzing query and retrieving medical facts..."):
try:
# Run the async pipeline
alert = asyncio.run(pipeline.run(query))
st.subheader("Results")
# Show summary and severity
col1, col2 = st.columns(2)
with col1:
st.info(f"**Query Summary:** {alert.query_summary}")
with col2:
severity_color = {
"HIGH": "red",
"MODERATE": "orange",
"LOW": "green",
"UNKNOWN": "gray"
}.get(alert.severity_flag.name, "gray")
st.markdown(f"**Severity Flag:** <span style='color:{severity_color}; font-weight:bold; font-size:1.2em;'>{alert.severity_flag.value}</span>", unsafe_allow_html=True)
st.markdown("---")
# Show the raw alert text
st.markdown("### Clinical Alert Synthesis")
st.markdown(alert.raw_alert_text)
st.markdown("---")
st.caption(alert.disclaimer)
st.caption(f"Sources Cited: {', '.join(alert.sources_cited)}")
except Exception as e:
st.error(f"An error occurred: {e}")