mariapar commited on
Commit
1806ec2
Β·
verified Β·
1 Parent(s): 6fb2409

Update app_core.py

Browse files
Files changed (1) hide show
  1. 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.5 # 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(f"""
42
- You are a presentation-outliner. (json!)
43
-
44
- β€’ Maximum slides: {MAX_SLIDES} (incl. title)
45
- β€’ First slide = "title".
46
- β€’ Prefer "list" slides whenever possible (≀ 5 bullets).
47
- β€’ Allowed types: "list" | "text" | "quote" | "code"
48
- β€’ Preserve ``` code ``` verbatim.
49
-
50
- Return **only**
51
- {{
52
- "slides":[
53
- {{ "{{" }} "slide_idx":N, "type":"…", "title":"…", "body":… {{ "}}" }},
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 narrator. (json!)
111
-
112
- For every slide write 2-3 warm sentences (25–60 words) that match its content.
113
- Return:
114
- { "narration":[ { "slide_idx":N, "voice_text":"..." }, … ] }
 
 
 
 
 
 
 
 
 
 
 
 
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: