When I store the uploaded file as a variable and call the uploaded file once to store inside a variable, there seems to be no issues with it. But when I reference the uploaded file a second time to store it in another variable I get the following error:
Here is my code:
def read_pdf(file, coordinates, page):
df = tabula.read_pdf(file, area = coordinates,pages = page)
pg2_df = read_pdf(uploaded_file,(11.858,174.267,151.088,565.947),'2')
df2 = read_pdf(uploaded_file,(204.638,176.333,756.968,556.538),'1')
As you can see, I am referencing the uploaded file in two variables which causes this error to occur.
It’s very hard to determine what this is from without the full code or knowing if that file location you passed is correct. The error seems to indicate that that file is either empty or doesn’t exist.
I have actually never used tabula so I’m not sure about its syntax in your code example. Also, you reference
uploaded_file but haven’t included this in your Minimum Working Example (MWE).
Can you please provide a more detailed code snippet, or ideally a link to a GitHub repo where you’re developing this code to better understand your issue?
Use the community guidelines on making posts that helps others understand your question to help you get an answer:
Welcome to the Questions
category, the place to be if you’re having issues with your code, want to chat on Streamlit best practices or share some exotic code snippets with other users
Don’t hesitate to post any problem you’re having with Streamlit there, so other people can discuss it with you ! If you have trouble writing about your issue, from our experience the following details help a lot :
A quick description of what you are trying to achieve and the roadb…
The first time you read the file, it is consumed. So, the second time you try to read it, there is no data in the file object.
How you fix this is difficult to advise on, given the amount of code you have included.
But, just for fun, try adding the line
in between your two calls to the read_pdf function.
(ie add a new line before
df2 = ... and paste in the line I’ve written).
It will be interesting to hear if that helps, or even works!