Update app.py
Browse files
app.py
CHANGED
|
@@ -1,74 +1,46 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
from PIL import Image
|
| 4 |
-
import io
|
| 5 |
import tempfile
|
| 6 |
-
import subprocess
|
| 7 |
-
'''
|
| 8 |
-
|
| 9 |
-
# Define the function to call the Hugging Face model
|
| 10 |
-
def remove_reflection(image_path):
|
| 11 |
-
# Read the image file
|
| 12 |
-
with open(image_path, "rb") as image_file:
|
| 13 |
-
img_byte_arr = image_file.read()
|
| 14 |
-
|
| 15 |
-
# Send the image to the Hugging Face model
|
| 16 |
-
response = requests.post(
|
| 17 |
-
"https://api-inference.huggingface.co/models/your-model-name",
|
| 18 |
-
headers={"Authorization": "Bearer hf_API_Key"},
|
| 19 |
-
data=img_byte_arr,
|
| 20 |
-
)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
return result_image
|
| 25 |
-
|
| 26 |
-
# Streamlit app
|
| 27 |
-
st.title("Reflection Removal App")'''
|
| 28 |
|
|
|
|
| 29 |
uploaded_file = st.file_uploader("Choose a file", type=["jpg", "jpeg", "png"])
|
| 30 |
|
|
|
|
| 31 |
if uploaded_file is not None:
|
| 32 |
# Save the uploaded file to a temporary directory
|
| 33 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp_file:
|
| 34 |
tmp_file.write(uploaded_file.getvalue())
|
| 35 |
tmp_file_path = tmp_file.name
|
| 36 |
-
|
| 37 |
# Display the uploaded image
|
| 38 |
image = Image.open(tmp_file_path)
|
| 39 |
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 40 |
-
|
| 41 |
-
'''if st.button('Remove Reflection'):
|
| 42 |
-
result_image = remove_reflection(tmp_file_path)
|
| 43 |
-
st.image(result_image, caption='Processed Image', use_column_width=True)
|
| 44 |
-
|
| 45 |
-
# Clean up the temporary file
|
| 46 |
-
tmp_file.close()'''
|
| 47 |
|
| 48 |
-
# Define constants or variables
|
| 49 |
-
MODEL_NAME = 'dsrnet_s'
|
| 50 |
-
MODEL_PATH = 'dsrnet_model_sirs'
|
| 51 |
-
DATASET = 'sirs_dataset'
|
| 52 |
-
NAME = 'dsrnet_s_test'
|
| 53 |
-
BASE_DIR = tmp_file_path
|
| 54 |
-
|
| 55 |
-
#
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
# Display error if any
|
| 73 |
-
if stderr:
|
| 74 |
-
st.error(stderr.decode('utf-8'))
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import subprocess
|
| 3 |
from PIL import Image
|
|
|
|
| 4 |
import tempfile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# Streamlit app title
|
| 7 |
+
st.title("Reflection Removal App")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# File upload section
|
| 10 |
uploaded_file = st.file_uploader("Choose a file", type=["jpg", "jpeg", "png"])
|
| 11 |
|
| 12 |
+
# Display uploaded image if available
|
| 13 |
if uploaded_file is not None:
|
| 14 |
# Save the uploaded file to a temporary directory
|
| 15 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp_file:
|
| 16 |
tmp_file.write(uploaded_file.getvalue())
|
| 17 |
tmp_file_path = tmp_file.name
|
| 18 |
+
|
| 19 |
# Display the uploaded image
|
| 20 |
image = Image.open(tmp_file_path)
|
| 21 |
st.image(image, caption='Uploaded Image', use_column_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# Define constants or variables for model execution
|
| 24 |
+
MODEL_NAME = 'dsrnet_s'
|
| 25 |
+
MODEL_PATH = 'dsrnet_model_sirs'
|
| 26 |
+
DATASET = 'sirs_dataset'
|
| 27 |
+
NAME = 'dsrnet_s_test'
|
| 28 |
+
BASE_DIR = tmp_file_path
|
| 29 |
+
|
| 30 |
+
# Function to run the command
|
| 31 |
+
def run_command(command):
|
| 32 |
+
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
| 33 |
+
stdout, stderr = process.communicate()
|
| 34 |
+
return stdout, stderr
|
| 35 |
+
|
| 36 |
+
# Command execution
|
| 37 |
+
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}'")
|
| 38 |
+
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}'")
|
| 39 |
+
|
| 40 |
+
# Display command output
|
| 41 |
+
st.write("Command Output:")
|
| 42 |
+
st.code(stdout.decode('utf-8'))
|
| 43 |
+
|
| 44 |
+
# Display error if any
|
| 45 |
+
if stderr:
|
| 46 |
+
st.error(stderr.decode('utf-8'))
|
|
|
|
|
|
|
|
|