Originally presented as a short talk to IGDA Ann Arbor on November 11, 2022.
Basically I want to automate this process…
Please see the previous 2 blogs for the fine details.
Manual process:
●ScummVM with ‘Windham’ extension
Extract clusters to .cls (raw data)
●Python + Image Magick
Upscale and convert to .PNG
●Python + GIMP
Add noise
●Stable Diffusion using Automatic1111 WebUI
AI Art paintover and paint-in
●GIMP
Manually composite screens back together
High level goals:
●Automate tedious and error prone steps
●Manage lots of image files
●Associate game data (text, rules, audio)
●Present a project snapshot
●Support collaboration
●Hot load game data on any device
●Direct AI Art
●Free (as in Beer)
Let’s just use Google Sheets: Organize the Data!
Let’s just use Google Sheets: Grid Layout
Note the indirect address magic to get the cells from a column into a grid.
Now I have a nice snapshot of the whole map in the original art.
How do I get images into Google Sheets using Python?
●1) First you need a Google Developer Account - https://developers.google.com/
●2) Next you need a Project
●3) Then you need to turn on the Google APIs for your Project
●4) Also you need to set up a service account
●5) And you need to create credentials for the service account
●6) Finally you need to share your Google drive and/or docs with the service account
How do I get images into Google Drive and Sheets? Step by step:
●1) First you need a Google Developer Account - https://developers.google.com/
●2) Next you need to create or add a Project
●3) Then you need to turn on the Google APIs for your Project
●4) Also you need to set up a service account
●5) And you need to create credentials for the service account
●6) Finally you need to share your Google drive and/or docs with the service account
How do I get images into Google Sheets with Python? Prep
Python - There are lots of ways to get python, but a lot of the Stable Diffusion libraries use miniconda. So let's just use that.
PIP - PIP is a package manager for python that makes it super easy to install dependencies.
Google APIs - Super easy to install the google APIs using PIP.
How do I get images into Google Drive and Sheets? Import
●Imports, scopes, init APIs, load credentials, use sheet UUID
The first section is all about imports that the examples below use for interacting with google APIs, printing to the console, saving/loading files, and running external processes. The second section sets up scopes and permissions for accessing your google drive and sheets. The third section initializes the python interface to the google docs and sheets APIs. Finally, we have a link to the 'master control' google sheet.
The UUID of the google sheet is right there in the URL.
●Find/create folder
In google drive, the file system is 'flat' and a 'directory' is really just a label on a given file. The procedure for getting a folder is to first see if it exists, otherwise create one.
●Find/create folder, find/create file
Similarly, a file can either be created or updated depending on whether it already existed. If you don't check for existence first, then you can end up with multiple files with the same name!
Create a sub-sheet if it doesn’t already exist
Check to see if the subsheet exists. The only way I found way to try and access it and then handle the exception if the lookup fails. Also, for subsheet operations, you have to use the 'batch update' approach and embed JSON in the request.
●Fill in header and rows in spreadsheet
Here we are setting up a template row and updating the subsheet with that.
This is what the subsheet looks like with a header and a sample row.
Linking images in google sheets with URL and =Image
Any image you want to see in a google sheet will have to be shared with your account. OR you can share the whole folder.
The UUID for the image is buried in its URL.
Use this image lookup template URL with the UUID of your image.
And then you can reference a URL in another cell using the =image(...cellid...) approach.
●Download and save to local file example
Here is an example of pulling a file from google drive and saving it locally.
●Processing with Python and GIMP
Here is an example of running a simple 'command line' application from within Python.
Here is a more complex example where we use 'subprocess' instead and do a bunch of string mangling with \\ and such to run an exe in a path with spaces and with multiple arguments including single-quote sections.
And here is a gimp-fu python script.
Now push the files back up and add to sheet
Here is an example of uploading an image to google drive and linking it back into the google sheet.
Here’s the sheet we auto-populated
Neat! Now we can batch process 'cluster' files from Python and Google Sheets!
Coming soon, questions, and comments….
●Driving Stable Diffusion from a spreadsheet and a Python daemon
●Art directing from a Google Sheet
●Automatic composition
●Running a game from data in a Google Sheet
●How are/could you use Google Sheets in your project?
Comentários