saikumar27 commited on
Commit
f4dbfb2
Β·
verified Β·
1 Parent(s): 09a77a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -6,16 +6,21 @@ from langchain.prompts import PromptTemplate
6
  import os
7
  from dotenv import load_dotenv
8
 
9
- # βœ… Load API Key from Environment Variables
10
- if not load_dotenv():
11
- st.error("🚨 .env file not found! Please ensure it exists and contains your GOOGLE_API_KEY.")
12
- st.stop()
13
-
14
  api_key = os.getenv("GOOGLE_API_KEY")
15
 
 
16
  if not api_key:
17
- st.error("🚨 API key missing! Add your GOOGLE_API_KEY to the environment variables.")
18
- st.stop()
 
 
 
 
 
 
 
19
 
20
  # βœ… Configure Gemini Model
21
  model = ChatGoogleGenerativeAI(model="gemini-1.5-pro", api_key=api_key)
 
6
  import os
7
  from dotenv import load_dotenv
8
 
9
+ # βœ… Load API Key from Environment Variables or User Input
10
+ load_dotenv() # Try to load .env file
 
 
 
11
  api_key = os.getenv("GOOGLE_API_KEY")
12
 
13
+ # If .env file is missing or API key is not found, ask the user to input it
14
  if not api_key:
15
+ st.warning("πŸ”‘ Google API key not found in .env file. Please enter your API key below.")
16
+ api_key = st.text_input("Enter your Google API Key:", type="password")
17
+
18
+ if not api_key:
19
+ st.error("🚨 API key is required to proceed.")
20
+ st.stop()
21
+ else:
22
+ # Save the API key to the environment for the session
23
+ os.environ["GOOGLE_API_KEY"] = api_key
24
 
25
  # βœ… Configure Gemini Model
26
  model = ChatGoogleGenerativeAI(model="gemini-1.5-pro", api_key=api_key)