app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import io
|
| 5 |
+
|
| 6 |
+
# Define the function to call the Hugging Face model
|
| 7 |
+
def remove_reflection(image):
|
| 8 |
+
# Convert PIL image to byte array
|
| 9 |
+
img_byte_arr = io.BytesIO()
|
| 10 |
+
image.save(img_byte_arr, format='PNG')
|
| 11 |
+
img_byte_arr = img_byte_arr.getvalue()
|
| 12 |
+
|
| 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 YOUR_HUGGING_FACE_API_KEY"},
|
| 17 |
+
data=img_byte_arr,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# Convert the response to a PIL image
|
| 21 |
+
result_image = Image.open(io.BytesIO(response.content))
|
| 22 |
+
return result_image
|
| 23 |
+
|
| 24 |
+
# Streamlit app
|
| 25 |
+
st.title("Reflection Removal App")
|
| 26 |
+
|
| 27 |
+
uploaded_file = st.file_uploader("Choose a file", type=["jpg", "jpeg", "png"])
|
| 28 |
+
|
| 29 |
+
if uploaded_file is not None:
|
| 30 |
+
image = Image.open(uploaded_file)
|
| 31 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 32 |
+
|
| 33 |
+
if st.button('Remove Reflection'):
|
| 34 |
+
result_image = remove_reflection(image)
|
| 35 |
+
st.image(result_image, caption='Processed Image', use_column_width=True)
|