Explorar el Código

`generate_indices` is conditional, add openai

`/img` is an image generator (handy)
master
The Dod hace 1 año
padre
commit
01b4517d6d
Se han modificado 4 ficheros con 60 adiciones y 34 borrados
  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 Ver fichero

@@ -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"),

+ 1
- 0
requirements.txt Ver fichero

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

+ 24
- 10
static/slides.json Ver fichero

@@ -41,11 +41,8 @@
41 41
                 {
42 42
                     "id": "sins_against_others",
43 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 46
                     "soundtrack": "static/audio/ho-oponopono.mp3"
50 47
                 }
51 48
             ]
@@ -54,15 +51,32 @@
54 51
             "id": "intospection",
55 52
             "title": "Introspection",
56 53
             "params": {
57
-                "theme": "league",
54
+                "theme": "beige",
58 55
                 "background-video": "static/bg-video/underwater.mp4",
59 56
                 "background-video-loop": true,
60
-                "background-video-mute": true,
61
-                "background-opacity": "0.25"
57
+                "background-video-mute": true
62 58
             },
63 59
             "markdown": "# \u262f\n",
64 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 Ver fichero

@@ -36,21 +36,24 @@
36 36
                                         {# column's top slide #}
37 37
                                         <h3 class="title slide_title">{{column.title}}</h3>
38 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 57
                                         {% endif %}
55 58
                                     </section>
56 59
                                     {# show all column's sub-slides #}

Loading…
Cancelar
Guardar