Spaces:
Runtime error
Runtime error
chendelong1999
commited on
Commit
·
94cf70c
1
Parent(s):
2838528
prettify
Browse files
app.py
CHANGED
@@ -23,9 +23,11 @@ def get_dblp_bibref(title):
|
|
23 |
url = soup.select_one('url').text + '.bib'
|
24 |
response = requests.get(url)
|
25 |
|
26 |
-
|
|
|
|
|
27 |
except Exception as e:
|
28 |
-
return f'Error during get bibref from DBLP: {e}'
|
29 |
|
30 |
# set pprint width
|
31 |
pp = pprint.PrettyPrinter(width=128)
|
@@ -110,9 +112,9 @@ def summarize_paper_info(paper_info):
|
|
110 |
author_str += f"[{author['name']}](https://www.semanticscholar.org/author/{author['authorId']}), "
|
111 |
author_str = author_str[:-2]
|
112 |
|
113 |
-
info_str += f"**Authors
|
114 |
|
115 |
-
info_str += f"**Abstract**: {paper_info['abstract']}\n\n"
|
116 |
info_str += f"**Citation Count**: {paper_info['citationCount']}\n\n"
|
117 |
return info_str
|
118 |
|
@@ -124,14 +126,36 @@ def get_output(title):
|
|
124 |
citation_str = get_md_citation(paper_info)
|
125 |
else:
|
126 |
citation_str = "No paper found with that title."
|
|
|
|
|
127 |
|
128 |
citation_str = f"""
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
133 |
---
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
"""
|
136 |
|
137 |
print(citation_str)
|
@@ -139,12 +163,19 @@ def get_output(title):
|
|
139 |
return citation_str
|
140 |
|
141 |
def main():
|
142 |
-
iface = gr.Interface(
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
iface.launch()
|
149 |
|
150 |
if __name__=="__main__":
|
|
|
23 |
url = soup.select_one('url').text + '.bib'
|
24 |
response = requests.get(url)
|
25 |
|
26 |
+
paper_link = soup.select_one('url').text + '.html'
|
27 |
+
|
28 |
+
return response.text, paper_link
|
29 |
except Exception as e:
|
30 |
+
return f'Error during get bibref from DBLP: {e}', None
|
31 |
|
32 |
# set pprint width
|
33 |
pp = pprint.PrettyPrinter(width=128)
|
|
|
112 |
author_str += f"[{author['name']}](https://www.semanticscholar.org/author/{author['authorId']}), "
|
113 |
author_str = author_str[:-2]
|
114 |
|
115 |
+
info_str += f"**Authors**:\n\n{author_str}\n\n"
|
116 |
|
117 |
+
info_str += f"\n\n> **Abstract**: {paper_info['abstract']}\n\n"
|
118 |
info_str += f"**Citation Count**: {paper_info['citationCount']}\n\n"
|
119 |
return info_str
|
120 |
|
|
|
126 |
citation_str = get_md_citation(paper_info)
|
127 |
else:
|
128 |
citation_str = "No paper found with that title."
|
129 |
+
|
130 |
+
bibtex, dblp_link = get_dblp_bibref(paper_info['title'])
|
131 |
|
132 |
citation_str = f"""
|
133 |
+
```text
|
134 |
+
{paper_info['title']}
|
135 |
+
```
|
136 |
+
|
137 |
+
{citation_str}
|
138 |
+
|
139 |
---
|
140 |
+
|
141 |
+
**Markdown source code**
|
142 |
+
|
143 |
+
```markdown
|
144 |
+
{citation_str}
|
145 |
+
```
|
146 |
+
|
147 |
+
|
148 |
+
**BibTex**
|
149 |
+
|
150 |
+
```bibtex
|
151 |
+
{bibtex}
|
152 |
+
```
|
153 |
+
|
154 |
+
{summarize_paper_info(paper_info)}
|
155 |
+
|
156 |
+
---
|
157 |
+
|
158 |
+
🔗 [[Open in Semantic Scholar]](https://www.semanticscholar.org/paper/{paper_info['paperId']}) | [[DBLP Page]]({dblp_link})
|
159 |
"""
|
160 |
|
161 |
print(citation_str)
|
|
|
163 |
return citation_str
|
164 |
|
165 |
def main():
|
166 |
+
iface = gr.Interface(
|
167 |
+
fn=get_output,
|
168 |
+
inputs=gr.components.Textbox(
|
169 |
+
lines=1,
|
170 |
+
label="Please input the title of the paper to get its citation.",
|
171 |
+
placeholder="Your title here",
|
172 |
+
autofocus=True,
|
173 |
+
),
|
174 |
+
outputs="markdown",
|
175 |
+
allow_flagging='never',
|
176 |
+
title="Citation Tool",
|
177 |
+
description="### Search paper title from [Semantic Scholar](https://www.semanticscholar.org/) and [DBLP](http://dblp.org/), and get structured citation.",
|
178 |
+
)
|
179 |
iface.launch()
|
180 |
|
181 |
if __name__=="__main__":
|