yilunzhao commited on
Commit
45398ec
·
verified ·
1 Parent(s): e16449f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -53,13 +53,15 @@ def insert_sentence(text, sentence, interval):
53
 
54
  def format_bibtex(paper, style='apa'):
55
  bibtex_entry = paper["citationStyles"]["bibtex"]
56
- bib_data = parse_string(bibtex_entry, 'bibtex')
57
- formatter = find_plugin('pybtex.style.formatting', style)()
58
- entries = list(bib_data.entries.values())
59
- if not entries:
60
- return "No valid entries found."
61
- formatted_entry = formatter.format_entries(entries)
62
- return '\n'.join(entry.text.render_as('text') for entry in formatted_entry)
 
 
63
 
64
  def search_paper(query):
65
  SEMANTIC_SCHOLAR_API_URL = "https://api.semanticscholar.org/graph/v1/paper/"
 
53
 
54
  def format_bibtex(paper, style='apa'):
55
  bibtex_entry = paper["citationStyles"]["bibtex"]
56
+ try:
57
+ bib_data = parse_string(bibtex_entry, 'bibtex')
58
+ formatter = find_plugin('pybtex.style.formatting', style)()
59
+ entries = list(bib_data.entries.values())
60
+ formatted = formatter.format_entries(entries)
61
+ return '\n'.join(e.text.render_as('text') for e in formatted)
62
+ except MissingFieldError:
63
+ # Fallback: ▸ return raw BibTeX ▸ or convert to a safe @misc record
64
+ return bibtex_entry.strip()
65
 
66
  def search_paper(query):
67
  SEMANTIC_SCHOLAR_API_URL = "https://api.semanticscholar.org/graph/v1/paper/"