Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
|
| 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.
|
| 18 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|