DeathBlade020 commited on
Commit
cca61af
Β·
verified Β·
1 Parent(s): 255ee38

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +73 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,75 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
1
+
 
 
2
  import streamlit as st
3
+ import random
4
+ from constants import *
5
+ import tempfile
6
+ from get_graph import create_workflow
7
+
8
+ # Page config
9
+ st.set_page_config(
10
+ page_title="πŸ₯ Medical Assistant",
11
+ page_icon="πŸ₯",
12
+ layout="centered"
13
+ )
14
+
15
+ # Title
16
+ st.title(st_title)
17
+ st.markdown(st_markdown)
18
+
19
+
20
+ workflow = create_workflow()
21
+
22
+
23
+ if "messages" not in st.session_state:
24
+ st.session_state.messages = [
25
+ {"role": "assistant", "content": st_welcome_message}
26
+ ]
27
+
28
+ for message in st.session_state.messages:
29
+ with st.chat_message(message["role"]):
30
+ st.markdown(message["content"])
31
+
32
+
33
+
34
+ if prompt := st.chat_input("Ask a medical question..."):
35
+ st.session_state.messages.append({"role": "user", "content": prompt})
36
+
37
+ with st.chat_message("user"):
38
+ st.markdown(prompt)
39
+
40
+ with st.chat_message("assistant"):
41
+ with st.spinner(random.choice(spinner_messages)):
42
+
43
+ try:
44
+ result = workflow.invoke({
45
+ "question": prompt,
46
+ "answer": "",
47
+ "decision": ""
48
+ })
49
+
50
+ response = result['answer']
51
+
52
+ route_used = result.get('decision', 'Unknown')
53
+ if route_used == "EMERGENCY":
54
+ st.error(f"🚨 Emergency detected!")
55
+ elif route_used == "RAG":
56
+ st.info("πŸ“š Using medical knowledge base")
57
+ else:
58
+ st.info("πŸ’¬ General response")
59
+
60
+ st.markdown(response)
61
+
62
+ except Exception as e:
63
+ error_msg = st_error_message
64
+ st.error(error_msg)
65
+ response = error_msg
66
+ st.error(f"Error: {str(e)}")
67
+
68
+ st.session_state.messages.append({"role": "assistant", "content": response})
69
+
70
+
71
+ with st.sidebar:
72
+ st.header("ℹ️ Information")
73
+ st.write(sidebar_messages)
74
+ st.button("Clear Chat", on_click=lambda: st.session_state.pop("messages", None), help="Clear the chat history")
75