pgleeson commited on
Commit
d5b28d0
·
1 Parent(s): 07d335e

Add publications tab

Browse files
Files changed (2) hide show
  1. app.py +21 -1
  2. publications.py +46 -0
app.py CHANGED
@@ -12,7 +12,7 @@ from ring import get_openai_api_key
12
  from ring import generate_response
13
  from ring import generate_panel_response
14
 
15
- __version__ = '0.1.5'
16
 
17
  col1, col2 = st.columns([3, 1])
18
 
@@ -68,3 +68,23 @@ with tab_panel:
68
  temperature=temperature)
69
 
70
  st.info(response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  from ring import generate_response
13
  from ring import generate_panel_response
14
 
15
+ __version__ = '0.1.6'
16
 
17
  col1, col2 = st.columns([3, 1])
18
 
 
68
  temperature=temperature)
69
 
70
  st.info(response)
71
+
72
+ with tab_pubs:
73
+
74
+ from publications import find_basis_paper
75
+
76
+ st.markdown("**Find literature related to _C. elegans_**")
77
+
78
+ with st.form("form_pubs"):
79
+
80
+ text = st.text_input("Enter a topic:", "C. elegans locomotion")
81
+
82
+ num = st.text_input("Number of results", value=5)
83
+
84
+ submitted = st.form_submit_button("Submit")
85
+
86
+ if submitted:
87
+ response = find_basis_paper(query=text,
88
+ result_limit=num)
89
+
90
+ st.info(response)
publications.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Based on: https://github.com/allenai/s2-folks/tree/main/examples/python
2
+ #
3
+ #
4
+
5
+ import os
6
+ import re
7
+
8
+ import requests
9
+
10
+ S2_API_KEY = os.getenv('S2_API_KEY')
11
+ result_limit = 10
12
+
13
+
14
+ def find_basis_paper(query, result_limit=10):
15
+
16
+ papers = None
17
+ info = '''Search results:
18
+
19
+ '''
20
+ while not papers:
21
+ if not query:
22
+ continue
23
+
24
+ rsp = requests.get('https://api.semanticscholar.org/graph/v1/paper/search',
25
+ headers={'X-API-KEY': S2_API_KEY},
26
+ params={'query': query, 'limit': result_limit, 'fields': 'title,url'})
27
+ rsp.raise_for_status()
28
+ results = rsp.json()
29
+ total = results["total"]
30
+ if not total:
31
+ print('No matches found. Please try another query.')
32
+ continue
33
+
34
+ print(f'Found {total} results. Showing up to {result_limit}.')
35
+ papers = results['data']
36
+ info += format_paper_list(papers)
37
+
38
+ print(info)
39
+ return info
40
+
41
+ def format_paper_list(papers):
42
+ list = ''
43
+ for idx, paper in enumerate(papers):
44
+ list+=(f"{idx}: [{paper['title']}]({paper['url']}) \n\n")
45
+
46
+ return list