Update
This commit is contained in:
60
app/Helpers/FirstParty/AI/RunwareAI.php
Normal file
60
app/Helpers/FirstParty/AI/RunwareAI.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Helpers\FirstParty\AI\OpenAI;
|
||||
use App\Helpers\FirstParty\AI\RunwareAI;
|
||||
use Str;
|
||||
|
||||
class TestController extends Controller
|
||||
{
|
||||
@@ -24,4 +26,12 @@ public function writeMeme()
|
||||
|
||||
dd($meme_output);
|
||||
}
|
||||
|
||||
public function generateSchnellImage()
|
||||
{
|
||||
$uuid = Str::uuid();
|
||||
$image_url = RunwareAI::generateSchnellImage($uuid, 'office desk cluttered with papers and a computer', 1024, 1024);
|
||||
|
||||
dd($image_url);
|
||||
}
|
||||
}
|
||||
|
||||
83
app/Models/Category.php
Normal file
83
app/Models/Category.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Kalnoy\Nestedset\NodeTrait;
|
||||
use Pgvector\Laravel\HasNeighbors;
|
||||
use Pgvector\Laravel\Vector;
|
||||
use Spatie\Tags\HasTags;
|
||||
|
||||
/**
|
||||
* Class Category
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $slug
|
||||
* @property string $description
|
||||
* @property int $_lft
|
||||
* @property int $_rgt
|
||||
* @property int|null $parent_id
|
||||
* @property string|null $subcategories
|
||||
* @property string|null $meme_angles
|
||||
* @property string|null $sample_captions
|
||||
* @property string|null $keywords
|
||||
* @property string $payload
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class Category extends Model
|
||||
{
|
||||
use NodeTrait, HasTags, HasNeighbors;
|
||||
|
||||
protected $table = 'categories';
|
||||
|
||||
protected $casts = [
|
||||
'embedding' => Vector::class,
|
||||
'_lft' => 'int',
|
||||
'_rgt' => 'int',
|
||||
'parent_id' => 'int',
|
||||
'subcategories' => 'object',
|
||||
'meme_angles' => 'array',
|
||||
'sample_captions' => 'array',
|
||||
'keywords' => 'array',
|
||||
'payload' => 'object',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'description',
|
||||
'_lft',
|
||||
'_rgt',
|
||||
'parent_id',
|
||||
'subcategories',
|
||||
'meme_angles',
|
||||
'sample_captions',
|
||||
'keywords',
|
||||
'payload'
|
||||
];
|
||||
|
||||
/**
|
||||
* Scope to get only main categories
|
||||
*/
|
||||
public function scopeMainCategories($query)
|
||||
{
|
||||
return $query->whereNull('parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to get only subcategories
|
||||
*/
|
||||
public function scopeSubcategories($query)
|
||||
{
|
||||
return $query->whereNotNull('parent_id');
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Pgvector\Laravel\HasNeighbors;
|
||||
use Pgvector\Laravel\Vector;
|
||||
use Spatie\Tags\HasTags;
|
||||
|
||||
/**
|
||||
* Class MemeMedia
|
||||
@@ -33,13 +34,15 @@
|
||||
*/
|
||||
class MemeMedia extends Model
|
||||
{
|
||||
use HasNeighbors, SoftDeletes;
|
||||
use HasNeighbors, SoftDeletes, HasTags;
|
||||
|
||||
protected $table = 'meme_medias';
|
||||
|
||||
protected $casts = [
|
||||
'embedding' => Vector::class,
|
||||
'duration' => 'double',
|
||||
'keywords' => 'array',
|
||||
'is_enabled' => 'boolean',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
@@ -85,7 +88,7 @@ class MemeMedia extends Model
|
||||
protected function ids(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn ($value, $attributes) => hashids_encode($attributes['id']),
|
||||
get: fn($value, $attributes) => hashids_encode($attributes['id']),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user