talkingwallace / ChatGPT-Paper-Reader

This repo offers a simple interface that helps you to read&summerize research papers in pdf format. You can ask some questions after reading. This interface is developed based on openai API and using GPT-3.5-turbo model.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: Unsupported input type: <class 'tempfile._TemporaryFileWrapper'>

YuSekai opened this issue · comments

I upload the alexnet.pdf and click start analyse ,it return an Error.
And I check the IDE it show this.

Beep....Beep....Beep.... Parsing
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\gradio\routes.py", line 292, in run_predict
output = await app.blocks.process_api(
File "C:\ProgramData\Anaconda3\lib\site-packages\gradio\blocks.py", line 1007, in process_api
result = await self.call_function(fn_index, inputs, iterator, request)
File "C:\ProgramData\Anaconda3\lib\site-packages\gradio\blocks.py", line 848, in call_function
prediction = await anyio.to_thread.run_sync(
File "C:\ProgramData\Anaconda3\lib\site-packages\anyio\to_thread.py", line 28, in run_sync
return await get_asynclib().run_sync_in_worker_thread(func, *args, cancellable=cancellable,
File "C:\ProgramData\Anaconda3\lib\site-packages\anyio_backends_asyncio.py", line 818, in run_sync_in_worker_thread
return await future
File "C:\ProgramData\Anaconda3\lib\site-packages\anyio_backends_asyncio.py", line 754, in run
result = context.run(func, *args)
File "F:\yjj\ChatGPT-Paper-Reader\gui.py", line 15, in analyse
return self.session.summarize(self.paper)
File "F:\yjj\ChatGPT-Paper-Reader\gpt_reader\pdf_reader.py", line 30, in summarize
paper = self.bot.read_paper(paper)
File "F:\yjj\ChatGPT-Paper-Reader\gpt_reader\bot\openai.py", line 139, in read_paper
titles = self.parse_pdf_title(paper.pdf_path)
File "F:\yjj\ChatGPT-Paper-Reader\gpt_reader\bot\openai.py", line 72, in parse_pdf_title
for page_layout in extract_pages(pdf_path):
File "C:\ProgramData\Anaconda3\lib\site-packages\pdfminer\high_level.py", line 203, in extract_pages
with open_filename(pdf_file, "rb") as fp:
File "C:\ProgramData\Anaconda3\lib\site-packages\pdfminer\utils.py", line 59, in init
raise TypeError("Unsupported input type: %s" % type(filename))
TypeError: Unsupported input type: <class 'tempfile._TemporaryFileWrapper'>

I copy it to the GPT4,it answered me :

The error is caused by the pdfminer.high_level.extract_pages() function expecting a file path (a string) or a file-like object as its argument, but it appears to be receiving a tempfile._TemporaryFileWrapper object instead.

To fix this issue, you should pass a proper file path or a file-like object to the extract_pages() function. You can make the following changes in your gpt_reader\bot\openai.py file:

1.If you are using a temporary file, make sure to call the name attribute to get the file path before passing it to the extract_pages() function:

temp_file_path = tempfile_object.name
for page_layout in extract_pages(temp_file_path):

2.Alternatively, if you want to pass a file-like object, you can open the temporary file in binary mode and pass it to the extract_pages() function:

with open(tempfile_object.name, "rb") as file_object:
for page_layout in extract_pages(file_object):

By ensuring that you are passing the correct file path or file-like object to the extract_pages() function, you should be able to avoid the TypeError raised in your script.

same

same

File "/Library/Mobile Documents/comappleCloudDocs/sycode/ChatGPT-Paper-Reader/gpt_reader/bot/openai.py", line 72, in parse_pdf_title
for page_layout in extract_pages(pdf_path):
File "//miniconda/envs/myenv/lib/python3.10/site-packages/pdfminer/high_level.py", line 203, in extract_pages
with open_filename(pdf_file, "rb") as fp:
File "//miniconda/envs/myenv/lib/python3.10/site-packages/pdfminer/utils.py", line 59, in init
raise TypeError("Unsupported input type: %s" % type(filename))
TypeError: Unsupported input type: <class 'tempfile._TemporaryFileWrapper'>