Introduction
Introduction Statistics Contact Development Disclaimer Help
dalle-gen-emoji - annna - Annna the nice friendly bot.
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6…
Log
Files
Refs
Tags
README
---
dalle-gen-emoji (1344B)
---
1 #!/usr/bin/env python
2 # coding=utf-8
3 #
4 # Kiss me when you can.
5 # by annna
6 #
7
8 import os
9 import os.path
10 import sys
11 import getopt
12 import requests
13 import base64
14
15 def usage(app):
16 app = os.path.basename(app)
17 print("usage: %s [-h] [::]some-emoji[:key=value...][::]" % (app),
18 file=sys.stderr)
19 sys.exit(1)
20
21 def main(args):
22 try:
23 opts, largs = getopt.getopt(args[1:], "h")
24 except getopt.GetoptError as err:
25 print(str(err))
26 usage(args[0])
27
28 for o, a in opts:
29 if o == "-h":
30 usage(args[0])
31 else:
32 assert False, "unhandled option"
33
34 if len(largs) < 1:
35 usage(args[0])
36
37 emoji = " ".join(largs)
38 emoji = emoji.strip("::")
39 emoji = emoji.replace(":", " ").replace(",", " ").replace("=", "…
40 replace(".", " ").replace("/", " ")
41 emoji = emoji.lower()
42
43 emojifile = "%s.jpg" % (emoji.replace(" ", "-"))
44
45 filebase = "/br/ai/dalle/dalle-results/"
46 emojiuribase = "gophers://bitreich.org/I/emoji/"
47 imguri = "http://127.0.0.1:32553/dalle"
48 jsonreq = {"text": emoji, "num_images": 1}
49
50 filepath = "%s%s" % (filebase, emojifile)
51 if not os.path.exists(filepath):
52 try:
53 answer = requests.post(imguri, json=jsonreq)
54 except:
55 return 1
56
57 fd = open(filepath, "wb")
58 fd.write(base64.b64decode(answer.json()[0]))
59 fd.close()
60
61 print("%s%s" % (emojiuribase, emojifile))
62
63 return 0
64
65 if __name__ == "__main__":
66 sys.exit(main(sys.argv))
67
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.