#credits: https://github.com/plaban1981/Medical-Agent-from-Scratch
import streamlit as st
import asyncio
from core.agent_manager import AgentManager
# Set page configuration with custom theme
st.set_page_config(
page_title="Medical AI Agents",
layout="wide",
initial_sidebar_state="expanded"
)
# Custom CSS for styling
st.markdown("""
""", unsafe_allow_html=True)
@st.cache_resource
def get_agent_manager():
return AgentManager()
def show_results_page(result_data):
st.markdown("
", unsafe_allow_html=True)
if "summary" in result_data["result"]:
st.write(result_data["result"]["summary"])
elif "article" in result_data["result"]:
st.write(result_data["result"]["article"])
elif "sanitized_data" in result_data["result"]:
st.write(result_data["result"]["sanitized_data"])
st.markdown("
", unsafe_allow_html=True)
# Action buttons in columns
col1, col2, col3 = st.columns([1, 1, 1])
with col2:
# Export button
if st.button("📥 Export Results"):
export_data = ""
if "summary" in result_data["result"]:
export_data = result_data["result"]["summary"]
elif "article" in result_data["result"]:
export_data = result_data["result"]["article"]
elif "sanitized_data" in result_data["result"]:
export_data = result_data["result"]["sanitized_data"]
st.download_button(
label="💾 Download Content",
data=export_data,
file_name="final_content.txt",
mime="text/plain"
)
with col3:
# Return button
if st.button("🏠 Return to Main Page"):
st.session_state.show_results = False
st.rerun()
def main():
# Sidebar styling
with st.sidebar:
st.markdown("", unsafe_allow_html=True)
if task_type == "summarize":
st.markdown("", unsafe_allow_html=True)
input_text = st.text_area("Enter medical text to summarize", height=200)
col1, col2 = st.columns(2)
with col1:
if st.button("🔄 Generate Summary"):
with st.spinner("Processing..."):
result = asyncio.run(agent_manager.process_task("summarize", input_text))
st.session_state.result_data = result
st.markdown("
", unsafe_allow_html=True)
st.subheader("Summary")
st.write(result["result"]["summary"])
st.markdown("
", unsafe_allow_html=True)
st.markdown("
", unsafe_allow_html=True)
st.subheader("Validation")
# Extract and display score
feedback = result["validation"]["feedback"]
if "Score:" in feedback:
score = feedback.split("Score:")[1].split("\n")[0].strip()
st.markdown(f"""
Validation Score: {score}
""", unsafe_allow_html=True)
st.write(feedback)
st.markdown("
", unsafe_allow_html=True)
with col2:
if st.session_state.result_data and st.button("👁️ View Edited Content"):
st.session_state.show_results = True
st.rerun()
elif task_type == "write_article":
st.markdown("", unsafe_allow_html=True)
topic = st.text_input("Enter research topic")
key_points = st.text_area("Enter key points (one per line)", height=150)
col1, col2 = st.columns(2)
with col1:
if st.button("📝 Generate Article"):
with st.spinner("Processing..."):
input_data = {"topic": topic, "key_points": key_points}
result = asyncio.run(agent_manager.process_task("write_article", input_data))
st.session_state.result_data = result
st.markdown("
", unsafe_allow_html=True)
st.subheader("Article")
st.write(result["result"]["article"])
st.markdown("
", unsafe_allow_html=True)
st.markdown("
", unsafe_allow_html=True)
st.subheader("Validation")
# Extract and display score
feedback = result["validation"]["feedback"]
if "Score:" in feedback:
score = feedback.split("Score:")[1].split("\n")[0].strip()
st.markdown(f"""
Validation Score: {score}
""", unsafe_allow_html=True)
st.write(feedback)
st.markdown("
", unsafe_allow_html=True)
with col2:
if st.session_state.result_data and st.button("👁️ View Edited Content"):
st.session_state.show_results = True
st.rerun()
elif task_type == "Redact PHI":
st.markdown("", unsafe_allow_html=True)
input_text = st.text_area("Enter medical text to redact PHI", height=200)
col1, col2 = st.columns(2)
with col1:
if st.button("🔐 Redact PHI"):
with st.spinner("Processing..."):
result = asyncio.run(agent_manager.process_task("sanitize", input_text))
st.session_state.result_data = result
st.markdown("
", unsafe_allow_html=True)
st.subheader("Redacted Text")
st.write(result["result"]["sanitized_data"])
st.markdown("
", unsafe_allow_html=True)
st.markdown("
", unsafe_allow_html=True)
st.subheader("Validation")
# Extract and display score
feedback = result["validation"]["feedback"]
if "Score:" in feedback:
score = feedback.split("Score:")[1].split("\n")[0].strip()
st.markdown(f"""
Validation Score: {score}
""", unsafe_allow_html=True)
st.write(feedback)
st.markdown("
", unsafe_allow_html=True)
with col2:
if st.session_state.result_data and st.button("👁️ View Edited Content"):
st.session_state.show_results = True
st.rerun()
st.markdown("
", unsafe_allow_html=True)
if __name__ == "__main__":
main()