[강의 내 소스 코드]
import streamlit as st
image = "imgs\\\\2023-06-06_7-31-48.png"
st.image(image, caption="분당 중앙 공원", width=400)
import streamlit as st
import os
#디렉터리의 이미지 경로를 가져옴
def load_imags(dirs):
images = []
for filename in os.listdir(dirs):
if filename.endswith(".jpg") or filename.endswith(".png"):
images_path = os.path.join(dirs, filename)
images.append(images_path)
return images
image_dir = "imgs"
images = load_imags(image_dir)
for image in images:
st.image(image, width=500)
사전 준비
시작하기 전에 다음을 준비해야 합니다:
Streamlit 설치:
pip install streamlit
이미지 파일 준비:
코드 실행:
코드를 .py 파일(예: image_gallery.py)로 저장합니다.
터미널에서 다음 명령어로 실행합니다:
streamlit run image_gallery.py
실행 후, 브라우저에서 http://localhost:8501로 접속해 결과를 확인합니다.
코드 주요 부분 설명
import streamlit as st
import os