File size: 2,725 Bytes
3e7ec89
32da46d
3e7ec89
1d7ca0c
a9873f9
3e7ec89
32da46d
 
3e7ec89
32da46d
3e7ec89
 
32da46d
3e7ec89
1d7ca0c
 
 
 
55a9f11
 
 
 
 
 
 
 
 
 
 
 
 
 
32da46d
1d7ca0c
 
3e7ec89
53bfd80
32da46d
 
444ccad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a9873f9
 
6aa8e15
a9873f9
 
 
 
58b5b50
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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.")