Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,34 +9,41 @@ GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions"
|
|
| 9 |
MODEL_NAME = "llama-3.1-8b-instant"
|
| 10 |
|
| 11 |
SYSTEM_PROMPT = """You are 'ScriptForge AI', a professional YouTube Script Writer.
|
| 12 |
-
Your goal is to write highly engaging
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
5. Maintain the requested Tone and Duration.
|
| 21 |
-
|
| 22 |
-
Example:
|
| 23 |
-
[SCENE DESCRIPTION]: Close-up of the product.
|
| 24 |
-
[SCRIPT]: You need to see this to believe it.
|
| 25 |
"""
|
| 26 |
|
| 27 |
def parse_script(full_text):
|
| 28 |
-
#
|
| 29 |
-
# Extract [SCRIPT] parts
|
| 30 |
script_parts = re.findall(r'\[?SCRIPT\]?:?\s*(.*?)(?=\[?SCENE DESCRIPTION\]?|$)', full_text, re.DOTALL | re.IGNORECASE)
|
| 31 |
-
clean_script = "\n".join([p.strip().replace("**", "") for p in script_parts if p.strip()])
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
scene_parts = re.findall(r'\[?SCENE DESCRIPTION\]?:?\s*(.*?)(?=\[?SCRIPT\]?|$)', full_text, re.DOTALL | re.IGNORECASE)
|
| 35 |
clean_scenes = "\n".join([p.strip().replace("**", "") for p in scene_parts if p.strip()])
|
| 36 |
|
| 37 |
-
# Fallback
|
| 38 |
if not clean_script and full_text:
|
| 39 |
-
|
|
|
|
| 40 |
|
| 41 |
return clean_script, clean_scenes
|
| 42 |
|
|
|
|
| 9 |
MODEL_NAME = "llama-3.1-8b-instant"
|
| 10 |
|
| 11 |
SYSTEM_PROMPT = """You are 'ScriptForge AI', a professional YouTube Script Writer.
|
| 12 |
+
Your goal is to write highly engaging scripts in the 2nd person (using 'You', 'Your').
|
| 13 |
+
|
| 14 |
+
FORMATTING RULES (STRICT):
|
| 15 |
+
1. ONLY output content within [SCENE DESCRIPTION] and [SCRIPT] tags.
|
| 16 |
+
2. NO introduction text, NO "Here is your script", and NO titles outside the tags.
|
| 17 |
+
3. [SCENE DESCRIPTION] is for visuals.
|
| 18 |
+
4. [SCRIPT] is ONLY for the spoken dialogue. Do NOT include headings like "Hook:", "Intro:", or "CTA:" inside the [SCRIPT] tag.
|
| 19 |
+
5. Talk directly to the audience.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
"""
|
| 21 |
|
| 22 |
def parse_script(full_text):
|
| 23 |
+
# 1. Extract [SCRIPT] segments
|
|
|
|
| 24 |
script_parts = re.findall(r'\[?SCRIPT\]?:?\s*(.*?)(?=\[?SCENE DESCRIPTION\]?|$)', full_text, re.DOTALL | re.IGNORECASE)
|
|
|
|
| 25 |
|
| 26 |
+
cleaned_dialogue = []
|
| 27 |
+
for part in script_parts:
|
| 28 |
+
# Remove markdown headers (e.g., ### Hook)
|
| 29 |
+
clean = re.sub(r'^#+.*$', '', part, flags=re.MULTILINE)
|
| 30 |
+
# Remove bolding/italics
|
| 31 |
+
clean = clean.replace("**", "").replace("*", "").replace("__", "")
|
| 32 |
+
# Remove common metadata words/colons at start of lines (e.g., "Hook:", "Intro:")
|
| 33 |
+
clean = re.sub(r'^(Hook|Intro|Body|CTA|Conclusion|Outro):\s*', '', clean, flags=re.IGNORECASE | re.MULTILINE).strip()
|
| 34 |
+
if clean:
|
| 35 |
+
cleaned_dialogue.append(clean)
|
| 36 |
+
|
| 37 |
+
clean_script = "\n\n".join(cleaned_dialogue)
|
| 38 |
+
|
| 39 |
+
# 2. Extract [SCENE DESCRIPTION] segments
|
| 40 |
scene_parts = re.findall(r'\[?SCENE DESCRIPTION\]?:?\s*(.*?)(?=\[?SCRIPT\]?|$)', full_text, re.DOTALL | re.IGNORECASE)
|
| 41 |
clean_scenes = "\n".join([p.strip().replace("**", "") for p in scene_parts if p.strip()])
|
| 42 |
|
| 43 |
+
# Fallback
|
| 44 |
if not clean_script and full_text:
|
| 45 |
+
# If no tags, try to strip common AI intro fluff
|
| 46 |
+
clean_script = re.sub(r'^(Here is|Sure|Okay|I can help|Youtube Script).*?$', '', full_text, flags=re.IGNORECASE | re.MULTILINE).strip()
|
| 47 |
|
| 48 |
return clean_script, clean_scenes
|
| 49 |
|