-1

This is because I have tried using the code below but when I run my web app no image is displayed. Note that this program is written on notepad++ ,,,

    #import the libraries.
    import streamlit as st
    import pandas as pd

    # insert Image.
    from IPython.display import Image
    Image("Desktop\stock.jpg")
Blak040
  • 7
  • 3

2 Answers2

0

you can do the following:
Make sure that the path of the image is the same as the path of the project folder and work on fixing the code for displaying the image

from IPython.display import Image
Image(filename='test.png') 

If the solution does not work, try to go to this question ref: How can I display an image from a file in Jupyter Notebook?

CodeView
  • 498
  • 3
  • 14
  • 1
    Can you explain ***why*** this solves the problem? According to [the docs](https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.Image), calling without the keyword will pass the argument to `data` which says: *"The raw image data or a URL or filename to load the data from"* so it seems to be fine – Tomerikoo Aug 23 '21 at 16:13
  • I modified the answer, I think it answers your request. Thank you – CodeView Aug 23 '21 at 17:09
0

To display images in Streamlit, you can use st.image:

https://docs.streamlit.io/en/stable/api.html?highlight=image#streamlit.image

import streamlit as st

st.image('sunrise.jpg')

#or, if you are processing the bytes

from PIL import Image
image = Image.open('sunrise.jpg')

st.image(image, caption='Sunrise by the mountains')
Randy Zwitch
  • 1,994
  • 1
  • 11
  • 19