Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -228,10 +228,10 @@ class PaperDownloader:
|
|
228 |
with open(filepath, 'wb') as f:
|
229 |
f.write(pdf_content)
|
230 |
logger.info(f"Successfully downloaded: {filename}")
|
231 |
-
return filepath,
|
232 |
else:
|
233 |
logger.warning(f"Could not download: {doi}")
|
234 |
-
return None, f"Could not download {doi}", f"
|
235 |
|
236 |
except Exception as e:
|
237 |
logger.error(f"Error processing {doi}: {e}")
|
@@ -248,6 +248,7 @@ class PaperDownloader:
|
|
248 |
|
249 |
downloaded_files = []
|
250 |
failed_dois = []
|
|
|
251 |
for i, doi in enumerate(tqdm(dois, desc="Downloading papers")):
|
252 |
filepath, success_message, fail_message = self.download_single_doi(doi)
|
253 |
if filepath:
|
@@ -256,9 +257,10 @@ class PaperDownloader:
|
|
256 |
filepath_unique = os.path.join(self.output_dir, filename)
|
257 |
os.rename(filepath,filepath_unique)
|
258 |
downloaded_files.append(filepath_unique)
|
259 |
-
|
260 |
-
failed_dois.append(f"{doi} (https://doi.org/{doi})")
|
261 |
|
|
|
|
|
262 |
|
263 |
if downloaded_files:
|
264 |
zip_filename = 'papers.zip'
|
@@ -267,8 +269,7 @@ class PaperDownloader:
|
|
267 |
zipf.write(file_path, arcname=os.path.basename(file_path))
|
268 |
logger.info(f"ZIP file created: {zip_filename}")
|
269 |
|
270 |
-
return zip_filename if downloaded_files else None, "\n".join(
|
271 |
-
|
272 |
|
273 |
|
274 |
def process_bibtex(self, bib_file):
|
@@ -295,6 +296,7 @@ class PaperDownloader:
|
|
295 |
# Result lists
|
296 |
downloaded_files = []
|
297 |
failed_dois = []
|
|
|
298 |
|
299 |
# Download PDFs
|
300 |
for doi in tqdm(dois, desc="Downloading papers"):
|
@@ -313,12 +315,13 @@ class PaperDownloader:
|
|
313 |
f.write(pdf_content)
|
314 |
|
315 |
downloaded_files.append(filepath)
|
|
|
316 |
logger.info(f"Successfully downloaded: {filename}")
|
317 |
else:
|
318 |
-
|
319 |
|
320 |
except Exception as e:
|
321 |
-
failed_dois.append(f"
|
322 |
logger.error(f"Error processing {doi}: {e}")
|
323 |
|
324 |
# Create ZIP of downloaded papers
|
@@ -329,7 +332,7 @@ class PaperDownloader:
|
|
329 |
zipf.write(file_path, arcname=os.path.basename(file_path))
|
330 |
logger.info(f"ZIP file created: {zip_filename}")
|
331 |
|
332 |
-
return zip_filename, "\n".join(
|
333 |
|
334 |
|
335 |
def create_gradio_interface():
|
@@ -364,8 +367,8 @@ def create_gradio_interface():
|
|
364 |
],
|
365 |
outputs=[
|
366 |
gr.File(label="Download Papers (ZIP) or Single PDF"),
|
367 |
-
gr.
|
368 |
-
gr.
|
369 |
gr.File(label="Downloaded Single PDF")
|
370 |
],
|
371 |
title="🔬 Academic Paper Batch Downloader",
|
|
|
228 |
with open(filepath, 'wb') as f:
|
229 |
f.write(pdf_content)
|
230 |
logger.info(f"Successfully downloaded: {filename}")
|
231 |
+
return filepath, f'<a href="https://doi.org/{doi}">{doi}</a>', ""
|
232 |
else:
|
233 |
logger.warning(f"Could not download: {doi}")
|
234 |
+
return None, f"Could not download {doi}", f'<a href="https://doi.org/{doi}">{doi}</a>'
|
235 |
|
236 |
except Exception as e:
|
237 |
logger.error(f"Error processing {doi}: {e}")
|
|
|
248 |
|
249 |
downloaded_files = []
|
250 |
failed_dois = []
|
251 |
+
downloaded_links = []
|
252 |
for i, doi in enumerate(tqdm(dois, desc="Downloading papers")):
|
253 |
filepath, success_message, fail_message = self.download_single_doi(doi)
|
254 |
if filepath:
|
|
|
257 |
filepath_unique = os.path.join(self.output_dir, filename)
|
258 |
os.rename(filepath,filepath_unique)
|
259 |
downloaded_files.append(filepath_unique)
|
260 |
+
downloaded_links.append(f'<a href="https://doi.org/{doi}">{doi}</a>')
|
|
|
261 |
|
262 |
+
else:
|
263 |
+
failed_dois.append(f'<a href="https://doi.org/{doi}">{doi}</a>')
|
264 |
|
265 |
if downloaded_files:
|
266 |
zip_filename = 'papers.zip'
|
|
|
269 |
zipf.write(file_path, arcname=os.path.basename(file_path))
|
270 |
logger.info(f"ZIP file created: {zip_filename}")
|
271 |
|
272 |
+
return zip_filename if downloaded_files else None, "\n".join(downloaded_links), "\n".join(failed_dois)
|
|
|
273 |
|
274 |
|
275 |
def process_bibtex(self, bib_file):
|
|
|
296 |
# Result lists
|
297 |
downloaded_files = []
|
298 |
failed_dois = []
|
299 |
+
downloaded_links = []
|
300 |
|
301 |
# Download PDFs
|
302 |
for doi in tqdm(dois, desc="Downloading papers"):
|
|
|
315 |
f.write(pdf_content)
|
316 |
|
317 |
downloaded_files.append(filepath)
|
318 |
+
downloaded_links.append(f'<a href="https://doi.org/{doi}">{doi}</a>')
|
319 |
logger.info(f"Successfully downloaded: {filename}")
|
320 |
else:
|
321 |
+
failed_dois.append(f'<a href="https://doi.org/{doi}">{doi}</a>')
|
322 |
|
323 |
except Exception as e:
|
324 |
+
failed_dois.append(f'<a href="https://doi.org/{doi}">{doi}</a>')
|
325 |
logger.error(f"Error processing {doi}: {e}")
|
326 |
|
327 |
# Create ZIP of downloaded papers
|
|
|
332 |
zipf.write(file_path, arcname=os.path.basename(file_path))
|
333 |
logger.info(f"ZIP file created: {zip_filename}")
|
334 |
|
335 |
+
return zip_filename, "\n".join(downloaded_links), "\n".join(failed_dois), None
|
336 |
|
337 |
|
338 |
def create_gradio_interface():
|
|
|
367 |
],
|
368 |
outputs=[
|
369 |
gr.File(label="Download Papers (ZIP) or Single PDF"),
|
370 |
+
gr.HTML(label="Downloaded DOIs/Message"),
|
371 |
+
gr.HTML(label="Failed DOIs"),
|
372 |
gr.File(label="Downloaded Single PDF")
|
373 |
],
|
374 |
title="🔬 Academic Paper Batch Downloader",
|