maaz21 commited on
Commit
1cb76bb
·
verified ·
1 Parent(s): 38f7bfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import streamlit as st
2
- from rembg import remove
3
  from PIL import Image
4
  import io
5
  import fitz # PyMuPDF for handling PDFs
@@ -25,9 +25,12 @@ if uploaded_file is not None:
25
 
26
  st.image(image, caption="Original Image", use_column_width=True)
27
 
28
- # Remove background using HQ model
 
 
 
29
  with st.spinner("Removing background with high quality..."):
30
- output_image = remove(image, model_name="u2net_hq") # Use the HQ model
31
 
32
  st.image(output_image, caption="Background Removed", use_column_width=True)
33
 
@@ -37,4 +40,4 @@ if uploaded_file is not None:
37
  st.download_button("Download Image", img_byte_arr.getvalue(), file_name="no_bg_image.png", mime="image/png")
38
 
39
  st.markdown("---")
40
- st.markdown("💡 Developed with ❤️ using Streamlit and rembg (U2Net HQ)")
 
1
  import streamlit as st
2
+ from rembg import remove, new_session
3
  from PIL import Image
4
  import io
5
  import fitz # PyMuPDF for handling PDFs
 
25
 
26
  st.image(image, caption="Original Image", use_column_width=True)
27
 
28
+ # Create a high-quality model session
29
+ session = new_session("u2net_hq") # Load the HQ model
30
+
31
+ # Remove background using the HQ model
32
  with st.spinner("Removing background with high quality..."):
33
+ output_image = remove(image, session=session)
34
 
35
  st.image(output_image, caption="Background Removed", use_column_width=True)
36
 
 
40
  st.download_button("Download Image", img_byte_arr.getvalue(), file_name="no_bg_image.png", mime="image/png")
41
 
42
  st.markdown("---")
43
+ st.markdown("💡 Developed with ❤️ using Streamlit and rembg (U2Net HQ)")