This commit is contained in:
ct
2025-06-19 13:16:17 +08:00
parent 4545fd64c6
commit 5d3a3c8818
19 changed files with 854 additions and 108 deletions

View File

@@ -0,0 +1,60 @@
<?php
namespace App\Helpers\FirstParty\AI;
use Illuminate\Support\Facades\Http;
class RunwareAI
{
public static function generateSchnellImage($uuid, $prompt, $width = 1024, $height = 1024)
{
$api_key = config('services.runware.api_key');
try {
$response = Http::timeout(60)
->withHeaders([
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $api_key,
])
->post('https://api.runware.ai/v1', [
[
"taskUUID" => $uuid,
"taskType" => "imageInference",
"width" => $width,
"height" => $height,
"numberResults" => 1,
"outputFormat" => "WEBP",
"outputType" => ["URL"],
"includeCost" => true,
"inputImages" => [],
"positivePrompt" => $prompt,
"model" => "runware:100@1"
]
]);
// Check if the request was successful
if ($response->successful()) {
$data = $response->json();
// Extract the image URL from the response
if (isset($data['data']) && count($data['data']) > 0) {
$imageData = collect($data['data'])
->where('taskType', 'imageInference')
->first();
if ($imageData && isset($imageData['imageURL'])) {
return $imageData['imageURL'];
}
}
throw new \Exception('Image URL not found in response');
}
throw new \Exception('API request failed: ' . $response->status() . ' - ' . $response->body());
} catch (\Exception $e) {
// Log the error or handle as needed
\Log::error('RunwareAI API Error: ' . $e->getMessage());
throw $e;
}
}
}

View File

@@ -23,7 +23,7 @@ public static function populateDurations()
}
}
private static function getDurationUsingFfmpeg($meme_media)
public static function getDurationUsingFfmpeg($meme_media)
{
$duration_milliseconds = FFMpeg::openUrl($meme_media->webm_url)->getDurationInMiliseconds();
$duration_seconds = ($duration_milliseconds / 1000);