-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
69 lines (63 loc) · 2.65 KB
/
Copy pathapp.py
File metadata and controls
69 lines (63 loc) · 2.65 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
68
69
import streamlit as st
import sqlite3
from pathlib import Path
import pipeline
st.set_page_config(page_title="PharmaPulse AI", layout="wide")
DB_PATH = Path(__file__).resolve().parent / "pharma_pulse.db"
if "conn" not in st.session_state:
try:
st.session_state.conn = sqlite3.connect(str(DB_PATH), check_same_thread=False)
except Exception as e:
st.error(f"Failed to connect to database: {e}")
st.stop()
conn = st.session_state.conn
st.session_state["db_conn"] = conn
st.session_state["db_path"] = str(DB_PATH)
st.sidebar.image("https://img.icons8.com/color/96/pharmacy-shop.png", width=60)
st.sidebar.title("PharmaPulse AI")
page = st.sidebar.radio(
"Navigate",
["Overview", "Demand Forecast", "Shortage Map", "Redistribution", "Medicine Alternatives"]
)
st.sidebar.header("Automation & Generative")
if st.sidebar.button("Run automation pipeline now"):
with st.spinner("Running automation pipeline"):
try:
result = pipeline.run_automation(conn)
st.success("Automation pipeline finished")
st.write(result["message"])
except Exception as e:
st.error(f"Automation failed: {e}")
if st.sidebar.button("Run generative summary now"):
with st.spinner("Running generative summary"):
try:
result = pipeline.run_generative(conn)
st.success("Generative summary saved")
st.write(result["summary"])
except Exception as e:
st.error(f"Generative generation failed: {e}")
last_insight = pipeline.load_latest_insight(conn)
if last_insight:
st.sidebar.markdown("### Latest generative summary")
st.sidebar.write(last_insight["summary_text"])
recent_runs = pipeline.load_latest_automation(conn)
if recent_runs:
st.sidebar.markdown("### Recent pipeline runs")
for run in recent_runs:
st.sidebar.write(f"{run['run_at']} {run['run_type']} {run['status']}")
PAGES_DIR = Path(__file__).resolve().parent / "Phase_4"
try:
if page == "Overview":
exec(open(PAGES_DIR / "overview_page.py", encoding="utf-8").read())
elif page == "Demand Forecast":
exec(open(PAGES_DIR / "demand_forecast_page.py", encoding="utf-8").read())
elif page == "Shortage Map":
exec(open(PAGES_DIR / "shortage_map_page.py", encoding="utf-8").read())
elif page == "Redistribution":
exec(open(PAGES_DIR / "redistribution_page.py", encoding="utf-8").read())
elif page == "Medicine Alternatives":
exec(open(PAGES_DIR / "medicine_alternatives_page.py", encoding="utf-8").read())
except Exception as e:
st.error(f"Error loading page: {str(e)}")
import traceback
st.error(traceback.format_exc())