Browse Source

`generate_indices` is conditional, add openai

`/img` is an image generator (handy)
master
The Dod 1 year ago
parent
commit
01b4517d6d
4 changed files with 60 additions and 34 deletions
  1. 17
    9
      app.py
  2. 1
    0
      requirements.txt
  3. 24
    10
      static/slides.json
  4. 18
    15
      templates/slides.html

+ 17
- 9
app.py View File

1
 from flask import Flask, render_template, request, abort, send_from_directory
1
 from flask import Flask, render_template, request, abort, send_from_directory
2
+import openai
2
 from dotenv import load_dotenv
3
 from dotenv import load_dotenv
3
 from markdown import markdown
4
 from markdown import markdown
4
 from glob import glob
5
 from glob import glob
12
 RE_VID = re.compile("""\[video ["']([^['"]*?)["']\]""")
13
 RE_VID = re.compile("""\[video ["']([^['"]*?)["']\]""")
13
 TEMPLATE_VID = """<video controls class="centered"><source src="{}" type="video/{}"></video>"""
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
 def preprocess_content(defs):
16
 def preprocess_content(defs):
19
     md = defs.get("markdown", "")
17
     md = defs.get("markdown", "")
20
     if md:
18
     if md:
44
             slide["content"] = preprocess_content(slide)
42
             slide["content"] = preprocess_content(slide)
45
 
43
 
46
 load_dotenv()
44
 load_dotenv()
45
+openai.organization = "org-GFWgNyt7NSKpCv6GhzXYZTpi"
47
 
46
 
48
 application = Flask(__name__)
47
 application = Flask(__name__)
49
 
48
 
51
 def home():
50
 def home():
52
     payload = json.load(open("static/slides.json"))
51
     payload = json.load(open("static/slides.json"))
53
     preprocess_payload(payload)
52
     preprocess_payload(payload)
54
-    return render_template("slides.html", **payload)
53
+    return render_template("slides.html", generate_indices=False, **payload)
55
 
54
 
56
 @application.post("/update")
55
 @application.post("/update")
57
 def update():
56
 def update():
64
     print(type(payload))
63
     print(type(payload))
65
     json.dump(payload, sys.stdout, indent=4)
64
     json.dump(payload, sys.stdout, indent=4)
66
     json.dump(payload, open("static/slides.json", "w"), indent=4)
65
     json.dump(payload, open("static/slides.json", "w"), indent=4)
67
-    return({"status": "success"})
66
+    return {"status": "success"}
68
 
67
 
69
 @application.get("/enum/<topic>")
68
 @application.get("/enum/<topic>")
70
 def choices(topic):
69
 def choices(topic):
72
         return {"type": "string", "enum": glob("static/{}/*.*".format(topic))}
71
         return {"type": "string", "enum": glob("static/{}/*.*".format(topic))}
73
     abort(404)
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
 @application.get("/editor")
74
 @application.get("/editor")
80
 def editor():
75
 def editor():
81
     return render_template("editor.html")
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
 @application.route("/favicon.ico")
91
 @application.route("/favicon.ico")
84
 def favicon():
92
 def favicon():
85
     return send_from_directory(os.path.join(application.root_path, "static"),
93
     return send_from_directory(os.path.join(application.root_path, "static"),

+ 1
- 0
requirements.txt View File

1
 python-dotenv
1
 python-dotenv
2
 flask
2
 flask
3
+openai
3
 markdown
4
 markdown

+ 24
- 10
static/slides.json View File

41
                 {
41
                 {
42
                     "id": "sins_against_others",
42
                     "id": "sins_against_others",
43
                     "title": "Sins against others",
43
                     "title": "Sins against others",
44
-                    "params": {
45
-                        "background-opacity": "0.5",
46
-                        "background-size": "contain"
47
-                    },
48
-                    "markdown": "* Anger\n* Disrespect",
44
+                    "params": {},
45
+                    "markdown": "You mentioned regret. You mentioned sorrow. \n\nLet me play for you a Hawaiian song called Ho'Opnopono. it has healing qualities for such moments.\n\n* Close your eyes.\n* Listen.\n* Sing in your heart.\n* Join with your voice.",
49
                     "soundtrack": "static/audio/ho-oponopono.mp3"
46
                     "soundtrack": "static/audio/ho-oponopono.mp3"
50
                 }
47
                 }
51
             ]
48
             ]
54
             "id": "intospection",
51
             "id": "intospection",
55
             "title": "Introspection",
52
             "title": "Introspection",
56
             "params": {
53
             "params": {
57
-                "theme": "league",
54
+                "theme": "beige",
58
                 "background-video": "static/bg-video/underwater.mp4",
55
                 "background-video": "static/bg-video/underwater.mp4",
59
                 "background-video-loop": true,
56
                 "background-video-loop": true,
60
-                "background-video-mute": true,
61
-                "background-opacity": "0.25"
57
+                "background-video-mute": true
62
             },
58
             },
63
             "markdown": "# \u262f\n",
59
             "markdown": "# \u262f\n",
64
             "soundtrack": "static/audio/sonar.wav",
60
             "soundtrack": "static/audio/sonar.wav",
65
-            "slides": []
61
+            "slides": [
62
+                {
63
+                    "id": "test",
64
+                    "title": "This is a test",
65
+                    "params": {
66
+                        "theme": "simple",
67
+                        "background-image": "static/bg/sea-view-garden.png",
68
+                        "background-opacity": "0.5",
69
+                        "background-size": "cover"
70
+                    },
71
+                    "image": {
72
+                        "placement": "none",
73
+                        "width": "50",
74
+                        "source": "static/img/horse.png",
75
+                        "alt": ""
76
+                    },
77
+                    "markdown": "Stay tuned..."
78
+                }
79
+            ]
66
         }
80
         }
67
     ]
81
     ]
68
-}
82
+}

+ 18
- 15
templates/slides.html View File

36
                                         {# column's top slide #}
36
                                         {# column's top slide #}
37
                                         <h3 class="title slide_title">{{column.title}}</h3>
37
                                         <h3 class="title slide_title">{{column.title}}</h3>
38
                                         {% if column.content %}{{ column.content|safe }}{% endif %}
38
                                         {% if column.content %}{{ column.content|safe }}{% endif %}
39
-                                        {# Main column shows links to other columns #}
40
-                                        {% if loop.first %}
41
-                                            <ul>
42
-                                                {% for other in columns %}
43
-                                                    {% if not loop.first %}<li><a href="#/{{other.id}}">{{other.title}}</a></li>{% endif %}
44
-                                                {% endfor %}
45
-                                            </ul>
46
-                                        {% endif %}
47
-                                        {# if column has sub-slides, link to them #}
48
-                                        {% if column.slides %}
49
-                                            <ul>
50
-                                                {% for slide in column.slides %}
51
-                                                    <li><a href="#/{{column.id}}_{{slide.id}}">{{slide.title}}</a></li>
52
-                                                {% endfor %}
53
-                                            </ul>
39
+
40
+                                        {% if generate_indices %}
41
+                                            {# Main column shows links to other columns #}
42
+                                            {% if loop.first %}
43
+                                                <ul>
44
+                                                    {% for other in columns %}
45
+                                                        {% if not loop.first %}<li><a href="#/{{other.id}}">{{other.title}}</a></li>{% endif %}
46
+                                                    {% endfor %}
47
+                                                </ul>
48
+                                            {% endif %}
49
+                                            {# if column has sub-slides, link to them #}
50
+                                            {% if column.slides %}
51
+                                                <ul>
52
+                                                    {% for slide in column.slides %}
53
+                                                        <li><a href="#/{{column.id}}_{{slide.id}}">{{slide.title}}</a></li>
54
+                                                    {% endfor %}
55
+                                                </ul>
56
+                                            {% endif %}
54
                                         {% endif %}
57
                                         {% endif %}
55
                                     </section>
58
                                     </section>
56
                                     {# show all column's sub-slides #}
59
                                     {# show all column's sub-slides #}

Loading…
Cancel
Save