Yew Chong commited on
Commit
91701f5
1 Parent(s): e7b07f9

update app

Browse files
Files changed (4) hide show
  1. app.py +31 -15
  2. db_firestore.py +3 -1
  3. templates/grader.txt +3 -1
  4. templates/patient.txt +2 -1
app.py CHANGED
@@ -37,11 +37,11 @@ import os, dotenv
37
  from dotenv import load_dotenv
38
  load_dotenv()
39
 
40
- if not os.path.isdir("../.streamlit"):
41
- os.mkdir("../.streamlit")
42
  print('made streamlit folder')
43
- if not os.path.isfile("../.streamlit/secrets.toml"):
44
- with open("../.streamlit/secrets.toml", "w") as f:
45
  f.write(os.environ.get("STREAMLIT_SECRETS"))
46
  print('made new file')
47
 
@@ -64,7 +64,6 @@ Dysphagia
64
  Headache
65
  ShortnessOfBreath
66
  Vomiting
67
- Warfarin
68
  Weakness
69
  Weakness2""".split("\n")
70
 
@@ -89,7 +88,7 @@ if index_selectbox != indexes[st.session_state.selected_index]:
89
 
90
 
91
  if "openai_model" not in st.session_state:
92
- st.session_state["openai_model"] = "gpt-3.5-turbo"
93
 
94
  if "messages_1" not in st.session_state:
95
  st.session_state.messages_1 = []
@@ -171,7 +170,7 @@ if ("chain" not in st.session_state
171
  )
172
  chain = st.session_state.chain
173
 
174
- sp_mapper = {"human":"student","ai":"patient"}
175
 
176
  ## ------------------------------------------------------------------------------------------------
177
  ## ------------------------------------------------------------------------------------------------
@@ -202,9 +201,11 @@ def format_docs(docs):
202
  return "\n--------------------\n".join(doc.page_content for doc in docs)
203
 
204
 
205
- fake_history = '\n'.join([(sp_mapper.get(i.type, i.type) + ": "+ i.content) for i in memory.chat_memory.messages])
 
 
206
 
207
- def x(_):
208
  return fake_history
209
 
210
  if ("chain2" not in st.session_state
@@ -213,7 +214,7 @@ if ("chain2" not in st.session_state
213
  st.session_state.chain2 = (
214
  {
215
  "context": retriever | format_docs,
216
- "history": x,
217
  "question": RunnablePassthrough(),
218
  } |
219
 
@@ -333,6 +334,16 @@ else:
333
  messages = st.session_state.messages_2
334
 
335
 
 
 
 
 
 
 
 
 
 
 
336
  if text_prompt:
337
  messages.append({"role": "user", "content": text_prompt})
338
 
@@ -343,10 +354,11 @@ if text_prompt:
343
  with (col1 if st.session_state.active_chat == 1 else col2):
344
  with st.chat_message("assistant"):
345
  message_placeholder = st.empty()
346
- if st.session_state.active_chat==1:
347
- full_response = chain.invoke(text_prompt).get("text")
348
- else:
349
- full_response = chain2.invoke(text_prompt).get("text").get("text")
 
350
  message_placeholder.markdown(full_response)
351
  messages.append({"role": "assistant", "content": full_response})
352
 
@@ -369,4 +381,8 @@ if text_prompt:
369
  # if st.button("START"):
370
  # count_down(int(time_in_seconds))
371
  # if __name__ == '__main__':
372
- # main()
 
 
 
 
 
37
  from dotenv import load_dotenv
38
  load_dotenv()
39
 
40
+ if not os.path.isdir("./.streamlit"):
41
+ os.mkdir("./.streamlit")
42
  print('made streamlit folder')
43
+ if not os.path.isfile("./.streamlit/secrets.toml"):
44
+ with open("./.streamlit/secrets.toml", "w") as f:
45
  f.write(os.environ.get("STREAMLIT_SECRETS"))
46
  print('made new file')
47
 
 
64
  Headache
65
  ShortnessOfBreath
66
  Vomiting
 
67
  Weakness
68
  Weakness2""".split("\n")
69
 
 
88
 
89
 
90
  if "openai_model" not in st.session_state:
91
+ st.session_state["openai_model"] = "gpt-3.5-turbo-1106"
92
 
93
  if "messages_1" not in st.session_state:
94
  st.session_state.messages_1 = []
 
170
  )
171
  chain = st.session_state.chain
172
 
173
+ sp_mapper = {"human":"student","ai":"patient", "user":"student","assistant":"patient"}
174
 
175
  ## ------------------------------------------------------------------------------------------------
176
  ## ------------------------------------------------------------------------------------------------
 
201
  return "\n--------------------\n".join(doc.page_content for doc in docs)
202
 
203
 
204
+ # fake_history = '\n'.join([(sp_mapper.get(i.type, i.type) + ": "+ i.content) for i in memory.chat_memory.messages])
205
+ fake_history = '\n'.join([(sp_mapper.get(i['role'], i['role']) + ": "+ i['content']) for i in st.session_state.messages_1])
206
+ st.write(fake_history)
207
 
208
+ def y(_):
209
  return fake_history
210
 
211
  if ("chain2" not in st.session_state
 
214
  st.session_state.chain2 = (
215
  {
216
  "context": retriever | format_docs,
217
+ "history": y,
218
  "question": RunnablePassthrough(),
219
  } |
220
 
 
334
  messages = st.session_state.messages_2
335
 
336
 
337
+ from langchain.callbacks.manager import tracing_v2_enabled
338
+ from uuid import uuid4
339
+ import os
340
+
341
+ os.environ['LANGCHAIN_TRACING_V2']='true'
342
+ os.environ['LANGCHAIN_ENDPOINT']='https://api.smith.langchain.com'
343
+ os.environ['LANGCHAIN_API_KEY']='ls__4ad767c45b844e6a8d790e12f556d3ca'
344
+ os.environ['LANGCHAIN_PROJECT']='streamlit'
345
+
346
+
347
  if text_prompt:
348
  messages.append({"role": "user", "content": text_prompt})
349
 
 
354
  with (col1 if st.session_state.active_chat == 1 else col2):
355
  with st.chat_message("assistant"):
356
  message_placeholder = st.empty()
357
+ with tracing_v2_enabled(project_name = "streamlit"):
358
+ if st.session_state.active_chat==1:
359
+ full_response = chain.invoke(text_prompt).get("text")
360
+ else:
361
+ full_response = chain2.invoke(text_prompt).get("text").get("text")
362
  message_placeholder.markdown(full_response)
363
  messages.append({"role": "assistant", "content": full_response})
364
 
 
381
  # if st.button("START"):
382
  # count_down(int(time_in_seconds))
383
  # if __name__ == '__main__':
384
+ # main()
385
+
386
+ st.write('fake history is:')
387
+ st.write(y(""))
388
+ st.write('done')
db_firestore.py CHANGED
@@ -13,7 +13,9 @@ except TypeError:
13
  import streamlit as st
14
  os.environ["FIREBASE_CREDENTIAL"] = st.secrets["FIREBASE_CREDENTIAL"]
15
  cred = credentials.Certificate(json.loads(os.environ.get("FIREBASE_CREDENTIAL"), strict=False))
16
- firebase_admin.initialize_app(cred,{'storageBucket': 'healthhack-store.appspot.com'}) # connecting to firebase
 
 
17
 
18
 
19
  def get_store(index_name, embeddings = None):
 
13
  import streamlit as st
14
  os.environ["FIREBASE_CREDENTIAL"] = st.secrets["FIREBASE_CREDENTIAL"]
15
  cred = credentials.Certificate(json.loads(os.environ.get("FIREBASE_CREDENTIAL"), strict=False))
16
+ # firebase_admin.initialize_app(cred,{'storageBucket': 'healthhack-store.appspot.com'}) # connecting to firebase
17
+ if not firebase_admin._apps:
18
+ firebase_admin.initialize_app(cred, {'storageBucket': 'healthhack-store.appspot.com'})
19
 
20
 
21
  def get_store(index_name, embeddings = None):
templates/grader.txt CHANGED
@@ -22,7 +22,7 @@ Your task is as follows:
22
  2. Next, taking into account of the rubrics, provide a letter grading for the student, from A to E, for each segment of the rubric.
23
  3. Provide relevant remarks for your letter grading and the reason for your grading, referencing specific points within the rubrics that the student was graded based upon. You can reference specific parts of the conversation history and the student's diagnosis.
24
  4. Taking into consideration of the grading from all rubric segments holistically, provide an overall grade for the student.
25
- 5. Give a summary on the overall grading of the student, and provide
26
  Finally, format your output into a valid JSON format.
27
 
28
  Example output JSON:
@@ -69,6 +69,8 @@ Some additional information that is useful to understand the the rubrics:
69
  - You are to grade the student based on the rubrics, by checking the looking through the conversation history between the patient and the medical student.
70
  - In the segment on presentating differentials and diagnosis, grade the student based on the diagnosis provided.
71
 
 
 
72
 
73
  =================================================================
74
 
 
22
  2. Next, taking into account of the rubrics, provide a letter grading for the student, from A to E, for each segment of the rubric.
23
  3. Provide relevant remarks for your letter grading and the reason for your grading, referencing specific points within the rubrics that the student was graded based upon. You can reference specific parts of the conversation history and the student's diagnosis.
24
  4. Taking into consideration of the grading from all rubric segments holistically, provide an overall grade for the student.
25
+ 5. Give a summary on the overall grading of the student, and provide remarks for the student's overall performance.
26
  Finally, format your output into a valid JSON format.
27
 
28
  Example output JSON:
 
69
  - You are to grade the student based on the rubrics, by checking the looking through the conversation history between the patient and the medical student.
70
  - In the segment on presentating differentials and diagnosis, grade the student based on the diagnosis provided.
71
 
72
+ Some information for grading:
73
+ - For Presentation of findings, diagnosis and differentials, if the top differential in the rubrics is not present in the student's diagnosis, you CANNOT give the student a grade above B.
74
 
75
  =================================================================
76
 
templates/patient.txt CHANGED
@@ -14,7 +14,7 @@ For example, you should not reply with "syncope", but instead with "fainting".
14
 
15
  You should not be able to understand ANY medical jargon. If the doctor asks you about your symptoms, do not reply in medical jargon, but give a description of your symptoms instead.
16
 
17
- If the doctor uses specific jargon terms, reply that you do not understand.
18
 
19
  You should never reveal the diagnosis. If the doctor asks you whether their diagnosis is right or not, you should reply "I don't know".
20
 
@@ -34,4 +34,5 @@ Question:
34
  {question}
35
  ----------------------------------------------------------------
36
  Remember, answer in a short and sweet manner, don't talk too much.
 
37
  Your reply:
 
14
 
15
  You should not be able to understand ANY medical jargon. If the doctor asks you about your symptoms, do not reply in medical jargon, but give a description of your symptoms instead.
16
 
17
+ If the doctor uses specific jargon terms, reply that you do not understand, and ask for further elaboration. E.g. "I don't understand what you mean, can you elaborate or rephrase?"
18
 
19
  You should never reveal the diagnosis. If the doctor asks you whether their diagnosis is right or not, you should reply "I don't know".
20
 
 
34
  {question}
35
  ----------------------------------------------------------------
36
  Remember, answer in a short and sweet manner, don't talk too much.
37
+ If you are unable to find the specific answer to the doctor's question on the symptom, reply that you do not have the symptom.
38
  Your reply: