Spaces:
Runtime error
Runtime error
shaocongma
commited on
Commit
·
4ed4801
1
Parent(s):
78f4b41
fix bug.
Browse files- utils/references.py +21 -3
utils/references.py
CHANGED
|
@@ -15,6 +15,7 @@
|
|
| 15 |
import itertools
|
| 16 |
import json
|
| 17 |
import re
|
|
|
|
| 18 |
import uuid
|
| 19 |
from typing import Dict, List, Optional, Union
|
| 20 |
|
|
@@ -202,13 +203,24 @@ def search_paper_arxiv(title):
|
|
| 202 |
|
| 203 |
|
| 204 |
def search_paper_ss(title):
|
|
|
|
|
|
|
|
|
|
| 205 |
fields = ["title", "abstract", "venue", "year", "authors", "tldr", "externalIds"]
|
| 206 |
limit = 1
|
| 207 |
-
|
| 208 |
-
|
|
|
|
|
|
|
| 209 |
headers = {"Accept": "*/*"}
|
| 210 |
response = requests.get(url, headers=headers, timeout=30)
|
| 211 |
results = response.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
raw_paper = results['data'][0]
|
| 213 |
if raw_paper['tldr'] is not None:
|
| 214 |
abstract = raw_paper['tldr']['text']
|
|
@@ -324,6 +336,8 @@ def load_papers_from_bibtex(bib_file_path):
|
|
| 324 |
|
| 325 |
|
| 326 |
def load_papers_from_text(text):
|
|
|
|
|
|
|
| 327 |
# split text by comma
|
| 328 |
titles = [part.strip() for part in text.split(',')]
|
| 329 |
titles = [remove_special_characters(title) for title in titles]
|
|
@@ -347,7 +361,7 @@ def ss_search(keywords, limit=20, fields=None):
|
|
| 347 |
fields = ["title", "abstract", "venue", "year", "authors", "tldr", "embedding", "externalIds"]
|
| 348 |
keywords = keywords.lower()
|
| 349 |
keywords = keywords.replace(" ", "+")
|
| 350 |
-
url = f'https://api.semanticscholar.org/graph/v1/paper/search?query={keywords}&limit={limit}&fields={",".join(fields)}
|
| 351 |
# headers = {"Accept": "*/*", "x-api-key": constants.S2_KEY}
|
| 352 |
headers = {"Accept": "*/*"}
|
| 353 |
|
|
@@ -563,3 +577,7 @@ class References:
|
|
| 563 |
for paper in papers:
|
| 564 |
papers_json[paper["paper_id"]] = paper
|
| 565 |
return papers_json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
import itertools
|
| 16 |
import json
|
| 17 |
import re
|
| 18 |
+
import time
|
| 19 |
import uuid
|
| 20 |
from typing import Dict, List, Optional, Union
|
| 21 |
|
|
|
|
| 203 |
|
| 204 |
|
| 205 |
def search_paper_ss(title):
|
| 206 |
+
if not title:
|
| 207 |
+
return {}
|
| 208 |
+
|
| 209 |
fields = ["title", "abstract", "venue", "year", "authors", "tldr", "externalIds"]
|
| 210 |
limit = 1
|
| 211 |
+
query = title.lower()
|
| 212 |
+
query = query.replace(" ", "+")
|
| 213 |
+
url = f'https://api.semanticscholar.org/graph/v1/paper/search?query={query}&limit={limit}&fields={",".join(fields)}'
|
| 214 |
+
time.sleep(5)
|
| 215 |
headers = {"Accept": "*/*"}
|
| 216 |
response = requests.get(url, headers=headers, timeout=30)
|
| 217 |
results = response.json()
|
| 218 |
+
try:
|
| 219 |
+
total = results['total']
|
| 220 |
+
if total == 0:
|
| 221 |
+
return {}
|
| 222 |
+
except KeyError:
|
| 223 |
+
return {}
|
| 224 |
raw_paper = results['data'][0]
|
| 225 |
if raw_paper['tldr'] is not None:
|
| 226 |
abstract = raw_paper['tldr']['text']
|
|
|
|
| 336 |
|
| 337 |
|
| 338 |
def load_papers_from_text(text):
|
| 339 |
+
print(text)
|
| 340 |
+
|
| 341 |
# split text by comma
|
| 342 |
titles = [part.strip() for part in text.split(',')]
|
| 343 |
titles = [remove_special_characters(title) for title in titles]
|
|
|
|
| 361 |
fields = ["title", "abstract", "venue", "year", "authors", "tldr", "embedding", "externalIds"]
|
| 362 |
keywords = keywords.lower()
|
| 363 |
keywords = keywords.replace(" ", "+")
|
| 364 |
+
url = f'https://api.semanticscholar.org/graph/v1/paper/search?query={keywords}&limit={limit}&fields={",".join(fields)}'
|
| 365 |
# headers = {"Accept": "*/*", "x-api-key": constants.S2_KEY}
|
| 366 |
headers = {"Accept": "*/*"}
|
| 367 |
|
|
|
|
| 577 |
for paper in papers:
|
| 578 |
papers_json[paper["paper_id"]] = paper
|
| 579 |
return papers_json
|
| 580 |
+
|
| 581 |
+
if __name__ == "__main__":
|
| 582 |
+
ref = References("Play Atari", load_papers="Atari Game Using Reinforcement Lear4ning")
|
| 583 |
+
ref.collect_papers({"Reinforcemetn Learning": 10}, tldr=True)
|