-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVision.py
81 lines (52 loc) · 2.07 KB
/
Vision.py
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
77
78
79
80
81
import base64
import requests
# OpenAI API Key
api_key = "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"
# Function to encode the image
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
# Path to your image
image_path = "D:\\0135.jpg"
# Getting the base64 string
base64_image = encode_image(image_path)
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
payload = {
"model": "gpt-4-vision-preview",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Provide as much detail as possible about the description of the man and the surroundings in this photo. Pay special attention to the description of facial features and haircut. It is important to describe in detail that the haircut is very short"
},
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{base64_image}"
}
}
]
}
],
"max_tokens": 4096
}
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
answer = response.json()
content = answer["choices"][0]["message"]["content"]
content = "3D cartoon gentleman with a confident smile, standing at an angle, wearing a light blue upper-body garment, with fair eye color, oval-shaped eyes. The texture of the cartoon should reflect a velvety finish, and the style should emulate a well-groomed, bald head. Holding a notebook with green letter d. Include text in a 3D rendering style, suitable for typography or illustration, to be used in a painting, photo, poster, or 3D rendered image."
from openai import OpenAI
client = OpenAI(api_key = "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")
response = client.images.generate(
model="dall-e-3",
prompt=content,
size="1024x1024",
quality="hd",
n=1,
)
image_url = response.data[0].url
print(image_url)