Spaces:
Runtime error
Runtime error
import streamlit as st | |
import os | |
from PIL import Image | |
# Define the path to the folder | |
FIRE_SHOT_FOLDER = os.path.join(os.getcwd(), 'FireShot') | |
# Ensure the folder exists | |
if not os.path.exists(FIRE_SHOT_FOLDER): | |
st.error("FireShot folder does not exist!") | |
else: | |
st.success(f"FireShot folder found at {FIRE_SHOT_FOLDER}") | |
# Display a file uploader | |
uploaded_file = st.file_uploader("Browse images from FireShot", type=["jpg", "png", "jpeg"]) | |
# If the user uploads a file, save it in the FireShot folder | |
if uploaded_file is not None: | |
img = Image.open(uploaded_file) | |
st.image(img, caption="Uploaded Image", use_column_width=True) | |
# Save the image to FireShot folder | |
file_path = os.path.join(FIRE_SHOT_FOLDER, uploaded_file.name) | |
img.save(file_path) | |
st.success(f"Image saved to {file_path}") | |
# Optionally, display all images from the FireShot folder | |
if st.button("Show all images in FireShot folder"): | |
image_files = [f for f in os.listdir(FIRE_SHOT_FOLDER) if f.endswith(('jpg', 'jpeg', 'png'))] | |
if image_files: | |
for image_file in image_files: | |
img_path = os.path.join(FIRE_SHOT_FOLDER, image_file) | |
img = Image.open(img_path) | |
st.image(img, caption=image_file, use_column_width=True) | |
else: | |
st.info("No images found in FireShot folder.") |