Joanna30's picture
Update app.py
c1db0a1 verified
raw
history blame
1.88 kB
import streamlit as st
from dotenv import load_dotenv
from utils import generate_script
import os
# 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 to capture Google API key
st.sidebar.title("API Configuration")
api_key = st.sidebar.text_input("Enter your Google API key:", type="password")
# If the API key is not entered, use the one from the environment (i.e., .env file)
if not api_key:
api_key = os.getenv('GOOGLE_API_KEY')
if not api_key:
st.error("Please provide a valid Google API key.")
st.stop()
# Main input fields for the 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")
# When the button is clicked, the script will be generated
if generate_script_button:
with st.spinner("Generating your script... Please wait!"):
# Generate the script using the utility function, passing the API key
try:
title, script, search_data = generate_script(prompt, video_length, creativity, api_key)
st.success("Script generated successfully!")
st.subheader(f"Title: {title}")
st.write(f"Script:\n\n{script}")
with st.expander("Show search data used for the script"):
st.write(search_data)
# Allow the user to download the script
st.download_button("Download Script", f"{title}.txt")
except Exception as e:
st.error(f"An error occurred: {e}")