fmmkii commited on
Commit
95a72ab
Β·
1 Parent(s): b716208

Updating app.py

Browse files
Files changed (7) hide show
  1. .gitignore +2 -1
  2. DOCS.md +0 -1
  3. __pycache__/generate_script.cpython-313.pyc +0 -0
  4. app.py +23 -18
  5. imggen.py +1 -1
  6. scriptgen.py +2 -2
  7. tweaker.py +29 -5
.gitignore CHANGED
@@ -1,3 +1,4 @@
1
  /.streamlit
2
  script_history.json
3
- /__pycache__
 
 
1
  /.streamlit
2
  script_history.json
3
+ /__pycache__\
4
+ .env
DOCS.md CHANGED
@@ -12,7 +12,6 @@ Instead of DuckDuckGo due to unpredictable API limits, we will be using Serpo AP
12
 
13
  Storing scripts using **json** provides an organized access to scripts and files which can be stored an prepared later for future use.
14
 
15
- To store secrets, we will use Streamlit instead as being modular and quick to set-up rather than dotenv.
16
  ### 3. Every Python File Explained
17
 
18
  This project utilizes multiple python files. The **app.py** is where the main application resides. Following that includes the **scriptgen.py (Script Generation)**, **imggen.py (Image Generation)**, **tweaker.py (Creative Consultant)**, and the **secretary.py (Script Secretary)**.
 
12
 
13
  Storing scripts using **json** provides an organized access to scripts and files which can be stored an prepared later for future use.
14
 
 
15
  ### 3. Every Python File Explained
16
 
17
  This project utilizes multiple python files. The **app.py** is where the main application resides. Following that includes the **scriptgen.py (Script Generation)**, **imggen.py (Image Generation)**, **tweaker.py (Creative Consultant)**, and the **secretary.py (Script Secretary)**.
__pycache__/generate_script.cpython-313.pyc ADDED
Binary file (1.96 kB). View file
 
app.py CHANGED
@@ -1,38 +1,43 @@
1
  import streamlit as st
 
 
 
 
 
2
 
3
  st.set_page_config(layout='wide', page_icon='✨')
4
 
5
  scriptgen = st.Page("scriptgen.py", title="Script Generator", icon='πŸ“ƒ')
6
  imggen = st.Page("imggen.py", title="Thumbnail Generator", icon='πŸ–ΌοΈ')
7
  tweaker = st.Page("tweaker.py", title="Creative Consultant", icon='🎬')
8
- jsonbase = st.Page("secretary.py", title = "Script Secretary", icon='πŸ“š')
9
- manual = st.Page("manual.py", title="Manual", icon="πŸ‘“", default= True)
10
- docs = st.Page("docs.py", title="Documentation", icon= 'πŸ“‘')
11
 
12
- api_key = st.secrets['OPENAI_API_KEY']
 
13
 
14
  # Sidebar for API Key input and options
15
  with st.sidebar:
16
- # Retrieve API Key from Streamlit secrets or prompt for input
17
- if 'OPENAI_API_KEY' in st.secrets:
18
- api_key = st.secrets['OPENAI_API_KEY'] # Retrieve the API key from secrets
19
- if not api_key.startswith('sk-proj'): # Validate the API key format
20
- api_key = st.text_input('Enter your OpenAI API token:', type='password')
 
 
21
  else:
22
- st.success('API Key Recognized!')
23
- else:
24
- api_key = st.text_input('Enter your OpenAI API token:', type='password')
25
 
26
- # Optional: Display feedback based on the provided or entered API key
27
- if api_key:
28
- if api_key.startswith('sk-proj'):
29
- st.sidebar.success('API Key is Valid!')
30
  else:
31
- st.sidebar.warning('The provided API Key format is incorrect.')
32
 
33
  pg = st.navigation(
34
  {
35
- "Others":[manual, docs],
36
  "Tools": [scriptgen, imggen, tweaker, jsonbase]
37
  }
38
  )
 
1
  import streamlit as st
2
+ from dotenv import load_dotenv, set_key
3
+ import os
4
+
5
+ # Load environment variables from .env file
6
+ load_dotenv()
7
 
8
  st.set_page_config(layout='wide', page_icon='✨')
9
 
10
  scriptgen = st.Page("scriptgen.py", title="Script Generator", icon='πŸ“ƒ')
11
  imggen = st.Page("imggen.py", title="Thumbnail Generator", icon='πŸ–ΌοΈ')
12
  tweaker = st.Page("tweaker.py", title="Creative Consultant", icon='🎬')
13
+ jsonbase = st.Page("secretary.py", title="Script Secretary", icon='πŸ“š')
14
+ manual = st.Page("manual.py", title="Manual", icon="πŸ‘“", default=True)
15
+ docs = st.Page("docs.py", title="Documentation", icon='πŸ“‘')
16
 
17
+ # Check if OPENAI_API_KEY exists in the environment
18
+ api_key = os.getenv('OPENAI_API_KEY', None) # Fallback to None if not found
19
 
20
  # Sidebar for API Key input and options
21
  with st.sidebar:
22
+ api_key_input = st.text_input('Enter your OpenAI API token:', type='password')
23
+
24
+ if st.button("Save API Key"):
25
+ if api_key_input.startswith("sk-"): # Basic validation
26
+ env_file = ".env"
27
+ set_key(env_file, "OPENAI_API_KEY", api_key_input) # Save to .env
28
+ st.success("API Key saved successfully!")
29
  else:
30
+ st.error("Invalid API Key format!")
 
 
31
 
32
+ # Check and display the status of the API key
33
+ if api_key:
34
+ st.success("API Key loaded from environment!")
 
35
  else:
36
+ st.warning("No API Key found. Please enter one.")
37
 
38
  pg = st.navigation(
39
  {
40
+ "Others": [manual, docs],
41
  "Tools": [scriptgen, imggen, tweaker, jsonbase]
42
  }
43
  )
imggen.py CHANGED
@@ -28,7 +28,7 @@ def load_script_history():
28
  script_history = load_script_history()
29
 
30
  # Retrieve the API key
31
- api_key = st.secrets.get('OPENAI_API_KEY') or os.getenv("OPENAI_API_KEY")
32
 
33
  if not api_key:
34
  st.error("API Key not provided! Please add it to Streamlit secrets or the .env file.")
 
28
  script_history = load_script_history()
29
 
30
  # Retrieve the API key
31
+ api_key = os.getenv("OPENAI_API_KEY")
32
 
33
  if not api_key:
34
  st.error("API Key not provided! Please add it to Streamlit secrets or the .env file.")
scriptgen.py CHANGED
@@ -14,8 +14,8 @@ st.title("Script Generator πŸ“ƒ")
14
  st.subheader("Create your script with just a single prompt!")
15
 
16
  # Retrieve API key from secrets or environment variables
17
- api_key = st.secrets.get("OPENAI_API_KEY") or os.getenv("OPENAI_API_KEY")
18
- serper_api_key = st.secrets.get("SERPER_API_KEY") or os.getenv("SERPER_API_KEY")
19
 
20
  if not api_key:
21
  st.error("Please provide a valid API Key in Streamlit secrets or .env file.")
 
14
  st.subheader("Create your script with just a single prompt!")
15
 
16
  # Retrieve API key from secrets or environment variables
17
+ api_key = os.getenv("OPENAI_API_KEY")
18
+ serper_api_key = os.getenv("SERPER_API_KEY")
19
 
20
  if not api_key:
21
  st.error("Please provide a valid API Key in Streamlit secrets or .env file.")
tweaker.py CHANGED
@@ -39,15 +39,39 @@ script_history = load_script_history()
39
  # Sidebar for script selection
40
  if script_history:
41
  st.sidebar.header("Previously Generated Scripts")
 
 
42
  script_titles = [f"Script {idx + 1}: {item['title']}" for idx, item in enumerate(script_history)]
43
- selected_script_idx = st.sidebar.selectbox("Choose a script to tweak:", range(len(script_titles)), format_func=lambda x: script_titles[x])
44
- selected_script = script_history[selected_script_idx]
45
-
46
- # Display the selected script
47
- st.sidebar.text_area("Script Content", value=selected_script["script"], height=200, disabled=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  else:
49
  st.sidebar.info("No scripts available. Please generate scripts using the Script Generator.")
50
 
 
51
  st.sidebar.button('Clear Chat History', on_click=clear_chat_history)
52
 
53
  # Prompt template for the Creative Consultant
 
39
  # Sidebar for script selection
40
  if script_history:
41
  st.sidebar.header("Previously Generated Scripts")
42
+
43
+ # Add "Other" option to the list of scripts
44
  script_titles = [f"Script {idx + 1}: {item['title']}" for idx, item in enumerate(script_history)]
45
+ script_titles.append("Other") # Add "Other" as an option
46
+
47
+ # Let the user select a script or "Other"
48
+ selected_script_idx = st.sidebar.selectbox(
49
+ "Choose a script to tweak:",
50
+ range(len(script_titles)),
51
+ format_func=lambda x: script_titles[x]
52
+ )
53
+
54
+ # If "Other" is chosen
55
+ if selected_script_idx == len(script_titles) - 1:
56
+ st.sidebar.text_area(
57
+ "Free Conversation or Custom Tweaking",
58
+ placeholder="Write your thoughts or tweaks here...",
59
+ height=200,
60
+ key="free_conversation"
61
+ )
62
+ else:
63
+ # Display the selected script
64
+ selected_script = script_history[selected_script_idx]
65
+ st.sidebar.text_area(
66
+ "Script Content",
67
+ value=selected_script["script"],
68
+ height=200,
69
+ disabled=True
70
+ )
71
  else:
72
  st.sidebar.info("No scripts available. Please generate scripts using the Script Generator.")
73
 
74
+
75
  st.sidebar.button('Clear Chat History', on_click=clear_chat_history)
76
 
77
  # Prompt template for the Creative Consultant