Hiba03 commited on
Commit
0928ebc
·
verified ·
1 Parent(s): 0043127

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -9,6 +9,7 @@ from bs4 import BeautifulSoup
9
  import arxiv
10
  from PyPDF2 import PdfReader
11
  from xml.etree import ElementTree
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
 
14
 
@@ -75,18 +76,16 @@ def get_paper_content(link:str)->str:
75
  pdf_url = paper.entry_id.replace("abs", "pdf") + ".pdf"
76
  response = requests.get(pdf_url)
77
  response.raise_for_status()
78
- pdf_path = "temp_paper.pdf"
79
- with open(pdf_path, "wb") as file:
80
- file.write(response.content)
81
 
82
-
83
  content = ""
84
- reader = PdfReader(pdf_path)
85
- pages = reader.pages[:4]
86
  for page in pages:
87
- content += page.extract_text()
88
-
89
- return content
90
 
91
  except Exception as e:
92
  return f"Error reading paper: {str(e)}"
 
9
  import arxiv
10
  from PyPDF2 import PdfReader
11
  from xml.etree import ElementTree
12
+ import io
13
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
14
 
15
 
 
76
  pdf_url = paper.entry_id.replace("abs", "pdf") + ".pdf"
77
  response = requests.get(pdf_url)
78
  response.raise_for_status()
79
+ pdf_buffer = io.BytesIO(response.content)
 
 
80
 
81
+ # Extract text from the first four pages
82
  content = ""
83
+ reader = PdfReader(pdf_buffer)
84
+ pages = reader.pages[:4]
85
  for page in pages:
86
+ content += page.extract_text() or ""
87
+
88
+ return content.strip()
89
 
90
  except Exception as e:
91
  return f"Error reading paper: {str(e)}"