diff options
author | msglm <msglm@techchud.xyz> | 2023-01-11 20:45:33 -0600 |
---|---|---|
committer | msglm <msglm@techchud.xyz> | 2023-01-11 20:45:33 -0600 |
commit | 9798cadf3116edc24684fdcd23a14ea4bb35abdc (patch) | |
tree | ec177263625dc0a1cd1c52f530e4c01a4af0066b /dalle_mini_api.nim | |
parent | c78b95c7c8482f92128cf0f702ab2884b2f59418 (diff) | |
download | dallegen-9798cadf3116edc24684fdcd23a14ea4bb35abdc.tar.gz dallegen-9798cadf3116edc24684fdcd23a14ea4bb35abdc.tar.bz2 dallegen-9798cadf3116edc24684fdcd23a14ea4bb35abdc.zip |
improved the number parameter and added an option to upscale
Diffstat (limited to 'dalle_mini_api.nim')
-rw-r--r-- | dalle_mini_api.nim | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/dalle_mini_api.nim b/dalle_mini_api.nim deleted file mode 100644 index d11d8f1..0000000 --- a/dalle_mini_api.nim +++ /dev/null @@ -1,64 +0,0 @@ -import argparse -import std/httpclient -import std/base64 -import std/oids -import std/json -import std/strutils - -var parser = newParser: - help("Abuse the dalle-mini API from the cli!") - option("-o", "--output", help="Write output to this folder", default=some("/tmp/")) - option("-n", "--number", help="number of images you'd like", default=some("9")) - arg("prompt", nargs = -1) - - -try: - let arguments = parser.parse() - var client = newHttpClient(userAgent="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0") - client.headers = newHttpHeaders({ - "Accept":"application/json", - "Accept-Language":"en-US,en;q=0.5", - "Accept-Encoding":"gzip, deflate, br", - "Referer":"https://hf.space/", - "Content-Type":"application/json", - "Origin":"https://hf.space", - "DNT":"1", - "Connection":"keep-alive", - "Sec-Fetch-Dest":"empty", - "Sec-Fetch-Mode":"cors", - "Sec-Fetch-Site":"cross-site" - }) - - for parsedPrompt in arguments.prompt: - echo "Now generating: " & parsedPrompt - var data = "{\"prompt\":\"" & parsedPrompt & "\"}" - var response: Response - var max = (parseInt(arguments.number)/9 + 1) - for i in countup(0,toInt(max)): - echo "New run..." - - echo "Waiting for response..." - response = client.request("https://bf.dallemini.ai/generate", httpMethod = HttpPost, body=data) - while response.status != "200 OK": - echo "Could not get response due to " & response.status & "! Trying again in 15 seconds!" - sleep 15 - response = client.request("https://bf.dallemini.ai/generate", httpMethod = HttpPost, body=data) - - var JSONifiedResponse = parseJSON(response.body) - for encodedImage in JSONifiedResponse["images"]: - var stringImage = $encodedImage - #var image = base64.decode(stringImage.replace("\\").replace("\"").replace("=")) - #echo stringImage.replace("\\n").replace("\"") - var image = base64.decode(stringImage.replace("\\n").replace("\"")) - var filename = arguments.output & parsedPrompt & " - " & $oids.genOid() & ".jpg" - echo "writing image to " & filename - writeFile(filename, image) - - -except ShortCircuit as e: - if e.flag == "argparse_help": - echo parser.help - quit(1) -except UsageError: - stderr.writeLine getCurrentExceptionMsg() - quit(1) |