“This machine can produce a five-thousand-word story, all typed and ready for dispatch, in thirty seconds. How can the writers compete with that?” Roald Dahl, The Great Automatic Grammatizator
One of the first literary anticipations of virtual reality was Adolfo Bioy Casares's Plan de Evasión in 1945 and the same year Roald Dahl published what could be considered some sort of generative AI in The Great Automatic Grammatizator.
With some inspiration from Roald Dahl’s story I designed an AI powered typewriter.
How does it work?
The device has a Python coded text editor similar to any other text editor but with an option to insert bursts of ChatGPT text considering previous material and based on specific styles (Hemingway like, surrealist and childish)
Parts
For the Grammatizator I did use
- A Raspberry Pi 2 with USB WiFi dongle (required for API calls)
- A small USB keyboard
- DFRobot LCD screen (great screen, BTW. One ribbon and no libraries to install at all)
- A custom made 3d printed enclosure
Software
The machine is a classic Raspberry Pi 2. The software is coded in Python, which has a library for OpenAI API. For the text editor I did use Tkinter. Some modifications were made to Raspberry Pi OS in order to autostart the Desktop app without taskbar.
python -m pip install pillow
sudo apt-get install python3-pil.imagetk
pip3 install openai
Kiosk mode
sudo nano /etc/xdg/autostart/display.desktop
[Desktop Entry]
Version=1.0
Name=Grammatizator
Comment=AI powered typewriter
Exec=/home/roni/grammatizator.py
Icon=/usr/share/pixmaps/python.xpm
Path=/home/roni/
Terminal=false
StartupNotify=true
Type=Application
Categories=Utility;Application;
chmod +x /home/roni/.config/autostart/chatgpt.desktop
Disable low voltage warning
$ sudo apt remove lxplug-ptbatt
Remove taskbar
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
#@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
OpenAI API and ChatGPT prompt
Existing text is being sent to OpenAI API as part of a prompt that also considers a selected style between:
- A dry prose, Hemingway sort of
- A poetic and surrealist prose
- Simple childish tone
Temperature setting is also modified according to the style. Low temperature is used for focused and conservative text generation and values closer to 1 for more creative and unexpected texts.
completion = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=temperatura,
)
response = completion.choices[0].text
response = response.strip()
response = response.replace("-", "")
Final notes
“He found himself, almost immediately, up against the old truth that a machine, however ingenious, is incapable of original thought. It can handle no problems except those that resolve themselves into mathematical terms problems that contain one, and only one, correct answer” another interesting quote form Roald Dahl that could be related to AI.
This was a fun project not complicated at all to make at all since there wasn't circuits involved or a challenging coding. Being a fiction writer myself, results of using the Grammatizator with ChatGPT bursts for a quick fiction are unexpected and interesting.
TikTok
https://www.tiktok.com/@ronibandini/video/7328438176211537157
Demo
Go to 2.28 for the actual demo
Source code and instructionsSource code and instructions can be obtained at Patreon
Interested in other artistic machines?- The machine to think of Gladys (Mario Levrero)
- Nyctograph machine (Lewis Carrol)
- The Klausner Machine (Roald Dahl)
- Reading machine (Raymond Roussel)
- The Argentinian rain making machine
- Hunter S. Thompson ASCII art installation
- Haiku reader
- Literature machines
Comments