icon

Grammatizator, fiction writing assisted by ChatGPT

With some inspiration from a 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 (dry, surrealist and child oriented)

 

 

Parts

 

A Raspberry Pi 2 with USB WiFi dongle (Raspberry Pi 4 is better and you don't need the USB dongle)
 

A small USB keyboard
 

5" DFRobot Touchscreen DSI screen (great screen, BTW. One ribbon and no libraries to install at all) 
 

A custom made 3d printed enclosure 

 


 

 

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 Hemingway, a poetic and surrealist prose or a 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.

Final notes

This was a fun project not complicated to make at all since there wasnt 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.

Sources
https://d-a-v-e.org/wp/wp-content/uploads/2020/09/The_Great_Automatic_Grammatizator.pdf 
https://www.linkedin.com/pulse/temperature-check-guide-best-chatgpt-feature-youre-using-berkowitz/

“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”

CODE
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

Configuración del kiosk

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

 

Typed text is sent to OpenAI API as part of a prompt that also considers a selected style between: a dry Hemingway, a poetic and surrealist prose or a 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.


 

Final notes

 

This is a fun project not so complicated to make since there wasn't circuits involved or a challenging coding. DFRobot screen is connected with just one ribbon and there are no complicated libraries or configurations to change. 

 

From coding point of view, knowing how to use the openAI API from Raspberry Pi/Python will unlock a world of possibilities

 

TikTok

 

https://www.tiktok.com/@ronibandini/video/7328438176211537157

 

 

CODE
import openai

openai.api_key  = ""
model_engine    = "text-davinci-003"
temperatura     = 0.5

myText=text_area.get(1.0, END)
   myLen=len(myText)

   if myLen>10:
       prompt=promptPrefix + myText

       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("-", "")

       typeit(text_area, "end", response)
License
All Rights
Reserved
licensBg
0