Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
import shutil
|
4 |
+
from PIL import Image
|
5 |
+
from nude import _process
|
6 |
+
|
7 |
+
|
8 |
+
def main():
|
9 |
+
st.title("UndressInator")
|
10 |
+
output_directory = "upload"
|
11 |
+
if not os.path.exists(output_directory):
|
12 |
+
os.makedirs(output_directory)
|
13 |
+
uploaded_file = st.file_uploader("Choose an image...", type="jpg")
|
14 |
+
if uploaded_file is not None:
|
15 |
+
for file_name in os.listdir(output_directory):
|
16 |
+
file_path = os.path.join(output_directory, file_name)
|
17 |
+
try:
|
18 |
+
if os.path.isfile(file_path):
|
19 |
+
os.unlink(file_path)
|
20 |
+
elif os.path.isdir(file_path):
|
21 |
+
shutil.rmtree(file_path)
|
22 |
+
except Exception as e:
|
23 |
+
st.error(f"Error deleting file: {e}")
|
24 |
+
image_path = os.path.join(output_directory, "input.jpg")
|
25 |
+
with open(image_path, "wb") as f:
|
26 |
+
f.write(uploaded_file.getvalue())
|
27 |
+
_process("upload/input.jpg", "upload/output.jpg", False)
|
28 |
+
st.image(image_path, caption="Uploaded Image", use_column_width=True)
|
29 |
+
st.image(Image.open("upload/output.jpg"), caption="Nude", use_column_width=True)
|
30 |
+
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
main()
|