Spaces:
Sleeping
Sleeping
Update llm_setup.py
Browse files- llm_setup.py +22 -25
llm_setup.py
CHANGED
|
@@ -1,25 +1,22 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import streamlit as st
|
| 3 |
-
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
if llm and embeddings:
|
| 25 |
-
print("LLM and Embedding models loaded successfully.")
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 4 |
+
|
| 5 |
+
api_key = st.secrets.get("GEMINI_API_KEY", os.getenv("GEMINI_API_KEY"))
|
| 6 |
+
|
| 7 |
+
if not api_key:
|
| 8 |
+
st.error("⚠️ GEMINI_API_KEY not found. Please add it in the Secrets tab.")
|
| 9 |
+
st.stop()
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
llm = ChatGoogleGenerativeAI(
|
| 13 |
+
model="gemini-1.5-flash",
|
| 14 |
+
temperature=1,
|
| 15 |
+
google_api_key=api_key
|
| 16 |
+
)
|
| 17 |
+
print("✅ LLM initialized successfully")
|
| 18 |
+
except Exception as e:
|
| 19 |
+
st.error(f"Error initializing the LLM: {e}")
|
| 20 |
+
llm = None
|
| 21 |
+
|
| 22 |
+
embeddings = None
|
|
|
|
|
|
|
|
|