Update
This commit is contained in:
@@ -16,15 +16,21 @@
|
||||
|
||||
class MemeGenerator
|
||||
{
|
||||
|
||||
const TYPE_SINGLE_CAPTION_MEME_BACKGROUND = 'single_caption_meme_background';
|
||||
|
||||
const STATUS_PENDING = 'pending';
|
||||
|
||||
const STATUS_COMPLETED = 'completed';
|
||||
|
||||
public static function getSuitableMeme(Meme $meme)
|
||||
{
|
||||
//dd($meme->toArray());
|
||||
return MemeMedia::first();
|
||||
}
|
||||
|
||||
public static function generateMemeByCategory(Category $category)
|
||||
{
|
||||
$meme_output = self::getMemeOutputByCategory($category);
|
||||
$meme_output = self::generateMemeOutputByCategory($category);
|
||||
|
||||
$meme = null;
|
||||
|
||||
@@ -38,18 +44,25 @@ public static function generateMemeByCategory(Category $category)
|
||||
'background' => $meme_output->background,
|
||||
'keywords' => $meme_output->keywords,
|
||||
'is_system' => true,
|
||||
'status' => self::STATUS_PENDING
|
||||
'status' => self::STATUS_PENDING,
|
||||
'primary_keyword_type' => $meme_output->primary_keyword_type,
|
||||
'action_keywords' => $meme_output->action_keywords,
|
||||
'emotion_keywords' => $meme_output->emotion_keywords,
|
||||
'misc_keywords' => $meme_output->misc_keywords,
|
||||
]);
|
||||
|
||||
$meme->attachTags($meme_output->keywords, 'meme');
|
||||
}
|
||||
|
||||
if (!is_null($meme) && $meme->status == self::STATUS_PENDING) {
|
||||
if (! is_null($meme) && $meme->status == self::STATUS_PENDING) {
|
||||
// populate meme_id
|
||||
$meme->meme_id = self::getMemeMediaByKeywords($meme_output->keywords)->id;
|
||||
$meme->meme_id = null; // self::getMemeMediaByKeywords($meme_output->keywords)->id;
|
||||
$meme->background_id = self::generateBackgroundMediaWithRunware($meme_output->background)->id;
|
||||
|
||||
if (!is_null($meme->meme_id) && !is_null($meme->background_id)) {
|
||||
if (
|
||||
//!is_null($meme->meme_id) &&
|
||||
! is_null($meme->background_id)
|
||||
) {
|
||||
$meme->status = self::STATUS_COMPLETED;
|
||||
}
|
||||
|
||||
@@ -59,21 +72,21 @@ public static function generateMemeByCategory(Category $category)
|
||||
return $meme;
|
||||
}
|
||||
|
||||
public static function getMemeOutputByCategory(Category $category)
|
||||
public static function generateMemeOutputByCategory(Category $category)
|
||||
{
|
||||
$retries = 3;
|
||||
$attempt = 0;
|
||||
|
||||
$random_keyword = Str::lower($category->name);
|
||||
|
||||
if (!is_null($category->parent_id)) {
|
||||
$random_keyword = $category->parent->name . " - " . $random_keyword;
|
||||
if (! is_null($category->parent_id)) {
|
||||
$random_keyword = $category->parent->name . ' - ' . $random_keyword;
|
||||
}
|
||||
|
||||
if (!is_null($category->meme_angles)) {
|
||||
$random_keyword .= " - " . collect($category->meme_angles)->random();
|
||||
} else if (!is_null($category->keywords)) {
|
||||
$random_keyword .= " - " . collect($category->keywords)->random();
|
||||
if (! is_null($category->meme_angles)) {
|
||||
$random_keyword .= ' - ' . collect($category->meme_angles)->random();
|
||||
} elseif (! is_null($category->keywords)) {
|
||||
$random_keyword .= ' - ' . collect($category->keywords)->random();
|
||||
}
|
||||
|
||||
$prompt = "Write me 1 meme about {$random_keyword}";
|
||||
@@ -87,12 +100,14 @@ public static function getMemeOutputByCategory(Category $category)
|
||||
|
||||
$output_is_valid = false;
|
||||
|
||||
if (!is_null($meme_output)) {
|
||||
if (! is_null($meme_output)) {
|
||||
if (
|
||||
isset($meme_output->caption) &&
|
||||
isset($meme_output->meme_keywords) &&
|
||||
isset($meme_output->background) &&
|
||||
isset($meme_output->keywords)
|
||||
isset($meme_output->keywords) &&
|
||||
isset($meme_output->primary_keyword_type) &&
|
||||
isset($meme_output->action_keywords) &&
|
||||
isset($meme_output->emotion_keywords)
|
||||
) {
|
||||
$output_is_valid = true;
|
||||
}
|
||||
@@ -118,7 +133,7 @@ public static function getMemeOutputByCategory(Category $category)
|
||||
$meme_output = (object) [
|
||||
'success' => false,
|
||||
'attempts' => $attempt, // Optional: track how many attempts were made
|
||||
'error' => 'Failed to generate valid meme after ' . $retries . ' attempts'
|
||||
'error' => 'Failed to generate valid meme after ' . $retries . ' attempts',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -131,7 +146,6 @@ public static function generateBackgroundMediaWithRunware($prompt)
|
||||
$media_height = 1024;
|
||||
$aspect_ratio = AspectRatio::get($media_width, $media_height);
|
||||
|
||||
|
||||
$runware_output_url = RunwareAI::generateSchnellImage(Str::uuid(), $prompt, $media_width, $media_height);
|
||||
|
||||
$media = MediaEngine::addMedia(
|
||||
|
||||
Reference in New Issue
Block a user