As you may see in the download_button function, there is an if alse statement if picle_it, inside else statement there is another if else statement in which it checks the distance.
you can see that there is written that if instance is pd.DataFrame, then you should use method ‘to_csv’
you need to change it to: pd.dataframe.to_excel() for more info check it here:pandas.DataFrame.to_excel — pandas 1.2.4 documentation
Hi, I am using similar function however when I call the function, along with the Download CSV hyperlink, I also get the None. Any idea how I can fix this?
Thanks for the answer it worked perfectly. Is it possible to send the bin_str in a mail as a hyperlink? I tried but was only able to get to display the wanted text with HTML but it was not clickable
My code is:
def send_email(email_address, download_link):
sender_email = ""
password = ""
msg = MIMEMultipart("alternative")
msg["Subject"] = "Your results are in!"
msg["From"] = sender_email
msg["To"] = email_address
html_line ="""<html> random text {download_link}</html>""".format(download_link=download_link)
print(download_link)
part = MIMEText(html_line, "html")
msg.attach(part)
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login(sender_email, password)
server.sendmail(
sender_email, email_address, msg.as_string()
)
download_link is the whole href output from get_binary_file_downloader_html
st.write("Preview")
#openCV image result cropped_image which is an np array
st.image(cropped_image)
#cropped_image converted to PIL image color
result = Image.fromarray(cropped_image.astype('uint8'), 'RGB')
img = Image.open(result)
btn = st.download_button(
label="Download image",
data=img,
file_name="imagename.png",
mime="image/png")
I want to use st.download_button to download the image result I know I cannot no use the cropped_image result since an np array. I converted the image array to a PIL image but I don’t know what I need to do from here to get the result image filename or how to pass the result image to the st.download_button. Could anyone please give me some ideas how to solve this issue.