Spaces:
Running
Running
Improved publications
Browse files- app.py +1 -1
- publications.py +25 -10
app.py
CHANGED
|
@@ -86,7 +86,7 @@ with tab_pubs:
|
|
| 86 |
|
| 87 |
text = st.text_input("Enter a topic:", "C. elegans locomotion")
|
| 88 |
|
| 89 |
-
num = st.text_input("Number of results", value=
|
| 90 |
|
| 91 |
submitted = st.form_submit_button("Submit")
|
| 92 |
|
|
|
|
| 86 |
|
| 87 |
text = st.text_input("Enter a topic:", "C. elegans locomotion")
|
| 88 |
|
| 89 |
+
num = st.text_input("Number of results", value=10)
|
| 90 |
|
| 91 |
submitted = st.form_submit_button("Submit")
|
| 92 |
|
publications.py
CHANGED
|
@@ -4,6 +4,7 @@
|
|
| 4 |
|
| 5 |
import os
|
| 6 |
import re
|
|
|
|
| 7 |
|
| 8 |
import requests
|
| 9 |
|
|
@@ -22,21 +23,27 @@ def find_basis_paper(query, result_limit=10):
|
|
| 22 |
continue
|
| 23 |
|
| 24 |
try:
|
|
|
|
|
|
|
|
|
|
| 25 |
rsp = requests.get('https://api.semanticscholar.org/graph/v1/paper/search',
|
| 26 |
headers={'X-API-KEY': S2_API_KEY},
|
| 27 |
-
params={'query': query,
|
|
|
|
|
|
|
|
|
|
| 28 |
rsp.raise_for_status()
|
| 29 |
results = rsp.json()
|
| 30 |
total = results["total"]
|
| 31 |
if not total:
|
| 32 |
-
|
| 33 |
-
continue
|
| 34 |
|
| 35 |
print(f'Found {total} results. Showing up to {result_limit}.')
|
| 36 |
papers = results['data']
|
| 37 |
-
info += format_paper_list(papers)
|
| 38 |
|
| 39 |
except Exception as e:
|
|
|
|
| 40 |
info += ('There was a problem...\n\n%s'%e)
|
| 41 |
|
| 42 |
print(info)
|
|
@@ -44,7 +51,7 @@ def find_basis_paper(query, result_limit=10):
|
|
| 44 |
|
| 45 |
|
| 46 |
def get_element(paper, part):
|
| 47 |
-
simple_parts = ['year','url','title']
|
| 48 |
if part in simple_parts:
|
| 49 |
if part in paper and paper[part] is not None:
|
| 50 |
v = paper[part]
|
|
@@ -71,12 +78,20 @@ def get_element(paper, part):
|
|
| 71 |
return '<unknown field %s>'%part
|
| 72 |
|
| 73 |
|
| 74 |
-
def format_paper_list(
|
| 75 |
list = ''
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
if paper['tldr'] and paper['tldr']['text']:
|
| 80 |
list+=(f"> _{paper['tldr']['text'].strip()}_ \n\n")
|
| 81 |
|
| 82 |
-
return list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
import os
|
| 6 |
import re
|
| 7 |
+
import traceback
|
| 8 |
|
| 9 |
import requests
|
| 10 |
|
|
|
|
| 23 |
continue
|
| 24 |
|
| 25 |
try:
|
| 26 |
+
if len(S2_API_KEY):
|
| 27 |
+
print('Using S2_API_KEY...')
|
| 28 |
+
|
| 29 |
rsp = requests.get('https://api.semanticscholar.org/graph/v1/paper/search',
|
| 30 |
headers={'X-API-KEY': S2_API_KEY},
|
| 31 |
+
params={'query': query,
|
| 32 |
+
'limit':100,
|
| 33 |
+
'fields': 'title,url,authors,year,tldr,journal,citationCount',
|
| 34 |
+
'sort': 'citationCount:desc'})
|
| 35 |
rsp.raise_for_status()
|
| 36 |
results = rsp.json()
|
| 37 |
total = results["total"]
|
| 38 |
if not total:
|
| 39 |
+
return 'No matches found. Please try another query.'
|
|
|
|
| 40 |
|
| 41 |
print(f'Found {total} results. Showing up to {result_limit}.')
|
| 42 |
papers = results['data']
|
| 43 |
+
info += format_paper_list(papers, int(result_limit))
|
| 44 |
|
| 45 |
except Exception as e:
|
| 46 |
+
print(traceback.format_exc())
|
| 47 |
info += ('There was a problem...\n\n%s'%e)
|
| 48 |
|
| 49 |
print(info)
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
def get_element(paper, part):
|
| 54 |
+
simple_parts = ['year','url','title','citationCount']
|
| 55 |
if part in simple_parts:
|
| 56 |
if part in paper and paper[part] is not None:
|
| 57 |
v = paper[part]
|
|
|
|
| 78 |
return '<unknown field %s>'%part
|
| 79 |
|
| 80 |
|
| 81 |
+
def format_paper_list(all_papers, result_limit):
|
| 82 |
list = ''
|
| 83 |
+
|
| 84 |
+
sorted_papers = sorted(all_papers, key=lambda d: d['citationCount'],reverse=True)[:result_limit]
|
| 85 |
+
|
| 86 |
+
print(sorted_papers)
|
| 87 |
+
for idx, paper in enumerate(sorted_papers):
|
| 88 |
+
|
| 89 |
+
list+=(f"{idx}: **{get_element(paper, 'authors')} et al. {get_element(paper, 'year')}**, [{get_element(paper, 'journal')}]({get_element(paper, 'url')}) {get_element(paper, 'title')}. Cited by {get_element(paper, 'citationCount')}\n\n")
|
| 90 |
if paper['tldr'] and paper['tldr']['text']:
|
| 91 |
list+=(f"> _{paper['tldr']['text'].strip()}_ \n\n")
|
| 92 |
|
| 93 |
+
return list
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
if __name__ == '__main__':
|
| 97 |
+
find_basis_paper('NeuroML')
|