AutoCrat

A machine that writes poems in the form of formal complaints to a fictional place, generated through a local language model, will create these poems using a fountain pen and a plotter. Once written, these poems will be given to the public

Github repository is found here



How this works

A local Large Language Model (LLM) called TheBloke Dolphin 2.1 'Mistral' 7B Q6_K hosted within LLM Studio using its OpenAI API Python interface to pass an API call to the LLM to generate responses for my code in llmapi.py.

Once the user presses the button 'Q' on the keyboard, the code generates a prompt based on a list of known prompts in the file 'llmapi/llm_messages'. Then, it randomly chooses a local authority within the file 'llmapi/councils', passes the pre-prompt and prompt to the LLM, and awaits the response.

Then the response is passed too the handwriting_synthesis https://github.com/otuva/handwriting-synthesis and that generates a tool path that is cleaned up in plot.py then is sent to the pen plotter plots on to paper via the axidraw api

project journal

what i have i done

  1. Using GPT-4ALL, I have got a running LLM (Large Language Model) on a Dell PowerEdge server that will respond to a user from a prompt. It doesn't have a means of inputting information into the command at the moment.

  2. Using a tool chain of Windows applications, I got a pen plotter to write a message if manually transferred with a Hershey's font message. The pen plotter is best used with a ballpoint tip; the end goal is to use a fountain pen.

  3. The paper will need to be moved around the machine using PVC pipe rollers on skate board bearings mounted to wood, so that I can hack it together on a small budget while making it as simple to build as possible.

  4. The PCB (Printed Circuit Board) is being designed in Tinkercad at https://www.tinkercad.com/things/dmjyJZViut4-brilliant-kieran-waasa/edit. It uses photo gates to detect the paper and an H-bridge to control motors with an Arduino Uno to control it all. The code can be found at ~/Code/photogate.

  5. A folding machine will need to be bought from this guy and built.

Some minor suggestions for improvement:

standards being used

m3 bolts whenever a bolt is needed for anything
m8 smooth rods when ever anything needs to rotate
skateboard bearings used for bearings
3d printed parts out of PLA when possible on a prusa Mk4

Moving Paper

paper control 21 11 2023

designed this controller for paper control via photo gates and dc motors controlled via bridge see pic

code for the photo gates is in ~/Code/photogate
note removed the 12V and the 5V grounds separate

circuit board issues 28 11 2023

H bridges are working now i have worked out you need twise the number of them to control 4 motors and working round a floating ground issue messing with the logic voltage.

current issue is trying to pull down the voltage on the photogates as they are not being pulled down and remain at logic level High


replaced the photo transistors for photo resistors as the logic level wasn't low enough
new lay out

day at the LIB 14 12 2023

Here is the corrected text:

Using Daw.IO, I have started the flow diagram for the firmware. I have added error catching and photo gate control to the flow diagram and added an input for the user. Still, I don't know where to use servos or not - it depends on whether the paper comes out straight from the stack and if it needs stopping or not. I have left the flow chart at the plotter io state; the image is below. Still need to add this to hackaday.io.

day at the lib 18 12 2023

I'm pleased to report progress with the flow chart, and I've created a diagram of the machine in its latest form. Notably, the motor that inserts the paper into the plotter never relinquishes control while it's being written on; instead, it uses a servo to change the path of the paper to a below-level location where the folding machine is housed.

22012024 i made it real this time

using the code from this website https://microcontrollerslab.com/arduino-l293d-motor-driver-shield-tutorial/
and the pic of the test stand

23012024 got the motors working

I wrote some code to get the motors working using DeepSea to debug sections. The problem with the delay() in the loop stops anything below it from working, so all delays should be in functions.

I've got an if statement that will call the turnOnMotor() function if true, and will turn off the motors with its relevant function otherwise.

Change of direction

making a paper management mechanisms is taking too long so i will drop it

17022024 killed off the paper idea its taking too long

moved over to getting the code working and found that axi draw have an API fro there drawing program https://axidraw.com/doc/cli_api/ and im able to to use it to build it
got to the install via python3 -m pip install https://cdn.evilmadscientist.com/dl/ad/public/AxiDraw_API.zip it conflicted need to come back later

19022024 got axicli to work you can find it here

/home/alex/Documents/Autocrat/AxiDraw_API_396/python3 axicli.py --help

  1. to get the output of LLM studio
  2. to get the output of sample of the input of axicli.py
  3. to get the output of libra office cli for formatting
  4. then glue them together

20022024 got the dependencies working now lets code like a boss

re installed the openai lib via pip and now using pip3, it now all works

their should be a script that the user generates the prompt via adlib
so a box of of a location .

i have got the code to work file name is llmapi.py

now have the wizardllm uncensored and it works fine i can now generate the enquired text about what ever i like

22022024 now what

tool chain so far

LLM manger -> Libra office template -> exsport as pdf -> pdf2svg to svg -> axidraw to gcode

for pdf to svg im going to be using https://github.com/dawbarton/pdf2svg with the tool chain of pdf2svg <input.pdf> <output.svg> [<page no of pdf or "all">]

pandoc could also work with pandoc input.txt -o output.pdf

prompts

after testing with the uncensored model i found a worrying issue, that's its horribly racist and is quick to insult people. the solution is too use prepared prompts that would be

  1. petty
  2. harmless
  3. hard to be racist against

prompt list

minor issues

  1. potholes
  2. dirty buss stops
  3. cyclists
  4. bin lorry too early
  5. un emted bins
  6. too much graffiti
  7. children having too much fun during shcool hours
  8. bus is late
  9. people parking outside my house
  10. gum
  11. post office closes to early
  12. not enough cash machines
  13. roads brumby
  14. taking too long to complain
  15. the bridge is an awful color
  16. horrible cycle paths
  17. emails with the wrong name on them
  18. People who don't indicate
  19. The queue at the coffee shop moves far too slowly.
  20. Overcrowded public transport during rush hour.
  21. The constant interruption of your favorite TV show by annoying advertisements.
  22. Overpriced items in corner shop
  23. Inconsiderate dog owners who don't clean up after their
  24. pets.
  25. Littering in public places
  26. The inefficiency of public transportation systems, with frequent delays and cancellations.
  27. Overly enthusiastic salespeople who follow you around the store without giving you space to browse.
  28. Long waiting times for appointments at medical facilities, causing unnecessary stress.
  29. People who don't put their shopping trollies in the designated area after use.
  30. The lack of accessible public restrooms for individuals with disabilities.
  31. Traffic during peak hours, wasting valuable time and increasing road congestion.
  32. Unreliable internet connections during important video calls or online gaming sessions.
  33. The seemingly endless construction work on major roads.
  34. Noisy neighbours who host frequent parties or engage in loud activities late into the night.
  35. People who don't flush the toilet in public restrooms, leaving the next user with an unpleasant task.
  36. The lack of adequate parking spaces in busy areas, forcing you to walk long distances with your shopping bags or heavy luggage.
  37. stale sandwiches
  38. Excessively loud televisions in public spaces
  39. food waste
  40. Overcrowded gyms
  41. The decline of traditional letter writing due to the rise of electronic communication, leading to the loss of a cherished form of personal connection.
  42. Inconsistent recycling practices
  43. the double yellow lines aren't yellow enough
  44. neighbours house house looks too good makes mine look bad
  45. neighbours window sunlight into my eyes at noon
  46. neighbours hedge too tall
  47. neighbours hedge too short
  48. corner shop does stock my favourite biscuits

GitHub

time too upload to github its getting hard to keep track of things on my laptop alone

25022024 adding git and variables

I added it to my Git. I used the DeepSeek 7B model to help with making the UI, as I've not made anything with GUI before. After reading the code from the printer in the hackerspace, I chose to use the same library, Tkinter.

29022024 it works and its ugly

did some coding on the way home from the space and bashed out a GUI with the help of deep seek as I not used that library before and it works.


next task is too get the ui to call the right functions with the data selected by the user

Designing the machine

How this machine is going to be laid out with a track ball in the front of the monitor and the pen plotter too the side
edit: this is stupid i changed this

new design a big red button that says complain

due to how much of an issue the GUI is I will remove it so can finish on time and will now randomly chose a prompt when the user presses a button on HID device

04032024 going to be a good day

Possible to use an Uno as a HID (Human Interface Device) and have a micro-switch trigger a keyboard button. Maybe there's a HackDay article on the subject.

todo

  1. get the code to trigger text gen on a button press DONE
  2. get the prompts to read the file of promts randomly and add this to the varible of the prompt DONE
  3. get a one button keyboard to work

good news

both my CPP's for EMF camp have been accepted that is both this autocrat and the trebuchet

even better news it works


made the code more functional and less procedural you now can edit the promt and pre promt in thier own functions and are genrated on the fly from a list of promts and councils

11032024 txt to gcode the story

writing more functions

my code doesnt work i wrote a lot of functions so will come back tomorrow and re do it

12032024 get in the .md

wrote more code to get it to output into a .md file however this is all on one line a porblem for later

  1. DONE fix output of convert_to_markdown(message): too format using the /n for new lines

now time to get it talking to pandoc its having a hissy fit using this command pandoc -f markdown output.md -t test.pdf

fixed the output of the message and fixed the /n with a replace

  1. encoding error

14032024

code works to produce pdf file now need to format the file to look like a letter using LaTex

  1. use the built in pyhon read file functiuon to read the file as the front matter is being added to the output.md in one line
    now complaining about font familys like the front mater worked !

1803202024

built the pen plotter and got it plotting

added a arm to hold down paper its 3d printed

Pen plotter issues

19032024 api time and testing time

debugging the pen plotter as their was some issues with voltage on the stepper drivers as so upped them to 0.8v over 0.5v this solved the issue


did some user testing on single line fonts and found a couple contenders one beeing

  • EMSNeato
  • EMSDelight
    both can be found in the fonts folder of the repo

updated the board to work with a the home Gcode now its orgin is in the top left of the machine

code is being started to be made on the automatic plotting of the markdown with the plot.py file

added files to make svg and try and convert them this can be found in the history of chatgpt and the
files

AI hand writing time

https://github.com/sjvasquez/handwriting-synthesis
this was used by stuff made here to great affect it should solve both the hand writing issue and taking the text and converting into something that the pen plotter can use

  1. get the repo working
    ive added it repo

21032024 build tensor flow from source

https://github.com/sjvasquez/handwriting-synthesis needs tensor flow and as i dont have a gpu in the server i wil be needing it to be done using cpu so that means building from source YAY/s

export CUDA_VISIBLE_DEVICES=""

updated the git to this new repo https://github.com/otuva/handwriting-synthesis

its working

to get the genration working you need to get it to running in a enviroment


(hand_gen_env) alex@henry:~/Documents/Autocrat/handwriting-synthesis$ python3 -m venv hand_gen_env
(hand_gen_env) alex@henry:~/Documents/Autocrat/handwriting-synthesis$ python main.py

struggling to get axidraw connected to the server

got the axi draw working on the server i needs a regex from the

height="100%" to height="1052.362179" and width="100%"  to width="744.09447"

the pen plotter chrashes now this is good fun/s

good idea is to try and realses the internal of the pen plotter and try again

the above code works btw and now need to get it working for my project

26032024 nearly their

things too do

  • regex replace the 100% with a4 dimentions so that i can be pen plotted
  • split up the compaint into 75 char lines
  • make a button and attach it to the plotter
  • write a good read me
  • comit new code
  • cite who i got this forcked code off
  • line 118 is sus got need to look at that look at chat gpt
  • fix the ns0 attribuite in plot.py

Things I have done today,

I have managed to get the handwriting recognition model working, and it is now installed into my code with the output of the LLM Bing piped into the input of the model. Additionally, I have added a plot.py file for testing the plotter as it was having issues with reliability; this was resolved by reflowing the USB port on the PCB and changing out the cable.

Hardware home run

29032024 almost

fixed the code that sorts the lines into 75 char long and now outputs a short poem this is a good idea as its speeds things up
problem is that it still draws the box the issue is that the <ns0:defs /><ns0:rect height="1052.362179" width="744.09447" x="0" y="0" /> is making a black sqaure that the plotter plots and its an issue alos having stability issues with the code
the git has also gone missing so need to repair that
an idea is too whole sale replacemnt of top of the svg and get the correct one from the bottom axi draw api

01042024 its working

used a hacky fix to make sure the svg is valid by chopping off the top and adding valid svg headers from a known file.
trimmed in the plotter as it was having issues with one side being a little too high
code now works after i spent so long trying to get it to work this has taken a long time

so far I have

  1. learnt eltronics from scratch only not too use it in the this project as it would have taken too long
  2. though it could be done in a long shell script how wrong i was
  3. learnt python3 with the help of the hackspace and my own dedication
  4. screamed at a server for far too long
  5. knowing how to maintain a ubuntu server and get linux to do things i never thought i could do without re imaging it.
  6. building a pen plotter without instructions as there whernt any
  7. interfacing with an api
  8. writing a function for that

Testing

the pen plotter needs to be reliable so to test the pen it can do something useful as well, m


can you spot the error in this i can i will have too re do this

Machine is "born"

finally i can say it is all in one piece ( minus the servo board that broke )

with the screen off


with the screen on

Promo and documentation

writing the promo posters

making the posters off the .GOV website the whole project is ment to be piss take so why not the branding too
so i present the new logo of the Autocrat

how to posters

in publisher writing the how to poster

promo poster

a promo poster is going to be next to the machine showing how it was made this was also made in publisher

Done

Now the replacement EBB board arrived I can now finish the project. so lets go over what I did

  1. programmed the start and stop buttons too use autokey shortcuts too launch the LLAPI.py script
  2. The stop key is simply a Ctrl + C as this the only way the EBB board can be stopped with software, as in the API does not contain a means of pausing with software. the only way i can pause it manually is a small button on the board it's self delicate.
  3. Pen plotter screwed down to the bed
  4. Written a UI in terminal
  5. Added power cut-off for the 12v + rail thought a lightswitch