I can't fetch image

hello, i have an image file and players.csv file that contains .png file and each png file are similar to playerid in players.csv. so, i convert image file into a dataframe that contains two columns ‘filename’ and ‘playerid’ and then on the basis of common column we will merge both files and create a function in which we will pass player_name and it will give image and all details of player. so, this app works fine in localhost but not on streamlit. help me to solve this problem. streamlit.runtime.media_file_storage.MediaFileStorageError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you’re on Streamlit Cloud, click on ‘Manage app’ in the lower right of your app).

Hi @NadeemAkhtar1947 , this is your repo i guess…
The problem is with your nba.pkl file. When you are generating this pkl file, your column Filename in data is having the file path as something like 'img\\203500.png'.
So correct these values to something like 'img/203500.png'.

Then it will work.
image

As you said , i have changed the file path but again i got error
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/elements/image.py”, line 359, in image_to_url

File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/memory_media_file_storage.py”, line 164, in _read_file

with open(filename, "rb") as f:

File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/memory_media_file_storage.py”, line 167, in _read_file

raise MediaFileStorageError(f"Error opening '{filename}'") from ex

streamlit.runtime.media_file_storage.MediaFileStorageError: Error opening ‘img\1630180.png’

hi @ilovetensor, As you said , i have changed the file path but again i got error
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/elements/image.py”, line 359, in image_to_url

File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/memory_media_file_storage.py”, line 164, in _read_file

with open(filename, “rb”) as f:
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/memory_media_file_storage.py”, line 167, in _read_file

raise MediaFileStorageError(f"Error opening ‘{filename}’") from ex

streamlit.runtime.media_file_storage.MediaFileStorageError: Error opening ‘img\1630180.png’

Use forward slash img/1630180.png

yeah, i have used forward slash
df[‘Filename’] = df[‘Filename’].str.replace(‘\’, ‘/’)

Use
df[‘Filename’].str.replace(‘\\’, ‘/’) to replace single backslash with single forward slash
and str.replace('\\\\','/') to replace double backslash with single fwd slash.

Thank you sir @ilovetensor

It appears that there is an issue with the ‘nba.pkl’ file in your repository. The problem stems from the ‘Filename’ column in your dataset, where the file paths are formatted as ‘img\203500.png’ instead of the expected ‘img/203500.png’.

Once you update these values to the correct format (‘img/203500.png’), the issue should be resolved.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.