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 #writing to text file # ######################### file = open("uploaded_img.txt", "w") # Write data to the file file.write(tmp_file.name) file.write("This is a second line.\n") # Close the file file.close() # 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 = './real45' WEIGHT_PATH = './weights/dsrnet_s_epoch14.pt' # Function to run the command def run_command(command): try: process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) stdout, stderr = process.communicate() return stdout.decode('utf-8'), stderr.decode('utf-8') except Exception as e: return "", str(e) # Command to execute 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 running command st.write(f"Running command: {command}") # Execute the command stdout, stderr = run_command(command) # Display command output st.write("Command Output:") if stdout: st.code(stdout) if stderr: st.error(f"Command Error:\n{stderr}") # 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.")