Created
March 10, 2022 02:16
-
-
Save HuemanInstrument/65b97e8bd9d0de4c57d5a0ff0c54d623 to your computer and use it in GitHub Desktop.
GauGAN2 automation code
This file contains 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
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
import os | |
import time | |
import sys | |
import helpers | |
import urllib | |
import PIL.ImageGrab | |
driver = webdriver.Chrome('chromedriver.exe') | |
time. sleep(3) | |
PPP=1 | |
#important number^ you'll have to edit this one to tell it what image you want it to start with. | |
z=0 | |
while(PPP <99999): | |
driver.get('http://gaugan.org/gaugan2/') | |
while (z <1): | |
time. sleep(7) | |
z = z+1 | |
########################################################### | |
#These check the boxes at the top, sometimes you have to check them or uncheck them and this is a good place to do that, just remove the hashtag for the box you want to check / uncheck | |
############################################################ | |
#driver.find_element_by_class_name("shepherd-cancel-icon").click() | |
#time. sleep(1.5) | |
#driver.find_element_by_id("enable_edge").click() | |
#time. sleep(0.8) | |
#driver.find_element_by_id("enable_text").click() | |
#time. sleep(0.8) | |
#inputElement = driver.find_element_by_id("text_input") | |
#time. sleep(0.8) | |
############################################################ | |
#this one types out words in the word prompt field | |
############################################################ | |
#inputElement.send_keys('Aquarium watercolor acrylic Lithograph underwater Tintype') | |
time. sleep(1) | |
driver.maximize_window() | |
time. sleep(1.5) | |
driver.execute_script("window.scrollTo(0,document.body.scrollHeight)") | |
time. sleep(1.5) | |
#REAL FILE | |
############################################################ | |
#These will put an image into the "image" thing | |
############################################################ | |
#upload_file = driver.find_element_by_id("realfile") | |
#upload_file.send_keys('D:\\D visuals\\Gif Frames\\91\\' + str(PPP) + '.png') | |
#time. sleep(1) | |
#driver.find_element_by_id("btnRealLoad").click() | |
#time. sleep(1) | |
#SEGMAP FILE These put an image into the segmap place | |
upload_file = driver.find_element_by_id("segmapfile") | |
upload_file.send_keys('D:\\D visuals\\Gif Frames\\92\\' + str(PPP) + '.png') | |
time. sleep(1.5) | |
driver.find_element_by_id("btnSegmapLoad").click() | |
time. sleep(1) | |
#SKETCH FILE | |
#upload_file = driver.find_element_by_id("sketchfile") | |
#upload_file.send_keys('D:\\D visuals\\GAUGANGELLION\\Episode_1\\FramesSeg\\' + str(PPP) + '.png') | |
#time. sleep(0.9) | |
#driver.find_element_by_id("btnSketchLoad").click() | |
#time. sleep(0.9) | |
############################################################ | |
#Extra button clicking at the top | |
############################################################ | |
#driver.find_element_by_id("enable_image").click() | |
#time. sleep(0.8) | |
#driver.find_element_by_id("enable_seg").click() | |
#time. sleep(0.2) | |
############################################################ | |
#this makes sure that you've got the Captcha checked at the bottom | |
############################################################ | |
driver.find_element_by_id("myCheck").click() | |
time. sleep(1) | |
#driver.find_element_by_id("enable_seg").click() | |
#time. sleep(0.7) | |
#driver.find_element_by_id("enable_image").click() | |
#time. sleep(0.8) | |
############################################################ | |
#this will hit the calculate sketch button, make sure you give it that 17 second sleep or so just to make sure it completes the process | |
############################################################ | |
#driver.find_element_by_id("get_sketch").click() | |
#time. sleep(17) | |
############################################################ | |
#This is the GO button, it chooses the 7th example, but you could point it to any of the choices or a random choice if you wanted, just hit f11 in your normal chrome browser when you're looking at the gaugan page, and look for the ID of the choice you want, then plug it in here | |
############################################################ | |
driver.find_element_by_id("example7").click() | |
time. sleep(19) | |
############################################################ | |
#This is to align your window so that it can take a screenshot properly, you'll have to mess with this one a lot I imagine, just remember x y = left to right (positive numbers) = up- and down+ (negative numbers?) lol idk why i wrote plus after down there... this might be bad info actually, you'll have to sort this out yourself I can't test right now. | |
############################################################ | |
#driver.execute_script("window.scrollBy(177,171)") | |
driver.execute_script("window.scrollBy(177,60)") | |
#driver.execute_script("window.scrollBy(177,60)") | |
############################################################ | |
#this is the script to zoom in and take a screenshot | |
#You'll have to input your own directory here of course, this directory needs to be the same as the next directory we call upon coming up- | |
############################################################ | |
driver.execute_script("document.body.style.zoom='89%'") | |
time. sleep(1.5) | |
driver.get_screenshot_as_file('E:\\programming\\newseg\\' + 'potato' + str(PPP) + '.png') | |
time. sleep(2.5) | |
from PIL import Image | |
time. sleep(0.7) | |
############################################################ | |
#This is important, it checks on this exact coordinate if your image had a white pixel | |
#If you're not mindful of this it could wind up making your projects not work correctly | |
#but this is a neccesary evil because GauGAN2 doesn't always produce image results, sometimes they just turn out 100% white | |
#so if it turns out white, it just tries the process over again with this code | |
############################################################ | |
im = Image.open('E:\\programming\\newseg\\' + 'potato' + str(PPP) + '.png') | |
time. sleep(0.7) | |
px = im.load() | |
time. sleep(0.7) | |
coordinate = x, y = 1350, 250 | |
time. sleep(0.7) | |
############################################################ | |
#this is used to print coordinate to see if it's sampling a white color zone or not in your powershell thing | |
############################################################ | |
print (im.getpixel(coordinate)) | |
P = (im.getpixel(coordinate)) | |
print (sum(P)) | |
if (sum(P)) >= 1019: | |
continue | |
time. sleep(1.2) | |
PPP = PPP+1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment