Download app/Services/Ai/FalAI.php from pnacorp/magicai: direct link, hf CLI and curl.
- Browser
- Download file 1.63 kB
-
https://huggingface.co/pnacorp/magicai/resolve/main/app/Services/Ai/FalAI.php
- Command line
-
hf download hf://pnacorp/magicai/app/Services/Ai/FalAI.php
-
curl -L -o FalAI.php https://huggingface.co/pnacorp/magicai/resolve/main/app/Services/Ai/FalAI.php
1.63 kB
| namespace App\Services\Ai; | |
| use App\Helpers\Classes\Helper; | |
| use Illuminate\Support\Arr; | |
| use Illuminate\Support\Facades\Http; | |
| class FalAI | |
| { | |
| public static function generate($prompt, string $model = 'flux-pro') | |
| { | |
| $model = 'fal-ai/' . (setting('fal_ai_default_model') ?: $model); | |
| $http = Http::withHeaders([ | |
| 'Content-Type' => 'application/json', | |
| 'Accept' => 'application/json', | |
| 'Authorization' => 'Key ' . Helper::setFalAIKey(), | |
| ]) | |
| ->post('https://queue.fal.run/' . $model, [ | |
| 'prompt' => $prompt, | |
| ]); | |
| if ($http->status() == 200) { | |
| if ($request_id = $http->json('request_id')) { | |
| return $request_id; | |
| } | |
| } | |
| return null; | |
| } | |
| public static function check($uuid, string $model = 'flux-pro') | |
| { | |
| $model = 'fal-ai/' . (setting('fal_ai_default_model') ?: $model); | |
| $url = 'https://queue.fal.run/' . $model . '/requests/' . $uuid; | |
| $http = Http::withHeaders([ | |
| 'Content-Type' => 'application/json', | |
| 'Accept' => 'application/json', | |
| 'Authorization' => 'Key ' . Helper::setFalAIKey(), | |
| ]) | |
| ->get($url); | |
| if ($images = $http->json('images')) { | |
| if (is_array($images)) { | |
| $image = Arr::first($images); | |
| return [ | |
| 'image' => $image, | |
| 'size' => data_get($image, 'width') . 'x' . data_get($image, 'height'), | |
| ]; | |
| } | |
| } | |
| return null; | |
| } | |
| } | |