pgleeson commited on
Commit
231c41d
·
1 Parent(s): 92b644c

Test corpus

Browse files
Files changed (3) hide show
  1. app.py +21 -1
  2. corpus_query.py +65 -0
  3. requirements.txt +2 -1
app.py CHANGED
@@ -26,10 +26,11 @@ with col2:
26
  st.image("images/OpenWormLogo.png")
27
 
28
 
29
- tab_free, tab_panel, tab_pubs, tab_data, tab_model = st.tabs(["Individual LLMs",
30
  "Panel discussion",
31
  "Publications",
32
  "Structured data",
 
33
  "Run model"])
34
 
35
 
@@ -120,6 +121,25 @@ with tab_data:
120
 
121
  st.info(response)
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  with tab_model:
124
 
125
  st.markdown("**Run a _C. elegans_ cell model**")
 
26
  st.image("images/OpenWormLogo.png")
27
 
28
 
29
+ tab_free, tab_panel, tab_pubs, tab_data, tab_corpus, tab_model = st.tabs(["Individual LLMs",
30
  "Panel discussion",
31
  "Publications",
32
  "Structured data",
33
+ "OpenWorm Corpus",
34
  "Run model"])
35
 
36
 
 
121
 
122
  st.info(response)
123
 
124
+ with tab_corpus:
125
+
126
+ from corpus_query import run_query
127
+
128
+ st.markdown("**Search a (small) corpus of _C. elegans_ literature** Uses: [paper-qa](https://github.com/whitead/paper-qa)")
129
+
130
+ with st.form("form_corpus"):
131
+
132
+ text = st.text_input("Enter a query:", "What types of ion channels are present in C. elegans neurons?")
133
+
134
+ llm_ver = st.selectbox('Which LLM version should I use?', (LLM_LLAMA2, LLM_GPT4))
135
+
136
+ submitted = st.form_submit_button("Submit")
137
+
138
+ if submitted:
139
+ response = run_query(query=text, llm_ver=llm_ver)
140
+
141
+ st.info(response)
142
+
143
  with tab_model:
144
 
145
  st.markdown("**Run a _C. elegans_ cell model**")
corpus_query.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from paperqa import Docs
2
+ import pickle
3
+
4
+ from ring import LLM_GPT35
5
+ from ring import LLM_GPT4
6
+ from ring import LLM_LLAMA2
7
+ from ring import get_llm
8
+
9
+ my_docs = ['corpus/MirzakhaliliEtAl2018.pdf',
10
+ 'corpus/NicollettiEtAl2019.pdf',
11
+ 'corpus/ATributetoSydneyBrenner.pdf']
12
+
13
+ #my_docs = ['corpus/ATributetoSydneyBrenner.pdf']
14
+
15
+ llm_to_use = LLM_GPT4
16
+ llm = get_llm(llm_to_use, 0.1)
17
+
18
+ CORPUS_PICKLE = 'corpus.pkl'
19
+
20
+ def generate_pickle():
21
+ docs = Docs(llm="langchain",
22
+ client=llm)
23
+
24
+ print('Initialised Docs with LLM: %s'%llm_to_use)
25
+
26
+ for d in my_docs:
27
+ print('Adding %s'%d)
28
+ docs.add(d)
29
+
30
+ print('Saving pickle of docs to: %s'%CORPUS_PICKLE)
31
+
32
+ f = open(CORPUS_PICKLE,'wb')
33
+ pickle.dump(docs, f)
34
+ f.close()
35
+
36
+
37
+ def run_query(query, llm_ver):
38
+
39
+ f = open(CORPUS_PICKLE,'rb')
40
+
41
+ docs = pickle.load(f)
42
+
43
+ llm = get_llm(llm_ver, 0)
44
+
45
+ docs.set_client(llm)
46
+ answer = docs.query(query)
47
+
48
+ return answer
49
+
50
+
51
+ if __name__ == '__main__':
52
+
53
+ #generate_pickle()
54
+
55
+ print('Running queries')
56
+
57
+ queries = ['Where did John Sulston do his postdoc?',"What types of potassium channels are expressed in C. elegans?"]
58
+
59
+ for query in queries:
60
+ print('-------------------')
61
+ print('Q: %s'%query)
62
+ #answer = docs.query(query)
63
+ answer = run_query(query, LLM_GPT4)
64
+
65
+ print('A: %s'%answer)
requirements.txt CHANGED
@@ -8,4 +8,5 @@ wormneuroatlas
8
  neuromllite
9
  matplotlib
10
  pylems
11
- pyneuroml
 
 
8
  neuromllite
9
  matplotlib
10
  pylems
11
+ pyneuroml
12
+ paper-qa==4.0.0rc8