File size: 1,876 Bytes
408f187
 
 
c1db0a1
408f187
3e16a00
408f187
 
 
 
 
 
f85e788
408f187
f85e788
408f187
c1db0a1
 
 
 
 
 
 
aed5cf2
408f187
 
 
 
aed5cf2
 
 
 
 
c1db0a1
f85e788
1b5de56
f85e788
1b5de56
 
 
 
 
c1db0a1
 
 
1b5de56
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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}")