aa
Browse files- __pycache__/main.cpython-310.pyc +0 -0
- babe.png +3 -0
- babe2.png +2 -2
- babe3.png +2 -2
- babe4.png +2 -2
- babe5.png +2 -2
- main.py +6 -2
- test_it.py +76 -50
- verrueckt.jpg +3 -0
- wildesweib.jpg +3 -0
- wweib.png +3 -0
- wweib_mask.png +3 -0
__pycache__/main.cpython-310.pyc
CHANGED
Binary files a/__pycache__/main.cpython-310.pyc and b/__pycache__/main.cpython-310.pyc differ
|
|
babe.png
ADDED
Git LFS Details
|
babe2.png
CHANGED
Git LFS Details
|
Git LFS Details
|
babe3.png
CHANGED
Git LFS Details
|
Git LFS Details
|
babe4.png
CHANGED
Git LFS Details
|
Git LFS Details
|
babe5.png
CHANGED
Git LFS Details
|
Git LFS Details
|
main.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from io import BytesIO
|
|
|
2 |
import random
|
3 |
|
4 |
import requests
|
@@ -54,8 +55,9 @@ def get_mask_replicate(input_pil, positive_prompt, expand_by=0, negative_prompt=
|
|
54 |
}
|
55 |
|
56 |
s3filepath = f"target/{os.urandom(20).hex()}.png"
|
57 |
-
input_buffer = BytesIO()
|
58 |
-
input_pil.
|
|
|
59 |
input_buffer.seek(0)
|
60 |
s3.put_object(Bucket=S3_BUCKET_NAME, Key=s3filepath, Body=input_buffer)
|
61 |
|
@@ -276,6 +278,8 @@ def get_nude(original_pil, original_max_size=2000, generate_max_size=768, positi
|
|
276 |
person_cropped_pil = crop_to_coords(
|
277 |
crop_coord_1, crop_coord_2, small_original_image)
|
278 |
|
|
|
|
|
279 |
expanded_mask_image = get_mask_replicate(
|
280 |
person_cropped_pil, "bra . blouse . skirt . dress", negative_prompt="face", expand_by=10, replicate_api_key=replicate_api_key)
|
281 |
|
|
|
1 |
from io import BytesIO
|
2 |
+
import io
|
3 |
import random
|
4 |
|
5 |
import requests
|
|
|
55 |
}
|
56 |
|
57 |
s3filepath = f"target/{os.urandom(20).hex()}.png"
|
58 |
+
input_buffer = io.BytesIO()
|
59 |
+
input_pil = input_pil.convert("RGB") # Convert to RGB if it's not
|
60 |
+
input_pil.save(input_buffer, 'PNG')
|
61 |
input_buffer.seek(0)
|
62 |
s3.put_object(Bucket=S3_BUCKET_NAME, Key=s3filepath, Body=input_buffer)
|
63 |
|
|
|
278 |
person_cropped_pil = crop_to_coords(
|
279 |
crop_coord_1, crop_coord_2, small_original_image)
|
280 |
|
281 |
+
person_cropped_pil.save("verrueckt.jpg")
|
282 |
+
|
283 |
expanded_mask_image = get_mask_replicate(
|
284 |
person_cropped_pil, "bra . blouse . skirt . dress", negative_prompt="face", expand_by=10, replicate_api_key=replicate_api_key)
|
285 |
|
test_it.py
CHANGED
@@ -1,52 +1,78 @@
|
|
1 |
-
from
|
2 |
-
import os
|
3 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
width, height = original.size
|
8 |
-
grid = Image.new('RGB', (width, height * 3))
|
9 |
-
|
10 |
-
# Paste the original and edited images into the grid
|
11 |
-
grid.paste(original, (0, 0))
|
12 |
-
grid.paste(edited1, (0, height))
|
13 |
-
grid.paste(edited2, (0, height * 2))
|
14 |
-
|
15 |
-
return grid
|
16 |
-
|
17 |
-
def process_images(input_dir, output_dir, edit_function):
|
18 |
-
# Create the output directory if it doesn't exist
|
19 |
-
if not os.path.exists(output_dir):
|
20 |
-
os.makedirs(output_dir)
|
21 |
-
|
22 |
-
# Loop through all files in the input directory
|
23 |
-
for filename in os.listdir(input_dir):
|
24 |
-
print(f"Processing {filename}")
|
25 |
-
if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
|
26 |
-
base_filename, file_extension = os.path.splitext(filename)
|
27 |
-
grid_filename = f"{base_filename}1{file_extension}"
|
28 |
-
|
29 |
-
if os.path.exists(os.path.join(output_dir, grid_filename)):
|
30 |
-
print(f"Skipping {filename}, already exists in output directory")
|
31 |
-
continue
|
32 |
-
|
33 |
-
# Construct full file path
|
34 |
-
file_path = os.path.join(input_dir, filename)
|
35 |
-
|
36 |
-
# Process the image
|
37 |
-
original = Image.open(file_path)
|
38 |
-
try:
|
39 |
-
edited_images = edit_function(original)
|
40 |
-
except Exception as e:
|
41 |
-
print(f"Error processing {filename}: {e}")
|
42 |
-
continue
|
43 |
-
|
44 |
-
# Create the grid image
|
45 |
-
grid_image = create_grid_image(original, edited_images[0], edited_images[1])
|
46 |
-
|
47 |
-
# Save the grid image
|
48 |
-
grid_image.save(os.path.join(output_dir, grid_filename))
|
49 |
-
|
50 |
-
print(f"Saved {grid_filename}")
|
51 |
-
|
52 |
-
process_images('./dataset', './dataset_result_grids', get_nude)
|
|
|
1 |
+
from io import BytesIO
|
|
|
2 |
from PIL import Image
|
3 |
+
import requests
|
4 |
+
import time
|
5 |
+
import os
|
6 |
+
import boto3
|
7 |
+
|
8 |
+
|
9 |
+
S3_REGION = "fra1"
|
10 |
+
S3_ACCESS_ID = "0RN7BZXS59HYSBD3VB79"
|
11 |
+
S3_ACCESS_SECRET = "hfSPgBlWl5jsGHa2xuByVkSpancgVeA2CVQf2EMp"
|
12 |
+
S3_ENDPOINT_URL = "https://s3.solarcom.ch"
|
13 |
+
S3_BUCKET_NAME = "pissnelke"
|
14 |
+
|
15 |
+
s3_session = boto3.session.Session()
|
16 |
+
s3 = s3_session.client(
|
17 |
+
service_name="s3",
|
18 |
+
region_name=S3_REGION,
|
19 |
+
aws_access_key_id=S3_ACCESS_ID,
|
20 |
+
aws_secret_access_key=S3_ACCESS_SECRET,
|
21 |
+
endpoint_url=S3_ENDPOINT_URL,
|
22 |
+
)
|
23 |
+
|
24 |
+
def get_mask_replicate(input_pil, positive_prompt, expand_by=0, negative_prompt="", replicate_api_key=""):
|
25 |
+
# Set up the API endpoint and headers
|
26 |
+
api_endpoint = "https://api.replicate.com/v1/predictions"
|
27 |
+
headers = {
|
28 |
+
"Authorization": f"Token {replicate_api_key}"
|
29 |
+
}
|
30 |
+
|
31 |
+
s3filepath = f"target/{os.urandom(20).hex()}.png"
|
32 |
+
input_buffer = BytesIO()
|
33 |
+
input_pil.save(input_buffer, 'JPEG') # Use the appropriate format
|
34 |
+
input_buffer.seek(0)
|
35 |
+
s3.put_object(Bucket=S3_BUCKET_NAME, Key=s3filepath, Body=input_buffer)
|
36 |
+
|
37 |
+
# Prepare the data for the POST request
|
38 |
+
data = {
|
39 |
+
"version": "ee871c19efb1941f55f66a3d7d960428c8a5afcb77449547fe8e5a3ab9ebc21c",
|
40 |
+
"input": {
|
41 |
+
"image": f"{S3_ENDPOINT_URL}/{S3_BUCKET_NAME}/{s3filepath}",
|
42 |
+
"mask_prompt": positive_prompt,
|
43 |
+
"negative_mask_prompt": negative_prompt,
|
44 |
+
"adjustment_factor": expand_by,
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
# Make the initial POST request
|
49 |
+
response = requests.post(api_endpoint, json=data, headers=headers)
|
50 |
+
response_data = response.json()
|
51 |
+
|
52 |
+
print(response_data)
|
53 |
+
|
54 |
+
# Check the status of the prediction and wait for completion
|
55 |
+
while True:
|
56 |
+
prediction_response = requests.get(f"{api_endpoint}/{response_data['id']}", headers=headers)
|
57 |
+
prediction_data = prediction_response.json()
|
58 |
+
|
59 |
+
if prediction_data['status'] == 'failed':
|
60 |
+
raise Exception(prediction_data.get('error'))
|
61 |
+
|
62 |
+
if prediction_data.get('status') == 'succeeded':
|
63 |
+
output_link = prediction_data['output'][2]
|
64 |
+
break
|
65 |
+
|
66 |
+
time.sleep(1) # Avoid spamming the server, wait for a bit before the next status check
|
67 |
+
|
68 |
+
# Get the output image
|
69 |
+
output_response = requests.get(output_link)
|
70 |
+
image_data = BytesIO(output_response.content)
|
71 |
+
|
72 |
+
# Use PIL to handle the image
|
73 |
+
output_image = Image.open(image_data)
|
74 |
+
|
75 |
+
return output_image
|
76 |
|
77 |
+
verrueckt_pil = Image.open("verrueckt.jpg")
|
78 |
+
get_mask_replicate(verrueckt_pil, "person", replicate_api_key="r8_GTeyENFqfOXFAI0COiGlB2RkhqEzqS64XBuIk")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verrueckt.jpg
ADDED
Git LFS Details
|
wildesweib.jpg
ADDED
Git LFS Details
|
wweib.png
ADDED
Git LFS Details
|
wweib_mask.png
ADDED
Git LFS Details
|