mart9992 commited on
Commit
157c221
1 Parent(s): 329b71f
Files changed (12) hide show
  1. __pycache__/main.cpython-310.pyc +0 -0
  2. babe.png +3 -0
  3. babe2.png +2 -2
  4. babe3.png +2 -2
  5. babe4.png +2 -2
  6. babe5.png +2 -2
  7. main.py +6 -2
  8. test_it.py +76 -50
  9. verrueckt.jpg +3 -0
  10. wildesweib.jpg +3 -0
  11. wweib.png +3 -0
  12. 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

  • SHA256: be04d6bc582d291dd05eeb4ad202604cf12c428563589f701ea357641a6892fe
  • Pointer size: 131 Bytes
  • Size of remote file: 748 kB
babe2.png CHANGED

Git LFS Details

  • SHA256: de461ef7f240fd6aee0580f14610dfc5c005e636d2c772d07376ecbca1194586
  • Pointer size: 131 Bytes
  • Size of remote file: 752 kB

Git LFS Details

  • SHA256: fac1f1a25ce2fc862a1098d97e85bce5e3187d1e6ec23caf50eb21b2dfba2f6b
  • Pointer size: 131 Bytes
  • Size of remote file: 748 kB
babe3.png CHANGED

Git LFS Details

  • SHA256: 6cf866d98ecd13767822c86da1be92eb6101ec228d7509d954d83557c7546f10
  • Pointer size: 131 Bytes
  • Size of remote file: 749 kB

Git LFS Details

  • SHA256: 6be7ae117cc42b155528be330e83b788e0a3c22b0268eed96d7ba5e4d10f07da
  • Pointer size: 131 Bytes
  • Size of remote file: 747 kB
babe4.png CHANGED

Git LFS Details

  • SHA256: b9c0e574b076bcee351f80ef7b8424aac8743bda54f46c17bdbcb37c3cf632b3
  • Pointer size: 131 Bytes
  • Size of remote file: 750 kB

Git LFS Details

  • SHA256: ceb1bbaa25105487e89c27809562604cd94a5bdfe2e82aedaae9a7b7839e7faa
  • Pointer size: 131 Bytes
  • Size of remote file: 750 kB
babe5.png CHANGED

Git LFS Details

  • SHA256: 75dd5b6ad1a1f7ffa677fc5b678641ad19dca77aaf1813836eab345c98deb88d
  • Pointer size: 131 Bytes
  • Size of remote file: 751 kB

Git LFS Details

  • SHA256: d62a901e986701bf85deb107dabae25779ccbb7fb1c1b5a8041408760f5e0116
  • Pointer size: 131 Bytes
  • Size of remote file: 753 kB
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.save(input_buffer, 'JPEG') # Use the appropriate format
 
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 main import get_nude
2
- import os
3
  from PIL import Image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- def create_grid_image(original, edited1, edited2):
6
- # Create a new image with appropriate size to hold the three images (original, edited1, edited2)
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

  • SHA256: a6f3ca57d8a98c254c4d03187cffe195d91b1027df6b657224c5d84e7e28863c
  • Pointer size: 130 Bytes
  • Size of remote file: 46.3 kB
wildesweib.jpg ADDED

Git LFS Details

  • SHA256: bb3e27ca80637edf3da9db7d034dd5c9b161d4aa26911acf63ac94c8dc196eba
  • Pointer size: 131 Bytes
  • Size of remote file: 398 kB
wweib.png ADDED

Git LFS Details

  • SHA256: c3635a804c28630ed82841a26e29b79bac083f44beb9bcaa5eff0e01994ecbe5
  • Pointer size: 131 Bytes
  • Size of remote file: 510 kB
wweib_mask.png ADDED

Git LFS Details

  • SHA256: 9e5e1c71321d922ca37c4481fef8aa52570596a3f7cec06a3f6accd7e7a3e4cb
  • Pointer size: 130 Bytes
  • Size of remote file: 23.5 kB