Aklavya commited on
Commit
36a1c8b
·
verified ·
1 Parent(s): 0f2cda2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -62,14 +62,14 @@ def swap_faces(destination_image, source_image):
62
  except MemoryError:
63
  return "Memory error: Face swapping operation failed due to memory overload."
64
 
65
- # Sharpen the output image by 20%
66
- kernel = np.array([[0, -1, 0],
67
- [-1, 5, -1],
68
- [0, -1, 0]])
69
- sharpened_res = cv2.filter2D(res, -1, kernel)
70
 
71
  # Add smoothing (blurring) for a more natural look
72
- smoothed_res = cv2.GaussianBlur(sharpened_res, (5, 5), 0)
73
 
74
  # Convert the result to RGB for display in Streamlit
75
  smoothed_res_rgb = cv2.cvtColor(smoothed_res, cv2.COLOR_BGR2RGB)
@@ -78,7 +78,7 @@ def swap_faces(destination_image, source_image):
78
 
79
  # Streamlit app layout
80
  def main():
81
- st.set_page_config(page_title="SnapSwap", page_icon=":camera:")
82
 
83
  # CSS for styling
84
  st.markdown("""
@@ -99,14 +99,14 @@ def main():
99
  """, unsafe_allow_html=True)
100
 
101
  # Page Header (outside sidebar)
102
- st.header("SnapSwap :camera:")
103
  st.write("Welcome to the face swapping app! Upload two images and watch the magic happen!")
104
 
105
  # Sidebar for file uploads and instructions
106
  with st.sidebar:
107
- st.subheader("Upload Images for Face Swapping and then click Swap Faces button")
108
- source_image = st.file_uploader("Upload Source Image", type=["jpg", "png", "jpeg"])
109
  destination_image = st.file_uploader("Upload Destination Image", type=["jpg", "png", "jpeg"])
 
110
 
111
  if destination_image and source_image:
112
  # Check if destination image contains adult content
@@ -132,7 +132,7 @@ def main():
132
  # Instructions on how to use the app (below upload buttons and swap button)
133
  st.subheader("How to Use the App:")
134
  st.markdown("""
135
- 1. **Upload the source and destination images**: Select the images you want to use for face swapping.
136
  2. **Click on the \"Swap Faces\" button**: The app will process the images and swap the faces.
137
  3. **View the output**: The swapped face image will appear after processing.
138
  """)
@@ -142,8 +142,8 @@ def main():
142
  st.image(st.session_state.result, caption="Swapped Face", use_container_width=True)
143
 
144
  # Footer with credits
145
- st.markdown("Developed with ❤ by Aklavya")
146
 
147
  # Run the app
148
  if __name__ == '__main__':
149
- main()
 
62
  except MemoryError:
63
  return "Memory error: Face swapping operation failed due to memory overload."
64
 
65
+ # Commented sharpening for testing purposes
66
+ # kernel = np.array([[0, -1, 0],
67
+ # [-1, 5, -1],
68
+ # [0, -1, 0]])
69
+ # sharpened_res = cv2.filter2D(res, -1, kernel)
70
 
71
  # Add smoothing (blurring) for a more natural look
72
+ smoothed_res = cv2.GaussianBlur(res, (5, 5), 0)
73
 
74
  # Convert the result to RGB for display in Streamlit
75
  smoothed_res_rgb = cv2.cvtColor(smoothed_res, cv2.COLOR_BGR2RGB)
 
78
 
79
  # Streamlit app layout
80
  def main():
81
+ st.set_page_config(page_title="Face Swapping", page_icon=":camera:")
82
 
83
  # CSS for styling
84
  st.markdown("""
 
99
  """, unsafe_allow_html=True)
100
 
101
  # Page Header (outside sidebar)
102
+ st.header("Face Swapping App :camera:")
103
  st.write("Welcome to the face swapping app! Upload two images and watch the magic happen!")
104
 
105
  # Sidebar for file uploads and instructions
106
  with st.sidebar:
107
+ st.subheader("Upload Images for Face Swapping")
 
108
  destination_image = st.file_uploader("Upload Destination Image", type=["jpg", "png", "jpeg"])
109
+ source_image = st.file_uploader("Upload Source Image", type=["jpg", "png", "jpeg"])
110
 
111
  if destination_image and source_image:
112
  # Check if destination image contains adult content
 
132
  # Instructions on how to use the app (below upload buttons and swap button)
133
  st.subheader("How to Use the App:")
134
  st.markdown("""
135
+ 1. **Upload the destination and source images**: Select the images you want to use for face swapping.
136
  2. **Click on the \"Swap Faces\" button**: The app will process the images and swap the faces.
137
  3. **View the output**: The swapped face image will appear after processing.
138
  """)
 
142
  st.image(st.session_state.result, caption="Swapped Face", use_container_width=True)
143
 
144
  # Footer with credits
145
+ st.markdown("Developed with ❤ by [Your Name]")
146
 
147
  # Run the app
148
  if __name__ == '__main__':
149
+ main()