abhinav0231 commited on
Commit
f9fe76c
·
verified ·
1 Parent(s): ab56328

Update llm_setup.py

Browse files
Files changed (1) hide show
  1. 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
- from langchain_huggingface import HuggingFaceEmbeddings
5
-
6
-
7
- api_key = st.secrets.get("GEMINI_API_KEY") or os.getenv("GEMINI_API_KEY")
8
-
9
- if not api_key:
10
- raise ValueError("GEMINI_API_KEY environment variable not set. Please set it in your .env file.")
11
-
12
- try:
13
- llm = ChatGoogleGenerativeAI(model="gemma-3-12b-it", temperature=1, google_api_key=api_key)
14
- except Exception as e:
15
- print(f"Error initializing the LLM: {e}")
16
- llm = None
17
-
18
- try:
19
- embeddings = HuggingFaceEmbeddings(model_name="all-MiniLM-L6-v2")
20
- except Exception as e:
21
- print(f"Error initializing the embedding model: {e}")
22
- embeddings = None
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