-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvision.py
More file actions
60 lines (52 loc) · 1.68 KB
/
vision.py
File metadata and controls
60 lines (52 loc) · 1.68 KB
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
import discord
import os
from openai import OpenAI
apikey = youropenaiapikey
discord_apikey = yourdiscordapikey
def getImage(description):
client = OpenAI(
api_key = apikey,
)
response = client.images.generate(
model="dall-e-3",
prompt=description,
size="1024x1024",
quality="standard",
n=1,
)
image_url = response.data[0].url
return image_url
def getDescription(url):
client = OpenAI(
api_key = apikey,
)
response = client.chat.completions.create(
model="gpt-4-vision-preview",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Describe the image in detail using as many proper names for each of the items as possible. Limit 2000 characters in response."},
{
"type": "image_url",
"image_url": url,
},
],
}
],
max_tokens=300,
)
return(response.choices[0].message.content)
intents = discord.Intents.all()
intents.members = True
client = discord.Client(intents=intents)
@client.event
async def on_message(message):
if len(message.attachments) > 0:
for attachment in message.attachments:
if attachment.filename.endswith('.jpg') or attachment.filename.endswith('.png'):
url = message.attachments[0].url
description = getDescription(url)
await message.reply(description)
await message.reply("\n\nHere's my best effort in creating the image: " + getImage(description))
client.run(yourdiscordapikey)