import streamlit as st import subprocess from PIL import Image import tempfile import os # Streamlit app title st.title("Reflection Removal App") # File upload section uploaded_file = st.file_uploader("Choose a file", type=["jpg", "jpeg", "png"]) # Display uploaded image if available if uploaded_file is not None: # Save the uploaded file to a temporary directory with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp_file: tmp_file.write(uploaded_file.getvalue()) tmp_file_path = tmp_file.name # Display the uploaded image image = Image.open(tmp_file_path) st.image(image, caption='Uploaded Image', use_column_width=True) # Define constants or variables for model execution MODEL_NAME = 'dsrnet_s' MODEL_PATH = 'dsrnet_model_sirs' DATASET = 'sirs_dataset' NAME = 'dsrnet_s_test' BASE_DIR = tmp_file_path WEIGHT_PATH = "./weights/dsrnet_s_epoch14.pt" # Function to run the command def run_command(command): process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) stdout, stderr = process.communicate() return stdout, stderr # Command execution st.write(f"Running command: python ./DSRNet/test_sirs.py --inet {MODEL_NAME} --model {MODEL_PATH} --dataset {DATASET} --name {NAME} --hyper --if_align --base_dir '{BASE_DIR} --resume --weight_path WEIGHT_PATH'") stdout, stderr = run_command(f"python ./DSRNet/test_sirs.py --inet {MODEL_NAME} --model {MODEL_PATH} --dataset {DATASET} --name {NAME} --hyper --if_align --base_dir '{BASE_DIR} --resume --weight_path WEIGHT_PATH'") # Display command output st.write("Command Output:") st.code(stdout.decode('utf-8')) # Display error if any if stderr: st.error(stderr.decode('utf-8')) # Search for image ending with '_l' in subdirectories of 'checkpoints' checkpoints_dir = './test' # Update this path according to your project structure # Function to recursively find image ending with '_l' # Find the image file desired_image = './test/dsrnet_s_l.png' # Display the found image if available if desired_image is not None: st.write("Found Image:") image_l = Image.open(desired_image) st.image(image_l, caption='Image ending with _l', use_column_width=True) else: st.write("Image ending with _l not found in checkpoints directory.")