PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.3
Kubio AI Page Builder v2.8.3
2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / AI / SDApi / KubioImageGenerate.php
kubio / lib / AI / SDApi Last commit date
KubioCloudSDApi.php 1 year ago KubioImageGenerate.php 1 year ago KubioImageManager.php 1 year ago KubioImagePrompts.php 2 years ago KubioImageSearch.php 1 year ago sd-endpoints.php 1 year ago
KubioImageGenerate.php
101 lines
1 <?php
2 namespace Kubio\Ai;
3 class KubioImageGenerate {
4 private $api = null;
5 private $negative_prompt = 'worst quality, normal quality, low quality, low res, blurry, text, watermark, logo, banner, extra digits, cropped, jpeg artifacts, signature, username, error, sketch ,duplicate, ugly, monochrome, horror, geometry, mutation, disgusting, camera';
6
7 function __construct( $api_key = false, $api_model = false, $api_dummy_response = false ) {
8 $this->api = new KubioCloudSDApi( $api_key, $api_model, $api_dummy_response );
9 }
10
11 public function mask( array $data, $image_prompt, $settings = array() ) {
12 $this->api->set_api_endpoint( 'v1/image-generation/mask' );
13 $data = $this->prepare_data( $data, $image_prompt );
14
15 $response = $this->post(
16 $data,
17 $settings
18 );
19
20 return $response;
21 }
22
23 public function variations( array $data, $image_prompt, $settings = array() ) {
24 $this->api->set_api_endpoint( 'v1/image-generation/image-to-image' );
25
26 $data = $this->prepare_data( $data, $image_prompt );
27
28 $response = $this->post(
29 $data,
30 $settings
31 );
32
33 return $response;
34 }
35
36 public function samples( array $data, $image_prompt, $settings = array() ) {
37 $this->api->set_api_endpoint( 'v1/image-generation/text-to-image' );
38
39 $data = $this->prepare_data( $data, $image_prompt );
40
41 $response = $this->post(
42 $data,
43 $settings
44 );
45
46 return $response;
47 }
48
49 private function prepare_data( $data, $image_prompt ) {
50 if ( is_array( $image_prompt ) ) {
51 foreach ( $image_prompt as $prompt ) {
52 if ( $prompt !== '' ) {
53 $data['text_prompts'][] = array(
54 'text' => $prompt,
55 'weight' => 1,
56 );
57 }
58 }
59
60 $data['text_prompts'][] = array(
61 'text' => $this->negative_prompt,
62 'weight' => -1,
63 );
64
65 } else {
66 if ( $image_prompt !== '' ) {
67 $data['text_prompts'] = $this->build_text_prompts( $image_prompt );
68 }
69 }
70
71 return $data;
72 }
73
74 public function build_text_prompts( $image_prompt ) {
75 return array(
76 array(
77 'text' => $image_prompt,
78 'weight' => 1,
79 ),
80 array(
81 'text' => $this->negative_prompt,
82 'weight' => -1,
83 ),
84 );
85 }
86
87 public function set_negative_prompt( $negative_prompt ) {
88 $this->negative_prompt = $negative_prompt;
89 }
90
91 private function post( $data, $files = array(), $settings = array() ) {
92 $response = $this->api->post(
93 $data,
94 $files,
95 $settings
96 );
97
98 return $response;
99 }
100 }
101