|
@@ -1,4 +1,5 @@
|
1
|
1
|
from flask import Flask, render_template, request, abort, send_from_directory
|
|
2
|
+import openai
|
2
|
3
|
from dotenv import load_dotenv
|
3
|
4
|
from markdown import markdown
|
4
|
5
|
from glob import glob
|
|
@@ -12,9 +13,6 @@ import re
|
12
|
13
|
RE_VID = re.compile("""\[video ["']([^['"]*?)["']\]""")
|
13
|
14
|
TEMPLATE_VID = """<video controls class="centered"><source src="{}" type="video/{}"></video>"""
|
14
|
15
|
|
15
|
|
-RE_SOUNDTRACK = re.compile("""\[soundtrack ["']([^['"]*?)["']\]""")
|
16
|
|
-TEMPLATE_SOUNDTRACK = """<audio loop data-autoplay><source src="{}" type="audio/{}"></audio>"""
|
17
|
|
-
|
18
|
16
|
def preprocess_content(defs):
|
19
|
17
|
md = defs.get("markdown", "")
|
20
|
18
|
if md:
|
|
@@ -44,6 +42,7 @@ def preprocess_payload(payload):
|
44
|
42
|
slide["content"] = preprocess_content(slide)
|
45
|
43
|
|
46
|
44
|
load_dotenv()
|
|
45
|
+openai.organization = "org-GFWgNyt7NSKpCv6GhzXYZTpi"
|
47
|
46
|
|
48
|
47
|
application = Flask(__name__)
|
49
|
48
|
|
|
@@ -51,7 +50,7 @@ application = Flask(__name__)
|
51
|
50
|
def home():
|
52
|
51
|
payload = json.load(open("static/slides.json"))
|
53
|
52
|
preprocess_payload(payload)
|
54
|
|
- return render_template("slides.html", **payload)
|
|
53
|
+ return render_template("slides.html", generate_indices=False, **payload)
|
55
|
54
|
|
56
|
55
|
@application.post("/update")
|
57
|
56
|
def update():
|
|
@@ -64,7 +63,7 @@ def update():
|
64
|
63
|
print(type(payload))
|
65
|
64
|
json.dump(payload, sys.stdout, indent=4)
|
66
|
65
|
json.dump(payload, open("static/slides.json", "w"), indent=4)
|
67
|
|
- return({"status": "success"})
|
|
66
|
+ return {"status": "success"}
|
68
|
67
|
|
69
|
68
|
@application.get("/enum/<topic>")
|
70
|
69
|
def choices(topic):
|
|
@@ -72,14 +71,23 @@ def choices(topic):
|
72
|
71
|
return {"type": "string", "enum": glob("static/{}/*.*".format(topic))}
|
73
|
72
|
abort(404)
|
74
|
73
|
|
75
|
|
-@application.get("/schema.json")
|
76
|
|
-def schema():
|
77
|
|
- return render_template("slides.schema.json", backgrounds=choices("bg"))
|
78
|
|
-
|
79
|
74
|
@application.get("/editor")
|
80
|
75
|
def editor():
|
81
|
76
|
return render_template("editor.html")
|
82
|
77
|
|
|
78
|
+@application.route("/img", methods=['GET', 'POST'])
|
|
79
|
+def image():
|
|
80
|
+ if request.method=='GET':
|
|
81
|
+ src = "static/img/marble-question-mark.png"
|
|
82
|
+ alt = "A question mark"
|
|
83
|
+ prompt = ""
|
|
84
|
+ else:
|
|
85
|
+ prompt = request.form["prompt"]
|
|
86
|
+ alt = prompt
|
|
87
|
+ response = openai.Image.create(prompt=prompt, n=1, size="1024x1024")
|
|
88
|
+ src = response['data'][0]['url']
|
|
89
|
+ return render_template("image.html", src=src, alt=alt, prompt=prompt)
|
|
90
|
+
|
83
|
91
|
@application.route("/favicon.ico")
|
84
|
92
|
def favicon():
|
85
|
93
|
return send_from_directory(os.path.join(application.root_path, "static"),
|