sonali-tamhankar commited on
Commit
abcfaf4
1 Parent(s): b11b0a8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.embeddings import HuggingFaceEmbeddings
2
+ from langchain.vectorstores import FAISS
3
+ from langchain import HuggingFaceHub
4
+ from langchain.chains import RetrievalQA
5
+ import streamlit as st
6
+
7
+ st.set_page_config(page_title = "Hospital Regulatory Chat", page_icon=":hospital:")
8
+
9
+ DB_FAISS_PATH = '.'
10
+
11
+ def get_vectorstore():
12
+ embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2",
13
+ model_kwargs={'device': 'cpu'})
14
+ vector_store = FAISS.load_local(DB_FAISS_PATH, embeddings)
15
+ return vector_store
16
+
17
+ vector_store = get_vectorstore()
18
+
19
+ llm = HuggingFaceHub(repo_id = "meta-llama/Llama-2-7b-chat-hf",huggingfacehub_api_token="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", model_kwargs={"temperature":0.5}) #, "max_length":512})
20
+
21
+ qa_chain = RetrievalQA.from_chain_type(llm=llm,
22
+ chain_type='stuff',
23
+ retriever=vector_store.as_retriever(search_kwargs={'k': 10}),
24
+ #retriever=vector_store.as_retriever(search_kwargs={"score_threshold": .01}),
25
+ return_source_documents = True
26
+ )
27
+
28
+
29
+ with st.container():
30
+ st.title("Solid Tumor Rules Chat")
31
+
32
+ with st.sidebar:
33
+ st.subheader("Find references in solid tumor staging manual.")
34
+ st.markdown("""
35
+ We look into the solid tumor staging manual to find top ten most relevant excerpts:
36
+ - [SEER Solid Tumor Rules](https://app.leg.wa.gov/rcw/default.aspx?cite=70.41https://seer.cancer.gov/tools/solidtumor/2023/STM_Combined.pdf)
37
+ """) #, unsafe_allow_html=True)
38
+ st.write("This is tool is meant to assist healthcare workers to the extent it can. Please note that the page numbers may be occasionally slightly off, use the included excerpt to find the reference if this happens.")
39
+
40
+ st.markdown("**Ask your question and :red[click 'Find Matches'.]**")
41
+
42
+ prompt = st.text_input("e.g. How do you code anaplastic meningioma?")
43
+
44
+ if (st.button("Find Matches")):
45
+ answer = qa_chain({"query":prompt})
46
+
47
+ n = len(answer['source_documents'])
48
+
49
+ for i in range(n):
50
+ with st.container():
51
+ #st.subheader(source_dictionary[answer['source_documents'][i].metadata['source']])
52
+ page_no = "**Page: " + str(answer['source_documents'][i].metadata['page']) + "**"
53
+ st.markdown(page_no)
54
+ st.write("...")
55
+ st.write(answer['source_documents'][i].page_content)
56
+ st.write("...")
57
+ st.write('---------------------------------\n\n')