Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import requests
|
|
| 3 |
from PIL import Image
|
| 4 |
import io
|
| 5 |
import tempfile
|
|
|
|
| 6 |
|
| 7 |
# Define the function to call the Hugging Face model
|
| 8 |
def remove_reflection(image_path):
|
|
@@ -13,7 +14,7 @@ def remove_reflection(image_path):
|
|
| 13 |
# Send the image to the Hugging Face model
|
| 14 |
response = requests.post(
|
| 15 |
"https://api-inference.huggingface.co/models/your-model-name",
|
| 16 |
-
headers={"Authorization": "Bearer
|
| 17 |
data=img_byte_arr,
|
| 18 |
)
|
| 19 |
|
|
@@ -41,4 +42,32 @@ if uploaded_file is not None:
|
|
| 41 |
st.image(result_image, caption='Processed Image', use_column_width=True)
|
| 42 |
|
| 43 |
# Clean up the temporary file
|
| 44 |
-
tmp_file.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import io
|
| 5 |
import tempfile
|
| 6 |
+
'''
|
| 7 |
|
| 8 |
# Define the function to call the Hugging Face model
|
| 9 |
def remove_reflection(image_path):
|
|
|
|
| 14 |
# Send the image to the Hugging Face model
|
| 15 |
response = requests.post(
|
| 16 |
"https://api-inference.huggingface.co/models/your-model-name",
|
| 17 |
+
headers={"Authorization": "Bearer hf_API_Key"},
|
| 18 |
data=img_byte_arr,
|
| 19 |
)
|
| 20 |
|
|
|
|
| 42 |
st.image(result_image, caption='Processed Image', use_column_width=True)
|
| 43 |
|
| 44 |
# Clean up the temporary file
|
| 45 |
+
tmp_file.close()'''
|
| 46 |
+
|
| 47 |
+
# Define constants or variables
|
| 48 |
+
MODEL_NAME = 'dsrnet_s'
|
| 49 |
+
MODEL_PATH = 'dsrnet_model_sirs'
|
| 50 |
+
DATASET = 'sirs_dataset'
|
| 51 |
+
NAME = 'dsrnet_s_test'
|
| 52 |
+
BASE_DIR = tmp_file_path
|
| 53 |
+
|
| 54 |
+
# Streamlit UI components
|
| 55 |
+
st.title('Hugging Face Reflection Eraser')
|
| 56 |
+
|
| 57 |
+
# Function to run the command
|
| 58 |
+
def run_command(command):
|
| 59 |
+
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
| 60 |
+
stdout, stderr = process.communicate()
|
| 61 |
+
return stdout, stderr
|
| 62 |
+
|
| 63 |
+
# Command execution
|
| 64 |
+
st.write(f"Running command: './DSRNet/test_sirs.py' --inet {MODEL_NAME} --model {MODEL_PATH} --dataset {DATASET} --name {NAME} --hyper --if_align --base_dir '{BASE_DIR}'")
|
| 65 |
+
stdout, stderr = run_command(f"python test_sirs.py --inet {MODEL_NAME} --model {MODEL_PATH} --dataset {DATASET} --name {NAME} --hyper --if_align --base_dir '{BASE_DIR}'")
|
| 66 |
+
|
| 67 |
+
# Display command output
|
| 68 |
+
st.write("Command Output:")
|
| 69 |
+
st.code(stdout.decode('utf-8'))
|
| 70 |
+
|
| 71 |
+
# Display error if any
|
| 72 |
+
if stderr:
|
| 73 |
+
st.error(stderr.decode('utf-8'))
|