File size: 1,219 Bytes
f56ede2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import random
import os
import sys

# Add the project root directory to the Python path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))

from src.controlnet_image_generator.infer import infer


def run_inference(

    input_image,

    prompt,

    negative_prompt,

    num_steps,

    seed,

    width,

    height,

    guidance_scale,

    controlnet_conditioning_scale,

    use_random_seed=False,

):
    config_path = "configs/model_ckpts.yaml"
    
    if use_random_seed:
        seed = random.randint(0, 2 ** 32)
    
    try:
        result = infer(
            config_path=config_path,
            input_image=input_image,
            image_url=None,
            prompt=prompt,
            negative_prompt=negative_prompt,
            num_steps=num_steps,
            seed=seed,
            width=width,
            height=height,
            guidance_scale=guidance_scale,
            controlnet_conditioning_scale=float(controlnet_conditioning_scale),
        )
        result = list(result)[0]
        return result, "Inference completed successfully"
    except Exception as e:
        return [], f"Error during inference: {str(e)}"