Spaces:
Running
Running
Update app_core.py
Browse files- app_core.py +51 -22
app_core.py
CHANGED
|
@@ -31,29 +31,46 @@ MODEL_CHAT = "gpt-4o-mini" # outline + narration
|
|
| 31 |
MODEL_TTS = "tts-1" # OpenAI TTS voice
|
| 32 |
VOICE_ID = "alloy"
|
| 33 |
MAX_SLIDES = 10
|
| 34 |
-
AUDIO_SPEED = 1.
|
| 35 |
|
| 36 |
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 37 |
|
| 38 |
# ------------------------------------------------------------------
|
| 39 |
# 1. OUTLINE PROMPT
|
| 40 |
# ------------------------------------------------------------------
|
| 41 |
-
PROMPT_JSON = textwrap.dedent(
|
| 42 |
-
You are a presentation-outliner.
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
β’
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
""").strip()
|
| 58 |
|
| 59 |
def text_to_outline(raw_text: str) -> list:
|
|
@@ -107,11 +124,23 @@ def slide_to_html(slide: dict) -> str:
|
|
| 107 |
# 3. NARRATION PROMPT
|
| 108 |
# ------------------------------------------------------------------
|
| 109 |
PROMPT_NARR = textwrap.dedent("""
|
| 110 |
-
You are a friendly
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
""").strip()
|
| 116 |
|
| 117 |
def narration(raw_text:str, slides:list) -> list:
|
|
|
|
| 31 |
MODEL_TTS = "tts-1" # OpenAI TTS voice
|
| 32 |
VOICE_ID = "alloy"
|
| 33 |
MAX_SLIDES = 10
|
| 34 |
+
AUDIO_SPEED = 1.0 # 1.0 = normal, 1.5 β 50 % faster
|
| 35 |
|
| 36 |
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 37 |
|
| 38 |
# ------------------------------------------------------------------
|
| 39 |
# 1. OUTLINE PROMPT
|
| 40 |
# ------------------------------------------------------------------
|
| 41 |
+
PROMPT_JSON = textwrap.dedent("""
|
| 42 |
+
You are a presentation-outliner.
|
| 43 |
+
The user needs VALID json only β no extra commentary. (json!)
|
| 44 |
+
|
| 45 |
+
β¦ Rules
|
| 46 |
+
0. Total slides β€ 10 (including the title slide).
|
| 47 |
+
β’ If the source text is longer, merge or summarise content to stay within 10 slides.
|
| 48 |
+
|
| 49 |
+
1. First slide MUST be type "title":
|
| 50 |
+
{ "slide_idx":1, "type":"title", "title":"β¦", "body":"" }
|
| 51 |
+
(body may stay empty)
|
| 52 |
+
|
| 53 |
+
2. Prefer **"list"** whenever possible.
|
| 54 |
+
+ β’ Break sentences into concise bullet-points.
|
| 55 |
+
+ β’ Use "text" only when the content truly cannot be listed.
|
| 56 |
+
+ Allowed types:
|
| 57 |
+
+ "list" β array, β€ 5 items β _default choice_
|
| 58 |
+
+ "text" β short paragraph
|
| 59 |
+
+ "quote" β short quotation or bold statement
|
| 60 |
+
+ "code" β code block, copy verbatim from ``` fences
|
| 61 |
+
|
| 62 |
+
3. Preserve every ``` β¦ ``` code block unchanged.
|
| 63 |
+
|
| 64 |
+
4. Return this exact schema:
|
| 65 |
+
{
|
| 66 |
+
"slides":[
|
| 67 |
+
{ "slide_idx":N, "type":"β¦", "title":"β¦", "body":β¦ },
|
| 68 |
+
β¦ // β€ 9 more objects after the title slide
|
| 69 |
+
]
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
Output the json only.
|
| 73 |
+
|
| 74 |
""").strip()
|
| 75 |
|
| 76 |
def text_to_outline(raw_text: str) -> list:
|
|
|
|
| 124 |
# 3. NARRATION PROMPT
|
| 125 |
# ------------------------------------------------------------------
|
| 126 |
PROMPT_NARR = textwrap.dedent("""
|
| 127 |
+
You are a friendly, motivational voice-over writer.
|
| 128 |
+
The user needs VALID json only β no extra commentary. (json!)
|
| 129 |
+
|
| 130 |
+
Source:
|
| 131 |
+
β’ "raw_text" β full original article
|
| 132 |
+
β’ "slides" β list of slide dictionaries (title, type, body)
|
| 133 |
+
|
| 134 |
+
Task for EACH slide in order:
|
| 135 |
+
β’ Write **at least two sentences** (β 25β60 words total).
|
| 136 |
+
β’ Use the slideβs visible content **and** extra context from raw_text.
|
| 137 |
+
β’ Keep a welcoming tone: encourage, explain, or add a useful tip.
|
| 138 |
+
β’ Mention code or quote briefly (βIn this code snippet youβll see β¦β).
|
| 139 |
+
β’ First slide β start with a warm greeting + slide title.
|
| 140 |
+
β’ Last slide β quick recap + short friendly goodbye.
|
| 141 |
+
|
| 142 |
+
Output exactly:
|
| 143 |
+
{ "narration":[ { "slide_idx":N, "voice_text":"..." }, β¦ ] }
|
| 144 |
""").strip()
|
| 145 |
|
| 146 |
def narration(raw_text:str, slides:list) -> list:
|