Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
YuSekai opened this issue Mar 30, 2023 · 3 comments

Comments

@YuSekai
Copy link

YuSekai commented Mar 30, 2023

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.

@pengzha0
Copy link

pengzha0 commented Apr 4, 2023

same

1 similar comment
@Bearbear006
Copy link

same

@shenbohe
Copy link

shenbohe commented Apr 6, 2023

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'>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants