Update app.py
Browse files
app.py
CHANGED
@@ -1,57 +1,33 @@
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
from datetime import datetime
|
4 |
-
import json
|
5 |
import requests
|
6 |
import uuid
|
7 |
-
from datetime import date, datetime
|
8 |
from pydantic import BaseModel
|
9 |
-
from typing import Optional
|
10 |
|
11 |
# Placeholder personas
|
12 |
placeHolderPersona1 = """## Mission Statement
|
13 |
-
My mission is to utilize my expertise to aid in the medical triaging process by providing a clear, concise, and accurate assessment of potential arthritis related conditions.
|
14 |
-
|
15 |
-
# Triaging process
|
16 |
-
Ensure you stay on the topic of asking questions to triage the potential of Rheumatoid arthritis.
|
17 |
-
Ask only one question at a time.
|
18 |
-
Provide some context or clarification around the follow-up questions you ask.
|
19 |
-
Do not converse with the customer.
|
20 |
-
Be as concise as possible.
|
21 |
-
Do not give a diagnosis """
|
22 |
|
23 |
placeHolderPersona2 = """## Mission
|
24 |
-
To analyse a clinical triaging discussion between a patient and AI doctor interactions with a focus on Immunology symptoms, medical history, and test results to deduce the most probable Immunology diagnosis.
|
25 |
-
|
26 |
-
|
27 |
-
Upon receipt of the clinical notes, I will follow a systematic approach to arrive at a diagnosis:
|
28 |
-
1. Review the patient's presenting symptoms and consider their relevance to immunopathology.
|
29 |
-
2. Cross-reference the gathered information with my knowledge base of immunology to identify patterns or indicators of specific immune disorders.
|
30 |
-
3. Formulate a diagnosis from the potential conditions.
|
31 |
-
4. Determine the most likely diagnosis and assign a confidence score from 1-100, with 100 being absolute certainty.
|
32 |
-
|
33 |
-
# Limitations
|
34 |
-
While I am specialized in immunology, I understand that not all cases will fall neatly within my domain. In instances where the clinical notes point to a condition outside of my expertise, I will provide the best possible diagnosis with the acknowledgment that my confidence score will reflect the limitations of my specialization in those cases"""
|
35 |
-
|
36 |
-
# Data model for API request
|
37 |
class ChatRequestClient(BaseModel):
|
38 |
user_id: str
|
39 |
user_input: str
|
40 |
numberOfQuestions: int
|
41 |
-
|
|
|
42 |
llm1: str
|
43 |
tokens1: int
|
44 |
temperature1: float
|
45 |
-
persona1SystemMessage: str
|
46 |
-
persona2SystemMessage: str
|
47 |
userMessage2: str
|
48 |
llm2: str
|
49 |
tokens2: int
|
50 |
temperature2: float
|
51 |
|
52 |
-
# Mock API call function
|
53 |
def call_chat_api(data: ChatRequestClient):
|
54 |
-
# Replace this with actual API logic
|
55 |
return {
|
56 |
"content": f"Response to: {data.user_input}",
|
57 |
"elapsed_time": 0.5,
|
@@ -59,53 +35,32 @@ def call_chat_api(data: ChatRequestClient):
|
|
59 |
"response_tokens": len(data.user_input.split()) # Mock token count
|
60 |
}
|
61 |
|
62 |
-
# Utility functions
|
63 |
-
def genuuid():
|
64 |
-
return uuid.uuid4()
|
65 |
-
|
66 |
def format_elapsed_time(time):
|
67 |
return "{:.2f}".format(time)
|
68 |
|
69 |
# Layout with three columns
|
70 |
-
col1, col2, col3 = st.columns([1,
|
71 |
|
72 |
# Left Column: Variables and Settings
|
73 |
with col1:
|
74 |
st.sidebar.image('cognizant_logo.jpg')
|
75 |
st.sidebar.header("Agent Personas Design")
|
76 |
st.sidebar.subheader("Intake AI")
|
77 |
-
numberOfQuestions = st.sidebar.slider(
|
78 |
-
|
79 |
-
)
|
80 |
-
|
81 |
-
|
82 |
-
)
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
)
|
87 |
-
tokens1 = st.sidebar.slider(
|
88 |
-
"Tokens", min_value=0, max_value=4000, step=100, value=500, key='persona1_tokens'
|
89 |
-
)
|
90 |
-
st.sidebar.subheader("Recommendation and Next Best Action AI")
|
91 |
-
persona2SystemMessage = st.sidebar.text_area(
|
92 |
-
"Define Recommendation Persona", value=placeHolderPersona2, height=300
|
93 |
-
)
|
94 |
-
llm2 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key='persona2_size')
|
95 |
-
temp2 = st.sidebar.slider(
|
96 |
-
"Temperature", min_value=0.0, max_value=1.0, step=0.1, value=0.5, key='persona2_temp'
|
97 |
-
)
|
98 |
-
tokens2 = st.sidebar.slider(
|
99 |
-
"Tokens", min_value=0, max_value=4000, step=100, value=500, key='persona2_tokens'
|
100 |
-
)
|
101 |
-
userMessage2 = st.sidebar.text_area(
|
102 |
-
"Define User Message", value="This is the conversation to date, ", height=150
|
103 |
-
)
|
104 |
-
st.sidebar.caption(f"Session ID: {genuuid()}")
|
105 |
|
106 |
# Middle Column: Chat Interface
|
107 |
with col2:
|
108 |
-
st.
|
|
|
|
|
109 |
user_id = st.text_input("User ID:", key="user_id")
|
110 |
|
111 |
if not user_id:
|
@@ -115,47 +70,47 @@ with col2:
|
|
115 |
if "messages" not in st.session_state:
|
116 |
st.session_state.messages = []
|
117 |
|
118 |
-
# Display chat history
|
119 |
-
|
120 |
-
|
121 |
-
|
|
|
|
|
122 |
|
123 |
-
#
|
124 |
if user_input := st.chat_input("Write your message here:"):
|
125 |
# Add user message
|
126 |
st.session_state.messages.append({"role": "user", "content": user_input})
|
127 |
st.chat_message("user").markdown(user_input)
|
128 |
|
129 |
-
# Prepare API
|
130 |
data = ChatRequestClient(
|
131 |
user_id=user_id,
|
132 |
user_input=user_input,
|
133 |
numberOfQuestions=numberOfQuestions,
|
134 |
-
|
|
|
135 |
llm1=llm1,
|
136 |
tokens1=tokens1,
|
137 |
temperature1=temp1,
|
138 |
-
|
139 |
-
persona2SystemMessage=persona2SystemMessage,
|
140 |
-
userMessage2=userMessage2,
|
141 |
llm2=llm2,
|
142 |
tokens2=tokens2,
|
143 |
-
temperature2=temp2
|
144 |
)
|
145 |
|
146 |
# Call the API
|
147 |
response = call_chat_api(data)
|
148 |
|
149 |
# Process response
|
150 |
-
agent_message = response
|
151 |
-
elapsed_time = response
|
152 |
-
count = response
|
153 |
-
response_tokens = response
|
154 |
|
155 |
# Add agent response
|
156 |
st.session_state.messages.append({"role": "assistant", "content": agent_message})
|
157 |
-
|
158 |
-
st.markdown(agent_message)
|
159 |
|
160 |
# Right Column: Stats
|
161 |
with col3:
|
@@ -166,8 +121,3 @@ with col3:
|
|
166 |
st.markdown(f"**Response Tokens:** {response_tokens}")
|
167 |
else:
|
168 |
st.markdown("No stats available yet.")
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
from datetime import datetime
|
|
|
4 |
import requests
|
5 |
import uuid
|
|
|
6 |
from pydantic import BaseModel
|
|
|
7 |
|
8 |
# Placeholder personas
|
9 |
placeHolderPersona1 = """## Mission Statement
|
10 |
+
My mission is to utilize my expertise to aid in the medical triaging process by providing a clear, concise, and accurate assessment of potential arthritis related conditions."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
placeHolderPersona2 = """## Mission
|
13 |
+
To analyse a clinical triaging discussion between a patient and AI doctor interactions with a focus on Immunology symptoms, medical history, and test results to deduce the most probable Immunology diagnosis."""
|
14 |
+
|
15 |
+
# Mock API call function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
class ChatRequestClient(BaseModel):
|
17 |
user_id: str
|
18 |
user_input: str
|
19 |
numberOfQuestions: int
|
20 |
+
persona1SystemMessage: str
|
21 |
+
persona2SystemMessage: str
|
22 |
llm1: str
|
23 |
tokens1: int
|
24 |
temperature1: float
|
|
|
|
|
25 |
userMessage2: str
|
26 |
llm2: str
|
27 |
tokens2: int
|
28 |
temperature2: float
|
29 |
|
|
|
30 |
def call_chat_api(data: ChatRequestClient):
|
|
|
31 |
return {
|
32 |
"content": f"Response to: {data.user_input}",
|
33 |
"elapsed_time": 0.5,
|
|
|
35 |
"response_tokens": len(data.user_input.split()) # Mock token count
|
36 |
}
|
37 |
|
|
|
|
|
|
|
|
|
38 |
def format_elapsed_time(time):
|
39 |
return "{:.2f}".format(time)
|
40 |
|
41 |
# Layout with three columns
|
42 |
+
col1, col2, col3 = st.columns([1, 3, 1]) # Adjusted width ratios for better centering
|
43 |
|
44 |
# Left Column: Variables and Settings
|
45 |
with col1:
|
46 |
st.sidebar.image('cognizant_logo.jpg')
|
47 |
st.sidebar.header("Agent Personas Design")
|
48 |
st.sidebar.subheader("Intake AI")
|
49 |
+
numberOfQuestions = st.sidebar.slider("Number of Questions", 0, 10, 5, 1)
|
50 |
+
persona1SystemMessage = st.sidebar.text_area("Define Intake Persona", value=placeHolderPersona1, height=300)
|
51 |
+
llm1 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'])
|
52 |
+
temp1 = st.sidebar.slider("Temperature", 0.0, 1.0, 0.6, 0.1)
|
53 |
+
tokens1 = st.sidebar.slider("Tokens", 0, 4000, 500, 100)
|
54 |
+
persona2SystemMessage = st.sidebar.text_area("Define Recommendation Persona", value=placeHolderPersona2, height=300)
|
55 |
+
llm2 = st.sidebar.selectbox("Model Selection", ['GPT-4', 'GPT3.5'], key="persona2")
|
56 |
+
temp2 = st.sidebar.slider("Temperature", 0.0, 1.0, 0.5, 0.1, key="temp2")
|
57 |
+
tokens2 = st.sidebar.slider("Tokens", 0, 4000, 500, 100, key="tokens2")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
# Middle Column: Chat Interface
|
60 |
with col2:
|
61 |
+
st.markdown("<div style='text-align: center;'><h1>Chat with the Agents</h1></div>", unsafe_allow_html=True)
|
62 |
+
|
63 |
+
# User ID Input
|
64 |
user_id = st.text_input("User ID:", key="user_id")
|
65 |
|
66 |
if not user_id:
|
|
|
70 |
if "messages" not in st.session_state:
|
71 |
st.session_state.messages = []
|
72 |
|
73 |
+
# Display chat history in a container
|
74 |
+
with st.container():
|
75 |
+
for message in st.session_state.messages:
|
76 |
+
role = "User" if message["role"] == "user" else "Agent"
|
77 |
+
with st.chat_message(message["role"]):
|
78 |
+
st.markdown(message["content"])
|
79 |
|
80 |
+
# Chat input at the bottom
|
81 |
if user_input := st.chat_input("Write your message here:"):
|
82 |
# Add user message
|
83 |
st.session_state.messages.append({"role": "user", "content": user_input})
|
84 |
st.chat_message("user").markdown(user_input)
|
85 |
|
86 |
+
# Prepare data for API call
|
87 |
data = ChatRequestClient(
|
88 |
user_id=user_id,
|
89 |
user_input=user_input,
|
90 |
numberOfQuestions=numberOfQuestions,
|
91 |
+
persona1SystemMessage=persona1SystemMessage,
|
92 |
+
persona2SystemMessage=persona2SystemMessage,
|
93 |
llm1=llm1,
|
94 |
tokens1=tokens1,
|
95 |
temperature1=temp1,
|
96 |
+
userMessage2="",
|
|
|
|
|
97 |
llm2=llm2,
|
98 |
tokens2=tokens2,
|
99 |
+
temperature2=temp2,
|
100 |
)
|
101 |
|
102 |
# Call the API
|
103 |
response = call_chat_api(data)
|
104 |
|
105 |
# Process response
|
106 |
+
agent_message = response["content"]
|
107 |
+
elapsed_time = response["elapsed_time"]
|
108 |
+
count = response["count"]
|
109 |
+
response_tokens = response["response_tokens"]
|
110 |
|
111 |
# Add agent response
|
112 |
st.session_state.messages.append({"role": "assistant", "content": agent_message})
|
113 |
+
st.chat_message("assistant").markdown(agent_message)
|
|
|
114 |
|
115 |
# Right Column: Stats
|
116 |
with col3:
|
|
|
121 |
st.markdown(f"**Response Tokens:** {response_tokens}")
|
122 |
else:
|
123 |
st.markdown("No stats available yet.")
|
|
|
|
|
|
|
|
|
|