import streamlit as st import openai import os # Set up OpenAI API key openai.api_key = os.getenv("OPENAI_API_KEY") def generate_video_script(title, formality_level, emotional_tone, engagement_level): # Construct the original detailed prompt as provided prompt = ( f"[Use this video framework below]\n" f"First we need to have a strong hook.\n" f"A short intro that stops people from scrolling and holds their attention\n" f"Example. \"{title}\"\n" f"Now we add in “The Setup\"\n" f"* This is used to Setup the scene and provide context to the Viewer\n" f"* ex. \"I've been creating videos recently and I guess something finally clicked\"\n" f"* This lets the viewer know that she’s been uploading more videos recently, and that could have led to an increase in views and followers.\n" f"ACT 2: \"The Conflict\"\n" f"* Introduce a point of conflict or problem that requires a solution\n" f"* ex. \"Some of you have been asking about scripting and storytelling and there's a lot to talk about, but I gotchu\"\n" f"* Setting up the foundation to lead to the topic of the video and posing the concern that 'there's a lot to talk about'\n" f"* Which opens the question of how we're going to tackle the topic in a limited amount of time\n" f"ACT 3: \"The Resolution\"\n" f"* Addressing the conflict we introduced and resolving it\n" f"* ex. \"Here's how I tell my stories. All you need are these 3: ACT I, ACT II, and ACT III.\"\n" f"* She proceeds to explain how we structure and tell our stories, which answers and resolves the initial conflict\n" f"A call to action or loop.\n" f"Call-To-Action\n" f"* After giving valuable information to your viewer, you have to be able to lead them somewhere or encourage them to engage\n" f"* ex. \"And if you wanna know how that looks like, then watch this video back and follow for more.\"\n" f"* This encourages the audience to rewatch the video to see the video is an actual example of what they just learned and it encourages them to follow and share the content if they found it valuable!\n" f"Follow viral video recipe above in creating a Viral Video script for me. Do not repeat the instructions above, just use the framework for the viral video script. Every output must include: HOOK, THE SETUP, THE CONFLICT, THE RESOLUTION, THE CTA. \n" f"Topic: {title}\n" f"Tone: {emotional_tone}\n" f"Formality Level: {formality_level}\n" f"Engagement Level: {engagement_level}" ) try: response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[ {"role": "system", "content": "Generate a script based on the following instructions."}, {"role": "user", "content": prompt} ], temperature=0.7, max_tokens=1024, ) # Accessing the generated script from the response script = response['choices'][0]['message']['content'].strip() return script except Exception as e: st.error(f"Failed to generate script: {str(e)}") return "Error in generating script." # Streamlit UI setup st.set_page_config(layout="wide") st.markdown("