the RunwareAI Plugin is working now
This commit is contained in:
@@ -71,7 +71,27 @@ class RunwareAi implements ApiPluginInterface
|
||||
return ['progress' => 0];
|
||||
}
|
||||
|
||||
public function upload(string $imagePath): array
|
||||
public function processImageStyleChange(string $imagePath, string $prompt, string $modelId, ?string $parameters = null): array
|
||||
{
|
||||
// Step 1: Upload the original image
|
||||
$uploadResult = $this->upload($imagePath);
|
||||
|
||||
if (!isset($uploadResult['data'][0]['imageUUID'])) {
|
||||
throw new \Exception('Image upload to AI service failed or returned no UUID.');
|
||||
}
|
||||
$seedImageUUID = $uploadResult['data'][0]['imageUUID'];
|
||||
|
||||
// Step 2: Request style change using the uploaded image's UUID
|
||||
$result = $this->styleChangeRequest($prompt, $seedImageUUID, $modelId, $parameters);
|
||||
|
||||
if (!isset($result['base64Data'])) {
|
||||
throw new \Exception('AI service did not return base64 image data.');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function upload(string $imagePath): array
|
||||
{
|
||||
$this->logInfo('Attempting to upload image to RunwareAI.', ['image_path' => $imagePath]);
|
||||
if (!$this->apiProvider->api_url || !$this->apiProvider->token) {
|
||||
@@ -83,15 +103,19 @@ class RunwareAi implements ApiPluginInterface
|
||||
$token = $this->apiProvider->token;
|
||||
$taskUUID = (string) Str::uuid();
|
||||
|
||||
$imageData = 'data:image/png;base64,' . base64_encode(file_get_contents($imagePath));
|
||||
|
||||
try {
|
||||
$response = Http::withHeaders([
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
'Accept' => 'application/json',
|
||||
])->attach(
|
||||
'image', file_get_contents($imagePath), basename($imagePath)
|
||||
)->post($apiUrl, [
|
||||
'taskType' => 'imageUpload',
|
||||
'taskUUID' => $taskUUID,
|
||||
'Content-Type' => 'application/json',
|
||||
])->post($apiUrl, [
|
||||
[
|
||||
'taskType' => 'imageUpload',
|
||||
'taskUUID' => $taskUUID,
|
||||
'image' => $imageData,
|
||||
]
|
||||
]);
|
||||
|
||||
$response->throw();
|
||||
@@ -103,7 +127,7 @@ class RunwareAi implements ApiPluginInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function styleChangeRequest(string $prompt, string $seedImageUUID, ?string $parameters = null): array
|
||||
private function styleChangeRequest(string $prompt, string $seedImageUUID, string $modelId, ?string $parameters = null): array
|
||||
{
|
||||
$this->logInfo('Attempting style change request to RunwareAI.', ['prompt' => $prompt, 'seed_image_uuid' => $seedImageUUID]);
|
||||
if (!$this->apiProvider->api_url || !$this->apiProvider->token) {
|
||||
@@ -121,6 +145,7 @@ class RunwareAi implements ApiPluginInterface
|
||||
'positivePrompt' => $prompt,
|
||||
'seedImage' => $seedImageUUID,
|
||||
'outputType' => 'base64Data',
|
||||
'model' => $modelId,
|
||||
];
|
||||
|
||||
$decodedParameters = json_decode($parameters, true) ?? [];
|
||||
@@ -132,13 +157,28 @@ class RunwareAi implements ApiPluginInterface
|
||||
$response = Http::withHeaders([
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
'Accept' => 'application/json',
|
||||
])->post($apiUrl, $data);
|
||||
])->post($apiUrl, [
|
||||
$data
|
||||
]);
|
||||
|
||||
$response->throw();
|
||||
$this->logInfo('Style change request successful to RunwareAI.', ['task_uuid' => $taskUUID, 'response' => $response->json()]);
|
||||
return $response->json();
|
||||
$responseData = $response->json();
|
||||
|
||||
if (!isset($responseData['data'][0]['imageBase64Data'])) {
|
||||
throw new \Exception('AI service did not return base64 image data.');
|
||||
}
|
||||
|
||||
$base64Image = $responseData['data'][0]['imageBase64Data'];
|
||||
|
||||
$this->logInfo('Style change request successful to RunwareAI.', ['task_uuid' => $taskUUID, 'response' => $responseData]);
|
||||
return ['base64Data' => $base64Image];
|
||||
} catch (\Exception $e) {
|
||||
$this->logError('Style change request to RunwareAI failed.', ['error' => $e->getMessage(), 'task_uuid' => $taskUUID]);
|
||||
$errorData = [];
|
||||
/*if ($e instanceof \Illuminate\Http\Client\RequestException && $e->response) {
|
||||
$errorData['response_body'] = $e->response->body();
|
||||
$errorData['response_status'] = $e->response->status();
|
||||
}*/
|
||||
$this->logError('Style change request to RunwareAI failed.', ['error' => $e->getMessage(), 'task_uuid' => $taskUUID] + $errorData);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user