File size: 1,964 Bytes
732b864
 
 
 
 
807c35c
 
732b864
807c35c
732b864
 
 
807c35c
732b864
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
807c35c
 
732b864
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import io
import requests
from PIL import Image

def remove_image_watermark(input):
    image = input["image"].convert("RGB")
    mask = input["mask"].convert("RGB")
    image_data = io.BytesIO()
    image.save(image_data, format="JPEG")
    image_data = image_data.getvalue()

    mask_data = io.BytesIO()
    mask.save(mask_data, format="JPEG")
    mask_data = mask_data.getvalue()

    # Prepare form data
    form_data = {
            'ldmSteps': 25,
            'ldmSampler': 'plms',
            'zitsWireframe': True,
            'hdStrategy': 'Original',
            'hdStrategyCropMargin': 196,
            'hdStrategyCropTrigerSize': 1280,
            'hdStrategyResizeLimit': 2048,
            'prompt': '',
            'negativePrompt': '',
            'croperX': -24,
            'croperY': -23,
            'croperHeight': 512,
            'croperWidth': 512,
            'useCroper': False,
            'sdMaskBlur': 5,
            'sdStrength': 0.75,
            'sdSteps': 50,
            'sdGuidanceScale': 7.5,
            'sdSampler': 'pndm',
            'sdSeed': 42,
            'sdMatchHistograms': False,
            'sdScale': 1,
            'cv2Radius': 5,
            'cv2Flag': 'INPAINT_NS',
            'paintByExampleSteps': 50,
            'paintByExampleGuidanceScale': 7.5,
            'paintByExampleSeed': 42,
            'paintByExampleMaskBlur': 5,
            'paintByExampleMatchHistograms': False,
            'sizeLimit': 1024,
        }

    files_data = {
        'image': ('image.jpg', image_data),
        'mask': ('mask.jpg', mask_data),
    }

    response = requests.post('https://ahmedghani-lama-cleaner-lama.hf.space/inpaint', data=form_data, files=files_data)

    if response.headers['Content-Type'] == 'image/jpeg' or response.headers['Content-Type'] == 'image/png':
        image = Image.open(io.BytesIO(response.content))
        return image
    else:
        print(f"Error processing Image: {response.text}")