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

can't read an svs image uploaded with st.file_uploader() #6801

Closed
3 of 5 tasks
juliecious opened this issue Jun 5, 2023 · 1 comment
Closed
3 of 5 tasks

can't read an svs image uploaded with st.file_uploader() #6801

juliecious opened this issue Jun 5, 2023 · 1 comment
Assignees
Labels
status:redirect-forum Question should be in the forum instead of GitHub issues type:not-issue This issue is not valid (e.g. debugging question, question unrelated to Streamlit, etc.)

Comments

@juliecious
Copy link

juliecious commented Jun 5, 2023

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

I am trying to upload an image with svs format and visualise it on streamlit, but I couldn't wrap my head around the UploadedFile.

When I upload a .svs file, the type shows octet-stream,
UploadedFile(id=18, name='sample_111720.svs', type='application/octet-stream', size=1630062624)

But when I upload a .png, the type becomes type=image/png.

I also tried to visualise it with the solution mentioned here, unfortunately, it only works with pictures with .png or .jpg.

Considering the large memory of svs images, I have also set the maxUploadSize to 3000, which is 3GB. An example .svs file can be downloaded through here.

Reproducible Code Example

from tiatoolbox.wsicore.wsireader import WSIReader
from PIL import Image
import streamlit as st

list_of_available_types = [".svs", ".npy", ".ndpi", ".mrxs", ".tif", ".tiff",
                           ".jp2", ".png", ".jpg", ".jpeg", ".zarr", ".db"]


uploaded_file = st.file_uploader("Choose a WSI file", type=list_of_available_types)

if uploaded_file is not None:
    st.code(uploaded_file)

    reader = WSIReader.open(uploaded_file)
    st.code(reader)

Steps To Reproduce

Screenshot 2023-06-05 at 22 46 44

Expected Behavior

Screenshot 2023-06-05 at 22 48 04

Current Behavior

No response

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.22.0
  • Python version: 3.10.10
  • Operating System: macOS 13.2.1
  • Browser: Chrome
  • Virtual environment: Conda

Additional Information

No response

Are you willing to submit a PR?

  • Yes, I am willing to submit a PR!
@juliecious juliecious added status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working labels Jun 5, 2023
@snehankekre snehankekre added type:not-issue This issue is not valid (e.g. debugging question, question unrelated to Streamlit, etc.) status:redirect-forum Question should be in the forum instead of GitHub issues and removed type:bug Something isn't working feature:st.file_uploader status:needs-triage Has not been triaged by the Streamlit team labels Jun 13, 2023
@snehankekre
Copy link
Collaborator

Hi @juliecious 👋

Thanks for reporting this issue. You'll be happy to know this behavior isn't a Streamlit issue but a bug in your code 😃

The documentation for WSIReader.open states that the supported types for the input_img param are str, pathlib.Path, numpy.ndarray or WSIReader.

In your Expected behavior screenshot you're passing the str path to WSIReader.open, which is why it works. In Streamlit, with your current code, you run into a TypeError:

image

That should be the first clue 🕵️‍♀️ i.e. the wrong type is being passed.

The solution is to convert the uploaded file object from type streamlit.runtime.uploaded_file_manager.UploadedFile to numpy.ndarray before passing it to WSIReader.open:

import numpy as np
from PIL import Image
from tiatoolbox.wsicore.wsireader import WSIReader
import streamlit as st

list_of_available_types = [".svs"]

uploaded_file = st.file_uploader("Choose a WSI file", type=list_of_available_types)

if uploaded_file is not None:
    st.code(uploaded_file)

    reader = WSIReader.open(np.array(uploaded_file))
    st.code(reader)

image

@snehankekre snehankekre self-assigned this Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:redirect-forum Question should be in the forum instead of GitHub issues type:not-issue This issue is not valid (e.g. debugging question, question unrelated to Streamlit, etc.)
Projects
None yet
Development

No branches or pull requests

3 participants