import streamlit as st from dotenv import load_dotenv from utils import generate_script import time # Load environment variables (for local development) load_dotenv() # App title and header st.title("YouTube Scriptwriting Tool") st.header("Generate a video script by specifying a topic, length, and creativity level.") # Sidebar for API key configuration st.sidebar.title("API Configuration") api_key = st.sidebar.text_input("Enter your Google API key:", type="password") # Main input fields for video script prompt = st.text_input("Provide the topic of the video:") video_length = st.number_input("Specify video length (in minutes):", min_value=1.0, step=0.5) creativity = st.slider("Set creativity level:", min_value=0.0, max_value=1.0, value=0.5) # Button to generate the script generate_script_button = st.button("Generate Script") # Placeholder for generated script script_placeholder = st.empty() if generate_script_button: if not api_key: st.error("Please provide a valid Google API key.") else: # Show loading spinner while generating the script with st.spinner("Generating script... Please wait."): try: title, script, search_data = generate_script(prompt, video_length, creativity, api_key) time.sleep(1) # Simulate processing time for a better user experience # Display generated script st.success("Script generated successfully!") st.subheader(f"Title: {title}") st.write(f"Script:\n\n{script}") with st.expander("Search Data Used for the Script"): st.write(search_data) # Add a download button for the script script_filename = "generated_script.txt" script_content = f"Title: {title}\n\nScript:\n{script}\n\nSearch Data:\n{search_data}" st.download_button( label="Download Script", data=script_content, file_name=script_filename, mime="text/plain" ) except Exception as e: st.error(f"An error occurred: {e}")