Becio commited on
Commit
38935a5
·
verified ·
1 Parent(s): 6be1f8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -4
app.py CHANGED
@@ -52,7 +52,7 @@ Below is an example YouTube video text that demonstrates the style, tone, pacing
52
  {style_text}
53
  --- STYLE INSPIRATION END ---
54
 
55
- Using this style as inspiration, write a full, complete, well-developed Youtube video text that contains between 2700 and 2800 words.
56
  You must expand on every key point, include vivid examples, and avoid summarizing too early. Try to cut the text (besides intro and outro) into 5-8 chapters.
57
  Tell realistic information each chapter.
58
 
@@ -71,22 +71,77 @@ Use the following current information for context:
71
 
72
  Maintain the same storytelling quality, sentence rhythm, and tone as the style sample.
73
  Make the tone of the YouTube video dramatic and mysterious, using rhetorical questions.
74
- Ensure the final script is between 2700 and 2800 words.
75
  """
76
 
77
  response = client.chat.completions.create(
78
- model="gpt-4.1",
79
  messages=[
80
  {"role": "system", "content": "You're a professional scriptwriter."},
81
  {"role": "user", "content": prompt}
82
  ]
83
  )
84
 
85
- return response.choices[0].message.content
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  except Exception as e:
88
  return f"❌ Er ging iets fout: {str(e)}"
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  # 🎛️ Gradio interface
91
  with gr.Blocks() as demo:
92
  gr.Markdown("# 🎨 Script Writer 2.0 – Met woordtelling en Fact-Check")
 
52
  {style_text}
53
  --- STYLE INSPIRATION END ---
54
 
55
+ Using this style as inspiration, write a full, complete, well-developed Youtube video text that contains between 2700 and 2800 words. Keep searching of you don't get 2700 words. Under 2700 words is NOT acceptable.
56
  You must expand on every key point, include vivid examples, and avoid summarizing too early. Try to cut the text (besides intro and outro) into 5-8 chapters.
57
  Tell realistic information each chapter.
58
 
 
71
 
72
  Maintain the same storytelling quality, sentence rhythm, and tone as the style sample.
73
  Make the tone of the YouTube video dramatic and mysterious, using rhetorical questions.
74
+ Ensure the final script is between 2700 and 2800 words. Under 2700 is NOT acceptable.
75
  """
76
 
77
  response = client.chat.completions.create(
78
+ model="gpt-4.1", # ✅ GPT-4.1 zoals je wilde
79
  messages=[
80
  {"role": "system", "content": "You're a professional scriptwriter."},
81
  {"role": "user", "content": prompt}
82
  ]
83
  )
84
 
85
+ raw_script = response.choices[0].message.content
86
+
87
+ # Stap 5: Controleer woordenaantal
88
+ word_count = len(raw_script.split())
89
+ if word_count < 2700:
90
+ extra_prompt = f"""
91
+ The following script is only {word_count} words long. Please continue writing naturally until it reaches at least 2700 words.
92
+ Maintain the same tone, structure, and factual accuracy.
93
+ Do NOT add editing notes, camera directions, or video comments.
94
+
95
+ Script so far:
96
+ {raw_script}
97
+ """
98
+ extra_response = client.chat.completions.create(
99
+ model="gpt-4.1",
100
+ messages=[
101
+ {"role": "system", "content": "You're a professional scriptwriter."},
102
+ {"role": "user", "content": extra_prompt}
103
+ ]
104
+ )
105
+ raw_script += "\n" + extra_response.choices[0].message.content
106
+
107
+ # Stap 6: Fact-check het script (versoepeld)
108
+ final_script = factual_review(raw_script, context, client)
109
+ return final_script
110
 
111
  except Exception as e:
112
  return f"❌ Er ging iets fout: {str(e)}"
113
 
114
+
115
+ # 🔎 Fact-check met soepele aanpak
116
+ def factual_review(script, context, client):
117
+ prompt = f"""
118
+ Below is a script and the factual context it was based on.
119
+
120
+ --- CONTEXT ---
121
+ {context}
122
+
123
+ --- SCRIPT ---
124
+ {script}
125
+
126
+ Please review the script for factual consistency:
127
+
128
+ - Minor elaborations are allowed if logically connected to the context.
129
+ - Remove clearly speculative or unverifiable claims.
130
+ - Keep dramatic tone and rhetorical questions if they don't create fake facts.
131
+ - Ensure the final script is at least 2700 and maximum 2800 words and keeps natural storytelling flow.
132
+ - Important: Do not add video editing instructions, title cards, camera directions, or editorial comments. Only return the final spoken script text.
133
+
134
+ Only rewrite or reword parts that really need it.
135
+ """
136
+ response = client.chat.completions.create(
137
+ model="gpt-4.1",
138
+ messages=[
139
+ {"role": "system", "content": "You are a careful but strict fact-checker and editor."},
140
+ {"role": "user", "content": prompt}
141
+ ]
142
+ )
143
+ return response.choices[0].message.content
144
+
145
  # 🎛️ Gradio interface
146
  with gr.Blocks() as demo:
147
  gr.Markdown("# 🎨 Script Writer 2.0 – Met woordtelling en Fact-Check")