-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvariations.php
29 lines (25 loc) · 902 Bytes
/
variations.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<h1>Variations</h1>
<form action="/variations.php" method="post" enctype="multipart/form-data">
Select file to upload: <br>
<label for="image">Image</label>
<input type="file" name="image" id="image">
<br>
<input type="submit" value="Upload File" name="submit">
</form>
<?php
require __DIR__ . '/vendor/autoload.php';
use Orhanerday\OpenAi\OpenAi;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (ob_get_contents()) ob_end_clean();
$open_ai_key = getenv('OPENAI_API_KEY');
$open_ai = new OpenAi($open_ai_key);
$tmp_file = $_FILES['image']['tmp_name'];
$file_name = basename($_FILES['image']['name']);
$image = curl_file_create($tmp_file, $_FILES['image']['type'], $file_name);
$result = $open_ai->createImageVariation([
"image" => $image,
"n" => 2,
"size" => "256x256",
]);
echo $result;
}