|
import streamlit as st
|
|
from PIL import Image
|
|
from agentic_rag import AgenticRAG
|
|
import pandas as pd
|
|
import plotly.express as px
|
|
|
|
|
|
|
|
|
|
|
|
agentic_rag = AgenticRAG()
|
|
|
|
|
|
header_image = Image.open("header_image.webp")
|
|
sidebar_image = Image.open("sidebar_image.webp")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tab1, tab2 = st.tabs(["π Ask ANA", "π View Analytics"])
|
|
|
|
st.markdown(
|
|
"""
|
|
<style>
|
|
/* Remove padding from the body */
|
|
.css-18e3th9 {
|
|
padding-top: 0px;
|
|
padding-bottom: 0px;
|
|
padding-left: 0px;
|
|
padding-right: 0px;
|
|
}
|
|
|
|
/* Remove default padding from sidebar */
|
|
.css-1d391kg {
|
|
padding-top: 0px;
|
|
padding-bottom: 0px;
|
|
}
|
|
|
|
/* Adjust space between sidebar and main content */
|
|
.css-1u6zpdt {
|
|
padding-left: 0px;
|
|
}
|
|
|
|
</style>
|
|
""",
|
|
unsafe_allow_html=True,
|
|
)
|
|
|
|
|
|
|
|
with tab1:
|
|
st.image("header_image.webp", use_container_width=True)
|
|
|
|
|
|
|
|
st.sidebar.image(sidebar_image, caption="ANA: Your Health Query Assistant", use_container_width=True)
|
|
st.sidebar.header("Instructions")
|
|
st.sidebar.write("""
|
|
1. Enter your query in the input box below.
|
|
2. Click on the **Submit** button.
|
|
""")
|
|
st.sidebar.markdown(
|
|
"### About\nANA is powered by Agentic RAG and LangGraph that combines LLM with document retrieval and web search to provide accurate answers based on context."
|
|
)
|
|
|
|
|
|
query = st.text_input("πType your question below:", "")
|
|
if st.button("Submit"):
|
|
if query.strip():
|
|
with st.spinner("Processing your query..."):
|
|
|
|
response = agentic_rag.invoke(query)
|
|
|
|
st.success("Query processed successfully!")
|
|
st.markdown("### π‘ ANA Says")
|
|
st.write(response.get("generation", "No response generated."))
|
|
else:
|
|
st.warning("Please enter a valid question.")
|
|
|
|
|
|
with tab2:
|
|
|
|
|
|
col1, col2 = st.columns(2)
|
|
|
|
with col1:
|
|
|
|
st.markdown(
|
|
"""
|
|
<div style="background-color: #f9f9f9; padding: 20px; border-radius: 10px; box-shadow: 2px 2px 10px rgba(0,0,0,0.1);">
|
|
<h4 style="color: #4caf50;">Most Asked Categories</h4>
|
|
""",
|
|
unsafe_allow_html=True,
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
df_queries = agentic_rag.agent.db.read_sql()
|
|
|
|
fig_query = px.bar(
|
|
df_queries,
|
|
x="category",
|
|
y="Count",
|
|
color="category",
|
|
text="Count"
|
|
)
|
|
st.plotly_chart(fig_query, use_container_width=True)
|
|
|
|
with col2:
|
|
|
|
st.markdown(
|
|
"""
|
|
<div style="background-color: #f9f9f9; padding: 20px; border-radius: 10px; box-shadow: 2px 2px 10px rgba(0,0,0,0.1);">
|
|
<h4 style="color: #ff5722;">Engagement Over Time</h4>
|
|
""",
|
|
unsafe_allow_html=True,
|
|
)
|
|
df_engagement = agentic_rag.agent.db.read_qns()
|
|
df_engagement["year_month"] =pd.Categorical(df_engagement["year_month"], ordered=True)
|
|
|
|
|
|
fig_engagement = px.line(
|
|
df_engagement,
|
|
x="year_month",
|
|
y="Count",
|
|
markers=True,
|
|
labels={"year_month": "Month-Year", "Count": "Number of Questions"}
|
|
)
|
|
|
|
|
|
st.plotly_chart(fig_engagement, use_container_width=True)
|
|
|
|
|
|
st.markdown(
|
|
"""
|
|
---
|
|
Developed by [Safni Usman](https://www.linkedin.com/in/safniusman/)
|
|
"""
|
|
)
|
|
|