Skip to content

Commit f794e9e

Browse files
Merge pull request #12 from CodeWithKyrian/change-init-process
Download ONNXRuntime automatically after composer install
2 parents eb27c1e + 2631b70 commit f794e9e

File tree

5 files changed

+35
-184
lines changed

5 files changed

+35
-184
lines changed

composer.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"ankane/onnxruntime": "^0.2.0",
1919
"rindow/rindow-math-matrix": "^1.2",
2020
"codewithkyrian/jinja-php": "^1.0",
21+
"codewithkyrian/onnxruntime-downloader-plugin": "^1.1",
2122
"symfony/console": "^6.4|^7.0",
2223
"imagine/imagine": "^1.3",
2324
"rokka/imagine-vips": "^0.31.0"
@@ -44,7 +45,8 @@
4445
],
4546
"config": {
4647
"allow-plugins": {
47-
"pestphp/pest-plugin": true
48+
"pestphp/pest-plugin": true,
49+
"codewithkyrian/onnxruntime-downloader-plugin": true
4850
}
4951
},
5052
"bin": [

examples/composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "kyrian/examples",
33
"autoload": {
44
"psr-4": {
5-
"Kyrian\\Examples\\": "src/"
5+
"Kyrian\\Examples\\": "/"
66
}
77
},
88
"authors": [
@@ -14,8 +14,9 @@
1414
"require": {
1515
"php": "^8.1",
1616
"symfony/console": "^7.0",
17-
"codewithkyrian/transformers" : "dev-main"
17+
"codewithkyrian/transformers": "dev-change-init-process"
1818
},
19+
"minimum-stability": "dev",
1920
"require-dev": {
2021
"symfony/var-dumper": "^7.0"
2122
},

src/Commands/DownloadModelCommand.php

+29
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Console\Input\InputInterface;
2020
use Symfony\Component\Console\Input\InputOption;
2121
use Symfony\Component\Console\Output\OutputInterface;
22+
use Symfony\Component\Console\Question\ConfirmationQuestion;
2223
use function Codewithkyrian\Transformers\Pipelines\pipeline;
2324

2425
#[AsCommand(
@@ -79,10 +80,38 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7980

8081
$output->writeln('✔ Model files downloaded successfully.');
8182

83+
$this->askToStar($input, $output);
84+
8285
return Command::SUCCESS;
8386
} catch (\Exception $e) {
8487
$output->writeln(''. $e->getMessage());
8588
return Command::FAILURE;
8689
}
8790
}
91+
92+
protected function askToStar(InputInterface $input, OutputInterface $output): void
93+
{
94+
if ($input->getOption('no-interaction')) {
95+
return;
96+
}
97+
98+
$helper = $this->getHelper('question');
99+
$question = new ConfirmationQuestion('? Would you like to show some love by starring the Transformers repo on GitHub? ', true);
100+
101+
if ($helper->ask($input, $output, $question)) {
102+
if (PHP_OS_FAMILY === 'Darwin') {
103+
exec('open https://github.com/CodeWithKyrian/transformers-php');
104+
}
105+
if (PHP_OS_FAMILY === 'Linux') {
106+
exec('xdg-open https://github.com/CodeWithKyrian/transformers-php');
107+
}
108+
if (PHP_OS_FAMILY === 'Windows') {
109+
exec('start https://github.com/CodeWithKyrian/transformers-php');
110+
}
111+
112+
$output->writeln('✔ Thank you!');
113+
} else {
114+
$output->writeln('✔ That\'s okay. You can always star the repo later.');
115+
}
116+
}
88117
}

src/Commands/InitCommand.php

-170
This file was deleted.

src/Transformers.php

-11
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
use Codewithkyrian\Transformers\Utils\Image;
99
use Codewithkyrian\Transformers\Utils\ImageDriver;
10-
use OnnxRuntime\FFI;
1110
use OnnxRuntime\Vendor;
12-
use function Codewithkyrian\Transformers\Utils\joinPaths;
1311

1412
class Transformers
1513
{
@@ -32,22 +30,13 @@ public static function setup(): static
3230

3331
public function apply(): void
3432
{
35-
FFI::$lib = self::libFile();
36-
3733
Image::$imagine = match (self::$imageDriver) {
3834
ImageDriver::IMAGICK => new \Imagine\Imagick\Imagine(),
3935
ImageDriver::GD => new \Imagine\GD\Imagine(),
4036
ImageDriver::VIPS => new \Imagine\Vips\Imagine(),
4137
};
4238
}
4339

44-
public static function libFile(): string
45-
{
46-
$template = joinPaths(Transformers::$cacheDir, self::platform('file'), 'lib', self::platform('lib'));
47-
48-
return str_replace('{{version}}', Vendor::VERSION, $template);
49-
}
50-
5140
/**
5241
* Set the default cache directory for transformers models and tokenizers
5342
* @param string $cacheDir

0 commit comments

Comments
 (0)