SunlitDeadline commited on
Commit
1d7ca0c
·
verified ·
1 Parent(s): b9e72b4

updated app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -2,13 +2,13 @@ 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(
@@ -27,9 +27,18 @@ st.title("Reflection Removal App")
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)
 
 
 
 
2
  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):
9
+ # Read the image file
10
+ with open(image_path, "rb") as image_file:
11
+ img_byte_arr = image_file.read()
 
12
 
13
  # Send the image to the Hugging Face model
14
  response = requests.post(
 
27
  uploaded_file = st.file_uploader("Choose a file", type=["jpg", "jpeg", "png"])
28
 
29
  if uploaded_file is not None:
30
+ # Save the uploaded file to a temporary directory
31
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp_file:
32
+ tmp_file.write(uploaded_file.getvalue())
33
+ tmp_file_path = tmp_file.name
34
+
35
+ # Display the uploaded image
36
+ image = Image.open(tmp_file_path)
37
  st.image(image, caption='Uploaded Image', use_column_width=True)
38
 
39
  if st.button('Remove Reflection'):
40
+ result_image = remove_reflection(tmp_file_path)
41
+ st.image(result_image, caption='Processed Image', use_column_width=True)
42
+
43
+ # Clean up the temporary file
44
+ tmp_file.close()