Raj Jayendrakumar Muchhala commited on
Commit
f1745b4
·
1 Parent(s): 84287b2

Add streamlit app for content creator

Browse files
Files changed (3) hide show
  1. app.py +90 -0
  2. prompts.py +28 -0
  3. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from openai import OpenAI
3
+ from prompts import SYSTEM_MESSAGE, USER_MESSAGE
4
+ import json
5
+
6
+ # Set Streamlit layout to wide mode
7
+ st.set_page_config(layout="wide")
8
+
9
+ st.title("🎬 AI-Powered Content Planner")
10
+ st.markdown("Paste a transcript on the left and view the generated content plan on the right.")
11
+
12
+ # Sidebar for OpenAI API Key
13
+ OPENAI_API_KEY = st.sidebar.text_input("Enter OpenAI API Key", type="password")
14
+ MODEL = "gpt-4o-2024-08-06"
15
+
16
+ if not OPENAI_API_KEY:
17
+ st.warning("⚠️ Please enter your OpenAI API key.")
18
+ st.stop()
19
+
20
+ client = OpenAI(api_key=OPENAI_API_KEY)
21
+
22
+ # Layout: Left (Input) | Right (Output)
23
+ col1, col2 = st.columns([1, 1])
24
+
25
+ with col1:
26
+ st.subheader("📝 Paste Your Transcript")
27
+ transcript = st.text_area("Enter the transcript here:", height=400)
28
+
29
+ with col2:
30
+ st.subheader("📋 Generated Content Plan")
31
+ generated_plan_container = st.container()
32
+
33
+ generate_button = st.button("Generate Plan")
34
+
35
+ if generate_button:
36
+ if not transcript.strip():
37
+ st.error("❌ Please enter a transcript.")
38
+ else:
39
+ with st.spinner("⏳ Generating content plan... Please wait."):
40
+ try:
41
+ # Define prompts
42
+ system_prompt = SYSTEM_MESSAGE
43
+ user_prompt = USER_MESSAGE.format(source_content=transcript)
44
+
45
+ messages = [
46
+ {"role": "system", "content": system_prompt},
47
+ {"role": "user", "content": user_prompt},
48
+ ]
49
+
50
+ # Create placeholder for dynamic streaming
51
+ generated_plan_container.empty()
52
+
53
+ # Stream OpenAI API Response
54
+ response = client.chat.completions.create(
55
+ model=MODEL,
56
+ messages=messages,
57
+ temperature=0.45,
58
+ max_tokens=5000,
59
+ top_p=1,
60
+ frequency_penalty=0,
61
+ presence_penalty=0,
62
+ response_format={"type": "json_object"},
63
+ )
64
+
65
+ # Parse the response
66
+ generated_response = response.choices[0].message.content.strip()
67
+ content_plan = json.loads(generated_response)
68
+
69
+ # Extract key (assuming there is only one key in the JSON response)
70
+ plan_key = list(content_plan.keys())[0]
71
+ clip_plans = content_plan.get(plan_key, [])
72
+
73
+ # Display final output
74
+ if clip_plans:
75
+ with generated_plan_container.container():
76
+ for i, clip in enumerate(clip_plans):
77
+ st.markdown(f"### 🎬 Clip {i + 1}")
78
+ st.write(f"**Title:** {clip.get('Title', 'N/A')}")
79
+ st.write(f"**Focus Prompt:** {clip.get('Focus Prompt', 'N/A')}")
80
+ st.write(f"**Duration:** {clip.get('Duration Target', 'N/A')} seconds")
81
+ st.write(f"**Aspect Ratio:** {clip.get('Aspect Ratio', 'N/A')}")
82
+ st.markdown("---")
83
+ else:
84
+ st.error("⚠️ No clips were generated. Try again.")
85
+
86
+ except json.JSONDecodeError:
87
+ st.error("⚠️ Failed to parse OpenAI response. Try again.")
88
+ except Exception as e:
89
+ st.error(f"❌ Error: {str(e)}")
90
+
prompts.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ SYSTEM_MESSAGE = '''
2
+ You are a ClipCreator, a specialized expert that helps users create multiple video clips from a single source transcript to maximize engagement and audience retention helping marketers looking to repurpose long form interviews, webinars and event footage.
3
+
4
+ Your goal is to analyze the provided transcript and generate a **high-level plan** for multiple video clips by identifying distinct topics, key moments, and engaging segments.
5
+
6
+ ### **How You Should Process the Transcript**
7
+ 1. **Segment the Transcript**
8
+ - Identify key topics, subjects or themes **in their natural order** as they appear in the transcript.
9
+ - Determine logical boundaries for where each topic starts and ends.
10
+
11
+ 2. **Generate Clip Concepts**
12
+ For each identified clip, provide the following details:
13
+ - **Title:** A concise and descriptive title for the clip that encapsulate the main idea or highlight.
14
+ - **Focus Prompt:** A short description starting with "Focus on..." that explains the central theme or takeaway of the clip.
15
+ - **Duration Target:** Estimated duration (in seconds) based on the transcript length and complexity.
16
+ - **Aspect Ratio:** Recommended format (Landscape, Square, Vertical) based on content type.
17
+
18
+ Format the response as a JSON object with Title, Focus Prompt, Duration Target, and Aspect Ratio for each clip concept.
19
+ '''
20
+
21
+ USER_MESSAGE = '''
22
+ Here is the reference transcript for generating video clip ideas:
23
+ ```
24
+ {source_content}
25
+ ```
26
+ Please analyze this transcript and generate multiple clip ideas using the structured approach outlined in your system instructions.
27
+ Ensure that each clip has a meaningful title, focus prompt, estimated duration, and recommended aspect ratio.
28
+ '''
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ openai