PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.1.1
Kubio AI Page Builder v2.1.1
2.9.1 2.9.0 2.8.6 2.8.5 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 2 years ago KubioImageGenerate.php 2 years ago KubioImageManager.php 2 years ago KubioImagePrompts.php 2 years ago KubioImageSearch.php 2 years ago sd-endpoints.php 2 years ago
KubioImageGenerate.php
107 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 ) : array {
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 ) : array {
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
88 public function set_negative_prompt( $negative_prompt ) : void {
89 $this->negative_prompt = $negative_prompt;
90 }
91
92 private function get_settings( $settings, $extra = array() ) : array {
93 return array_merge( $settings, $extra );
94 }
95
96 private function post( $data, $files = array(), $settings = array() ) {
97 $response = $this->api->post(
98 $data,
99 $files,
100 $settings
101 );
102
103 return $response;
104 }
105
106 }
107