0

I created a Daemon to wrap around Invoke-AI command line interface https://github.com/invoke-ai/InvokeAI to generate images for my website.

My issue is that it keeps failing on some artists names with "ō" in their name and I have no idea why. I had the same issue with another interface. Both were ran in an Anaconda Python environment. Both worked fine when I opened the command line directly and entered the name, so I think the issue is in my code.

For my below tests I used "Art by Baiōken Eishun" and "Art by Gyoshū Hayami".

I removed all the irrelevant code for troubleshooting. Running PHP 7.4 on Windows 11.

<?php
// tell php to automatically flush after every output
// including lines of output produced by shell commands
disable_ob();
set_time_limit(0);
chdir('E:\InvokeAI');

$startEnvCommand = '"C:\Windows\System32\cmd.exe "/K" C:\Users\Blake\anaconda3\Scripts\activate.bat invokeai"'.PHP_EOL;
$invokeCommand = 'python E:\InvokeAI\scripts\invoke.py';
$logFile = 'error.txt';

// open command line invokeAI environment

echo $startEnvCommand.'<br />';

$process = proc_open($startEnvCommand, array(
   0 => array("pipe", "r"),
   1 => array("pipe", "w"),
   2 => array("file", $logFile, "a")
), $pipes, 'E:\InvokeAI');

$stdin = $pipes[0];
$stdout = $pipes[1];

stream_set_blocking($stdout, false);
stream_set_blocking($stdin, true);

while ($data = fread($stdout, 8192)) {
    echo '"'.$data.'".<br />';
    if (substr($data, -12) == "E:\InvokeAI>") {
         echo "Env started...<br />";
        break;
    }
}
usleep(250000);

// start invoke prompt!
fwrite($stdin, $invokeCommand.PHP_EOL);
while ($data = fread($stdout, 8192)) {
   echo '"'.$data.'".<br />';
    if (substr($data, -8) == 'invoke> ') {
      echo 'Prompt started, start generating images...<br />';
      break;
    }
    
    if (substr($data, -12) == 'E:\InvokeAI>') {
      echo file_get_contents($logFile);
         exit('Error!');
        break;
    }
}

sleep(1);

// run command to test here
$command = '"Art by Baiōken Eishun" -s 50 -W 512 -H 512 -C 7 -n 5 -A k_euler_a';
$command = '"Art by Gyoshū Hayami" -s 50 -W 512 -H 512 -C 7 -n 5 -A k_euler_a';

         echo "Running command: \"{$command}\"<br />";

         // start invoke prompt!
         fwrite($stdin, $command.PHP_EOL);
         while ($data = fread($stdout, 8192)) {
            echo '"'.$data.'".<br />';
             if (substr($data, -8) == 'invoke> ') {
               echo 'Images complete...<br />';
           exit('done!');
               break;
             }
         }




function disable_ob() {
   // Turn off output buffering
   ini_set('output_buffering', 'off');
   // Turn off PHP output compression
   ini_set('zlib.output_compression', false);
   // Implicitly flush the buffer(s)
   ini_set('implicit_flush', true);
   ob_implicit_flush(true);
   // Clear, and turn off output buffering
   while (ob_get_level() > 0) {
       // Get the curent level
       $level = ob_get_level();
       // End the buffering
       ob_end_clean();
       // If the current level has not changed, abort
       if (ob_get_level() == $level) break;
   }
   // Disable apache output buffering/compression
   if (function_exists('apache_setenv')) {
       apache_setenv('no-gzip', '1');
       apache_setenv('dont-vary', '1');
   }
}



Output:

"Art by Baiōken Eishun"

"C:\Windows\System32\cmd.exe "/K" C:\Users\Blake\anaconda3\Scripts\activate.bat invokeai"
" (invokeai) E:\InvokeAI>".
Env started...
"python E:\InvokeAI\scripts\invoke.py ".
"* Initializing, be patient... >> GFPGAN Initialized >> CodeFormer Initialized >> ESRGAN Initialized >> Using device_type cuda >> Loading stable-diffusion-1.4 from models/ldm/stable-diffusion-v1/model.ckpt | LatentDiffusion: Running in eps-prediction mode | DiffusionWrapper has 859.52 M params. | Making attention of type 'vanilla' with 512 in_channels | Working with z of shape (1, 4, 32, 32) = 4096 dimensions. | Making attention of type 'vanilla' with 512 in_channels | Using faster float16 precision >> Model loaded in 14.59s >> Max VRAM used to load the model: 2.17G >> Current VRAM usage:2.17G >> Setting Sampler to k_lms * Initialization done! Awaiting your command (-h for help, 'q' to quit) invoke> ".
Prompt started, start generating images...
Running command: ""Art by Baiōken Eishun" -s 50 -W 512 -H 512 -C 7 -n 5 -A k_euler_a"
">> Setting Sampler to k_euler_a ".
">> Sampling with k_euler_ancestral starting at step 0 of 50 (50 new sampling steps) ".
" (invokeai) E:\InvokeAI>".

"Art by Gyoshū Hayami"

"C:\Windows\System32\cmd.exe "/K" C:\Users\Blake\anaconda3\Scripts\activate.bat invokeai"
" (invokeai) E:\InvokeAI>".
Env started...
"python E:\InvokeAI\scripts\invoke.py ".
"* Initializing, be patient... >> GFPGAN Initialized >> CodeFormer Initialized >> ESRGAN Initialized >> Using device_type cuda >> Loading stable-diffusion-1.4 from models/ldm/stable-diffusion-v1/model.ckpt | LatentDiffusion: Running in eps-prediction mode | DiffusionWrapper has 859.52 M params. | Making attention of type 'vanilla' with 512 in_channels | Working with z of shape (1, 4, 32, 32) = 4096 dimensions. | Making attention of type 'vanilla' with 512 in_channels | Using faster float16 precision >> Model loaded in 14.83s >> Max VRAM used to load the model: 2.17G >> Current VRAM usage:2.17G >> Setting Sampler to k_lms * Initialization done! Awaiting your command (-h for help, 'q' to quit) invoke> ".
Prompt started, start generating images...
Running command: ""Art by Gyoshū Hayami" -s 50 -W 512 -H 512 -C 7 -n 5 -A k_euler_a"
">> Setting Sampler to k_euler_a ".
">> Sampling with k_euler_ancestral starting at step 0 of 50 (50 new sampling steps) >> Sampling with k_euler_ancestral starting at step 0 of 50 (50 new sampling steps) >> Sampling with k_euler_ancestral starting at step 0 of 50 (50 new sampling steps) >> Sampling with k_euler_ancestral starting at step 0 of 50 (50 new sampling steps) >> Sampling with k_euler_ancestral starting at step 0 of 50 (50 new sampling steps) >> Usage stats: >> 5 image(s) generated in 31.76s >> Max VRAM used for this generation: 3.35G. Current VRAM utilization: 2.21G >> Max VRAM used since script start: 3.35G Outputs: [1.1] outputs/img-samples\000001.259883587.png: "Art by Gyoshū Hayami" -s 50 -S 259883587 -W 512 -H 512 -C 7.0 -A k_euler_a [1.2] outputs/img-samples\000001.3608423195.png: "Art by Gyoshū Hayami" -s 50 -S 3608423195 -W 512 -H 512 -C 7.0 -A k_euler_a [1.3] outputs/img-samples\000001.1094619114.png: "Art by Gyoshū Hayami" -s 50 -S 1094619114 -W 512 -H 512 -C 7.0 -A k_euler_a [1.4] outputs/img-samples\000001.1779765255.png: "Art by Gyoshū Hayami" -s 50 -S 1779765255 -W 512 -H 512 -C 7.0 -A k_euler_a [1.5] outputs/img-samples\000001.37246202.png: "Art by Gyoshū Hayami" -s 50 -S 37246202 -W 512 -H 512 -C 7.0 -A k_euler_a invoke> ".
Images complete...
done!

It must be an encoding issue but I haven't been able to find out what encoding it wants. Currently it's in UTF-8. I tried changing the encoding in the proc_open $env_vars but it gave encoding errors when I tried to make it UTF-8. I tried using mb_convert_encoding($command, "pass", "auto") as well, but this returns an empty string.

Blake
  • 33
  • 1
  • 6

1 Answers1

0

I found something that worked here. This setting is also in Windows 11 and is still in beta. Using UTF-8 Encoding (CHCP 65001) in Command Prompt / Windows Powershell (Windows 10)

Run intl.cpl (which opens the regional settings in Control Panel) then

How to activate UTF-8 in cmd

Blake
  • 33
  • 1
  • 6