Last active
November 22, 2024 07:05
-
-
Save jkominek/73ce05da40faf5a9349ab521f7ac56d5 to your computer and use it in GitHub Desktop.
How does AI do on the AI Art Turing Test?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import base64 | |
import csv | |
import os | |
import re | |
import urllib.parse | |
from io import BytesIO | |
import bs4 | |
import requests | |
from PIL import Image | |
def poll_llm(image): | |
body = { | |
"model": "llama3.2-vision", | |
"stream": False, | |
"messages": [ | |
{ | |
"role": "system", | |
"content": "You are a simple image classifier which answers only the question asked in the shortest possible fashion, without explanation or complaint.", | |
}, | |
{ | |
"role": "user", | |
"content": "Was this image produced by an AI image generator, or by a human? Answer just 'AI' or 'Human'.", | |
"images": [image], | |
}, | |
], | |
} | |
r = requests.post("http://sparky.local:11434/api/chat", json=body) | |
if "message" not in r.json(): | |
print(r.json()) | |
raise Exception() | |
else: | |
return r.json()["message"]["content"] | |
r = requests.get("https://www.astralcodexten.com/p/how-did-you-do-on-the-ai-art-turing") | |
soup = bs4.BeautifulSoup(r.content, features="lxml") | |
maybe_imgs = soup.find_all(class_="captioned-image-container") | |
results = csv.writer(open("results.csv", "w")) | |
for maybe_img in maybe_imgs: | |
maybe_p = maybe_img.find_previous_sibling() | |
# print(maybe_img) | |
if maybe_p.name == "p": | |
m = re.match("^\s*(\d+):\s*(.+)$", maybe_p.text) | |
if m: | |
num, title = m.group(1), m.group(2) | |
img = maybe_img.find("img") | |
desc = maybe_img.find_next_sibling() | |
classification = desc.text.strip().split()[0] | |
if classification.startswith("Human"): | |
human = True | |
ai = False | |
elif classification.startswith("AI"): | |
human = False | |
ai = True | |
else: | |
raise Exception() | |
print(num, title, "Human" if human else "AI") | |
url = img["src"] | |
m = re.search( | |
"(https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F.+)$", | |
url, | |
) | |
if not m: | |
raise Exception() | |
url = urllib.parse.unquote(m.group(1)) | |
filename = os.path.basename(urllib.parse.urlparse(url).path) | |
if not os.path.exists(filename): | |
r = requests.get(url) | |
f = open(filename, "wb") | |
f.write(r.content) | |
f.flush() | |
f.close() | |
with Image.open(filename) as img: | |
if img.format == "WEBP": | |
img = img.convert("RGB") | |
buffer = BytesIO() | |
img.save(buffer, format="JPEG") | |
imagedata = base64.b64encode(buffer.getvalue()) | |
else: | |
imagedata = base64.b64encode(open(filename, "rb").read()) | |
answer = poll_llm(imagedata) | |
if answer.endswith("."): | |
answer = answer[:-1] | |
print(answer) | |
results.writerow([num, title, "Human" if human else "AI", answer]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 | Angel Woman | Human | Human | |
---|---|---|---|---|
2 | Saint In Mountains | Human | Human | |
3 | Blue Hair Anime Girl | Human | AI | |
4 | Girl In Field | AI | Human | |
5 | Double Starship | Human | AI | |
6 | Bright Jumble Woman | AI | Human | |
7 | Cherub | AI | Human | |
8 | Praying In Garden | Human | Human | |
9 | Tropical Garden | Human | Human | |
10 | Ancient Gate | AI | AI | |
11 | Green Hills | AI | Human | |
12 | Bucolic Scene | Human | Human | |
13 | Anime Girl In Black | AI | AI | |
14 | Fancy Car | Human | AI | |
15 | Greek Temple | Human | Human | |
16 | String Doll | AI | AI | |
17 | Angry Crosses | AI | Human | |
18 | Rainbow Girl | Human | Human | |
19 | Creepy Skull | Human | Human | |
20 | Leafy Lane | AI | Human | |
21 | Ice Princess | AI | AI | |
22 | Celestial Display | Human | Human | |
23 | Mother And Child | AI | Human | |
24 | Fractured Lady | AI | Human | |
25 | Giant Ship | Human | Human | |
26 | Muscular Man | AI | Human | |
27 | Minaret Boat | AI | AI | |
28 | Purple Squares | Human | Human | |
29 | People Sitting | Human | Human | |
30 | Girl In White | Human | Human | |
31 | Riverside Cafe | AI | Human | |
32 | Serene River | Human | Human | |
33 | Turtle House | AI | AI | |
34 | Still Life | AI | Human | |
35 | Wounded Christ | Human | Human | |
36 | White Blob | Human | Human | |
37 | Weird Bird | AI | Human | |
38 | Ominous Ruin | AI | Human | |
39 | Vague Figures | Human | Human | |
40 | Dragon Lady | AI | AI | |
41 | White Flag | Human | Human | |
42 | Woman Unicorn | Human | Human | |
43 | Rooftops | AI | Human | |
44 | Paris Scene | AI | Human | |
45 | Pretty Lake | AI | Human | |
46 | Landing Craft | AI | AI | |
47 | Flailing Limbs | Human | Human | |
48 | Colorful Town | Human | Human | |
49 | Mediterranean Town | AI | AI | |
50 | Punk Robot | AI | AI |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
looks like 62% accuracy to me. which is oddly close to the score humans get.