Ansnaeem commited on
Commit
c4d4bda
·
verified ·
1 Parent(s): 3324231

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -19
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, audience-first scripts in the 2nd person (using 'You', 'Your').
13
- Talk directly to the viewer as if you are the creator speaking to the camera.
14
-
15
- FORMATTING RULES:
16
- 1. Every script must alternate between [SCENE DESCRIPTION] and [SCRIPT].
17
- 2. [SCENE DESCRIPTION] should describe the visuals, camera angles, or B-roll.
18
- 3. [SCRIPT] should be the actual spoken words.
19
- 4. Structure the script with a Hook, Intro, Main Points, and a Call to Action (CTA).
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
- # Improved regex: Handles optional colons, bolding (**), and case variations
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
- # Extract [SCENE DESCRIPTION] parts
 
 
 
 
 
 
 
 
 
 
 
 
 
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: If parsing fails but we have text, assume the whole thing is the script
38
  if not clean_script and full_text:
39
- clean_script = full_text
 
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