Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -38,16 +38,50 @@ def inference(img):
|
|
38 |
output = mainTest(inputpath, outputpath)
|
39 |
print(time.strftime("Finish!!!!!!!!! %Y-%m-%d %H:%M:%S", time.localtime()))
|
40 |
return output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
title = "Undress AI"
|
43 |
description = "β Input photos of people, similar to the test picture at the bottom, and undress pictures will be produced. You may have to wait 30 seconds for a picture. π Do not upload personal photos π There is a queue system. According to the logic of first come, first served, only one picture will be made at a time. Must be able to at least see the outline of a human body β"
|
44 |
|
45 |
examples = [
|
46 |
-
['example1.png'],
|
47 |
-
['example2.png'],
|
48 |
-
['example3.png'],
|
49 |
-
['example5.webp'],
|
50 |
-
['example6.webp'],
|
51 |
]
|
52 |
|
53 |
css = """
|
|
|
38 |
output = mainTest(inputpath, outputpath)
|
39 |
print(time.strftime("Finish!!!!!!!!! %Y-%m-%d %H:%M:%S", time.localtime()))
|
40 |
return output
|
41 |
+
from PIL import Image
|
42 |
+
|
43 |
+
def load_image_from_file(file_path, new_height=None):
|
44 |
+
"""
|
45 |
+
Load an image from a file and optionally resize it while maintaining the aspect ratio.
|
46 |
+
|
47 |
+
Args:
|
48 |
+
file_path (str): The path to the image file.
|
49 |
+
new_height (int, optional): The new height for the image. If None, the image is not resized.
|
50 |
+
|
51 |
+
Returns:
|
52 |
+
Image: The loaded (and optionally resized) image.
|
53 |
+
"""
|
54 |
+
try:
|
55 |
+
img = Image.open(file_path)
|
56 |
+
|
57 |
+
if new_height is not None:
|
58 |
+
# Calculate new width to maintain aspect ratio
|
59 |
+
aspect_ratio = img.width / img.height
|
60 |
+
new_width = int(new_height * aspect_ratio)
|
61 |
+
|
62 |
+
# Resize the image
|
63 |
+
img = img.resize((new_width, new_height), Image.LANCZOS)
|
64 |
+
|
65 |
+
return img
|
66 |
+
except FileNotFoundError:
|
67 |
+
print(f"File not found: {file_path}")
|
68 |
+
return None
|
69 |
+
except Image.UnidentifiedImageError:
|
70 |
+
print(f"Cannot identify image file: {file_path}")
|
71 |
+
return None
|
72 |
+
except Exception as e:
|
73 |
+
print(f"Error loading image from file: {e}")
|
74 |
+
return None
|
75 |
|
76 |
title = "Undress AI"
|
77 |
description = "β Input photos of people, similar to the test picture at the bottom, and undress pictures will be produced. You may have to wait 30 seconds for a picture. π Do not upload personal photos π There is a queue system. According to the logic of first come, first served, only one picture will be made at a time. Must be able to at least see the outline of a human body β"
|
78 |
|
79 |
examples = [
|
80 |
+
[load_image_from_file('example1.png')],
|
81 |
+
[load_image_from_file('example2.png')],
|
82 |
+
[load_image_from_file('example3.png')],
|
83 |
+
[load_image_from_file('example5.webp')],
|
84 |
+
[load_image_from_file('example6.webp')],
|
85 |
]
|
86 |
|
87 |
css = """
|