File size: 2,631 Bytes
3e7ec89
32da46d
3e7ec89
1d7ca0c
a9873f9
3e7ec89
32da46d
 
3e7ec89
32da46d
3e7ec89
 
32da46d
3e7ec89
1d7ca0c
 
 
 
32da46d
1d7ca0c
 
3e7ec89
53bfd80
32da46d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a9873f9
 
6aa8e15
a9873f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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.")