-
Notifications
You must be signed in to change notification settings - Fork 0
/
texttoimage.php
76 lines (57 loc) · 1.94 KB
/
texttoimage.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html lang="en">
<head>
<title>OPEN AI</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="col-sm-4">
<h1>OPEN AI</h1>
<h3>Generate Image from text</h3>
<?php
if(isset($_POST["prompt"])) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.openai.com/v1/images/generations',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"prompt": "'.$_POST['prompt'].'",
"n": 1,
"size": "1024x1024"
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Bearer $YOUR_API_KEYS'
),
));
$response = curl_exec($curl);
curl_close($curl);
$imageinfo=json_decode($response);
foreach ($imageinfo->data as $key => $value) {
echo 'Result for '.$_POST['prompt'].': <img src="'.$value->url.'" width="400px"/>';
}
}
?>
<form method="POST">
<div class="form-group">
<label for="comment">Prompt:</label>
<!-- <textarea class="form-control" rows="5" id="prompt" name="prompt"></textarea> -->
<input type="text" name="prompt" class="form-control">
</div>
<input type="submit" class="btn btn-primary" value="Send" />
</form>
</div>
</div>
</body>
</html>