SunlitDeadline's picture
Update app.py
6aa8e15 verified
Raw History Blame Contribute Delete
2.63 kB
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
# 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}'")
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}'")
# 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'
def find_image_in_subdirs(root_dir):
for root, dirs, files in os.walk(root_dir):
for filename in files:
if filename.endswith('_l.png'): # Adjust file extension if needed
return os.path.join(root, filename)
return None
# Find the image file
desired_image = find_image_in_subdirs(checkpoints_dir)
# 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.")