Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,72 +12,68 @@ SYSTEM_PROMPT = """You are 'ScriptForge AI', a professional YouTube Script Write
|
|
| 12 |
Your goal is to write highly engaging scripts in the 2nd person (using 'You', 'Your').
|
| 13 |
|
| 14 |
FORMATTING RULES (STRICT):
|
| 15 |
-
1. ONLY
|
| 16 |
-
2.
|
| 17 |
-
3. [
|
| 18 |
-
4.
|
| 19 |
-
5.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
"""
|
| 21 |
|
| 22 |
def parse_script(full_text):
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
|
| 27 |
-
# Split
|
| 28 |
-
parts = re.split(
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
|
| 33 |
current_tag = None
|
| 34 |
|
| 35 |
for part in parts:
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
# 4. Remove brackets like [Upbeat Music] that might be inside a script tag
|
| 58 |
-
content = re.sub(r'\[.*?\]', '', content, flags=re.DOTALL)
|
| 59 |
-
# 5. Remove bolding/formatting
|
| 60 |
-
content = content.replace("**", "").replace("*", "").replace("__", "")
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
clean_script.append(final_content)
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
script_text = re.sub(r'\[.*?\]', '', full_text, flags=re.DOTALL).strip()
|
| 79 |
-
|
| 80 |
-
return script_text, scenes_text
|
| 81 |
|
| 82 |
def save_to_file(script_text):
|
| 83 |
if not script_text:
|
|
|
|
| 12 |
Your goal is to write highly engaging scripts in the 2nd person (using 'You', 'Your').
|
| 13 |
|
| 14 |
FORMATTING RULES (STRICT):
|
| 15 |
+
1. Use ONLY these two tags: [VISUAL] for scenes, and [AUDIO] for spoken words.
|
| 16 |
+
2. [VISUAL]: Describe the visuals, camera shots, or on-screen text.
|
| 17 |
+
3. [AUDIO]: Write ONLY the spoken words. No actor directions, no "Host:", no markdown headers.
|
| 18 |
+
4. Do not output any intro text. Start directly with a [VISUAL] or [AUDIO] tag.
|
| 19 |
+
5. Example:
|
| 20 |
+
[VISUAL]
|
| 21 |
+
Wide shot of a clear blue sky.
|
| 22 |
+
[AUDIO]
|
| 23 |
+
Today is going to be amazing.
|
| 24 |
"""
|
| 25 |
|
| 26 |
def parse_script(full_text):
|
| 27 |
+
# Normalize tags just in case
|
| 28 |
+
full_text = re.sub(r'\[?(?:SCENE DESCRIPTION|SCENE|VISUALS)\]?:?', '[VISUAL]', full_text, flags=re.IGNORECASE)
|
| 29 |
+
full_text = re.sub(r'\[?(?:SCRIPT|NARRATION|AUDIO)\]?:?', '[AUDIO]', full_text, flags=re.IGNORECASE)
|
| 30 |
|
| 31 |
+
# Split by tags
|
| 32 |
+
parts = re.split(r'(\[(?:VISUAL|AUDIO)\])', full_text, flags=re.IGNORECASE)
|
| 33 |
|
| 34 |
+
clean_audio = []
|
| 35 |
+
clean_visuals = []
|
| 36 |
|
| 37 |
current_tag = None
|
| 38 |
|
| 39 |
for part in parts:
|
| 40 |
+
part = part.strip()
|
| 41 |
+
if not part:
|
| 42 |
+
continue
|
| 43 |
+
|
| 44 |
+
if part.upper() == "[AUDIO]":
|
| 45 |
+
current_tag = "AUDIO"
|
| 46 |
+
elif part.upper() == "[VISUAL]":
|
| 47 |
+
current_tag = "VISUAL"
|
| 48 |
+
elif current_tag == "AUDIO":
|
| 49 |
+
# Clean Audio
|
| 50 |
+
# Remove parenthetical notes like (whispering)
|
| 51 |
+
content = re.sub(r'\(.*?\)', '', part, flags=re.DOTALL)
|
| 52 |
+
# Remove headers
|
| 53 |
+
content = re.sub(r'^#+.*$', '', content, flags=re.MULTILINE)
|
| 54 |
+
# Remove labels like "Host:"
|
| 55 |
+
content = re.sub(r'^\w+:\s*', '', content, flags=re.MULTILINE)
|
| 56 |
+
# Remove formatting
|
| 57 |
+
content = content.replace("**", "").replace("*", "")
|
| 58 |
+
|
| 59 |
+
if content.strip():
|
| 60 |
+
clean_audio.append(content.strip())
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
elif current_tag == "VISUAL":
|
| 63 |
+
clean_visuals.append(part.strip())
|
|
|
|
| 64 |
|
| 65 |
+
# Fallback: If no tags found, attempt heuristic split
|
| 66 |
+
if not clean_audio and not clean_visuals:
|
| 67 |
+
lines = full_text.split('\n')
|
| 68 |
+
for line in lines:
|
| 69 |
+
line = line.strip()
|
| 70 |
+
if not line: continue
|
| 71 |
+
if line.startswith('(') or line.startswith('[') or "EXT." in line or "INT." in line:
|
| 72 |
+
clean_visuals.append(line)
|
| 73 |
+
else:
|
| 74 |
+
clean_audio.append(line)
|
| 75 |
+
|
| 76 |
+
return "\n\n".join(clean_audio), "\n\n".join(clean_visuals)
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
def save_to_file(script_text):
|
| 79 |
if not script_text:
|