Hey everyone, this should be fixed with Streamlit 0.84.1 streamlit/streamlit#3507 (comment). Iāve tested on the demo app and it works well, so it should work on your side too!
Fanilo
Hey everyone, this should be fixed with Streamlit 0.84.1 streamlit/streamlit#3507 (comment). Iāve tested on the demo app and it works well, so it should work on your side too!
Fanilo
Hey @andfanilo
I have a small issue I m trying to draw a polygon and use it as the ROI for detections in a video but I am not sure how exactly can I extract the points from the table as I am getting the following error
for this code st.dataframe(pd.json_normalize(canvas_result.json_data["objects"]))
in drawing a polygon
ArrowTypeError: ("Expected bytes, got a 'int' object", 'Conversion failed for column path with type object')
Iāve also had the same issue with the st.dataframe
function.
Hey @Pavankunchala @aswincandra
Sorry for taking so long to answer, holidays
Looks like a Streamlit Arrow upgrade problem, does it work if you downgrade Streamlit before version 0.85?
Fanilo
TypeError: a bytes-like object is required, not āCanvasResultā
I am using 0.88 version
# Create a canvas component
image_data = st_canvas(
b_width, b_color, bg_color, height=150, drawing_mode=drawing_mode, key="canvas"
)
# Do something interesting with the image data
if image_data is not None:
st.image(image_data)
and the code is:
I have a small issue I m trying to draw a polygon and use it as the ROI for detections in a video but I am not sure how exactly can I extract the points from the table as I am getting the following error for this code
st.dataframe(pd.json_normalize(canvas_result.json_data["objects"]))
in drawing a polygonArrowTypeError: ("Expected bytes, got a 'int' object", 'Conversion failed for column path with type object')
I think the explanation is https://discuss.streamlit.io/t/all-in-on-apache-arrow/15342/3:
if canvas_result.json_data is not None:
objects = pd.json_normalize(canvas_result.json_data["objects"])
for col in objects.select_dtypes(include=['object']).columns:
objects[col] = objects[col].astype("str")
st.dataframe(objects)
.streamlit/config.toml
the following:[global]
dataFrameSerialization = "legacy"
@BeyondMyself the image is stored in image_data.image_data
, the image_data
variable contains 2 properties: image_data
for the image and json_data
for the canvas JSON representation.
Hi, for some reason when I use the drawable canvas, a noticeable lag occurs while updating in real time.
Could I optimize the code in a way so that such a lag is not noticed?
Hey @watchdog welcome to the forums
update_streamlit=False
and updating by pushing the arrow in the toolbar if the lag really puts you off (actually you could even run custom code with Session State to pass update_streamlit
to True
every 5-10 strokes if you want).Happy drawing
Fanilo
Hi man, thank you for your awesome work!
When Iām trying to run your default demo code, I got exception info like this:
StreamlitAPIException : (āExpected bytes, got a āfloatā objectā, āConversion failed for column path with type objectā)
and it occurred here:
st.dataframe(pd.json_normalize(canvas_result.json_data[āobjectsā]))
Plus, when I uncheck update in realtime, thereās no button called āsend to streamlitā.
Can you take a look?
Btw, Iām using Steamlit 1.1.0
Hello @Sunix_Liu ! Thanks for the kind words
if canvas_result.json_data is not None:
objects = pd.json_normalize(canvas_result.json_data["objects"]) # need to convert obj to str because PyArrow
for col in objects.select_dtypes(include=['object']).columns:
objects[col] = objects[col].astype("str")
st.dataframe(objects)
because Streamlit uses Arrow to serialize dataframes, everything has to be cast out of objects. Is there a location I forgot to change this?
Do tell me if you have a better idea for a clearer icon
Happy drawing
Fanilo
@andfanilo, thank you for your prompt response.
I used the demo here:
I guess itās yet to be updated.
Btw, that icon makes me think itās download button , so I never try it.
Hi @andfanilo , actually I use it locally. By modifying the
update_streamlit=False
flag
I do not see a significant difference. I just find it strange that it has significant lag in contrast with the your demos. Regarding the Session State, is there any example showcasing its use for the canvas?
Hello! Thank you for providing Streamlit and guidance on how to use it, this package has really been a game-changer!
My question is about the centering of the images drawn in the drawing pad:
When I use the simple canvas method:
canvas_result = st_canvas(
fill_color=ārgba(255, 165, 0, 0.3)ā,
stroke_width=10,
stroke_color=āBlackā,
background_color=āWhiteā,
# width = 150,
height= 150,
key=ācanvasā,
)
I draw the image in the center; however, when I go to look at the image which I drew, it looks like this:
I should also mention I am using keras to reshape the data into to the size (600,600).
The goal was to make an app in which you could draw faces, and predict the emotions of the drawings; however, I donāt want the image to be split like this if the user decides to draw the image in the center of the drawing pad, which is the most likely place they will draw it.
If I draw slightly off to the right or left I get a centered image:
ā
Hello @Paul_Fentress,
Hmmm that is odd.
st.image(canvas_result.image_data)
what do you see?width=600
and height=600
to the st_canvas
call, so your image already has the correct size.That looks super cool, looking forward to the result!
Have a nice Streamlitinā
Fanilo
Hey Fanilo,
Thanks for the quick response!
I set the width and height to an already square shape like you suggested:
canvas_result = st_canvas(
stroke_width=10,
background_color=āWhiteā,
width = 300,
height= 300,
)
By doing this I am no longer reshaping the incoming data, and I get nice square images. Here are some examples of what I got after the images were augmented for training purposes, and this is exactly what I was trying to get:
This issue is resolved.
Thank you!
Hi @andfanilo , Iām using st_canvas but i cant display correct image (1080x1920). Please help me !!!
Thank you!! ^^
Is there a way I can override a drawing with a numpy array? It might be possible to structure it in the initial_drawing JSON form and then use it like this but that seems really complicated.
ty a lot for your awesome work btw!
Hey @foersterrobert !
Uhhh that looks a bit harder than I expected (I thought rastering an image to SVG).
What type of drawing are you envisioning to import, or type of use case you want to solve?
Fanilo
I created an MNIST-Drawer application once using your component. Now I also added the feature to generate MNIST-Digits using GANs and I would like to ādrawā the result on the canvas. So technically itās just a 28x28 tensor/array/image that I would like to resize to 280x280 pixels.
Thank you a lot btw.
Hi, I am seeing a weird behavior when using the polygon tool. I ask users to draw a polygon on the background image in order to create a mask later on and there seem to be issues with the toolbar:
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.