Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +10 -21
src/streamlit_app.py
CHANGED
|
@@ -30,27 +30,16 @@ with st.container():
|
|
| 30 |
st.markdown("Ask financial questions about ITC Ltd. based on transcript data, powered by AI.")
|
| 31 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 32 |
|
| 33 |
-
# Sidebar
|
| 34 |
-
with st.sidebar:
|
| 35 |
-
st.header("⚙️ Settings")
|
| 36 |
-
|
| 37 |
-
# Load API key securely from Hugging Face secrets
|
| 38 |
-
GOOGLE_API_KEY = st.secrets.get("GOOGLE_API_KEY", None)
|
| 39 |
-
|
| 40 |
-
if GOOGLE_API_KEY:
|
| 41 |
-
st.success("✅ Google API Key loaded successfully!")
|
| 42 |
-
else:
|
| 43 |
-
st.error("❌ Google API Key not found in Hugging Face Secrets. Please set 'GOOGLE_API_KEY'.")
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
|
| 50 |
# Initialize Chroma DB
|
| 51 |
@st.cache_resource
|
| 52 |
-
def initialize_vectorstore(
|
| 53 |
-
embedding = GoogleGenerativeAIEmbeddings(model="models/embedding-001", google_api_key=
|
| 54 |
zip_path = "./chroma_db1.zip"
|
| 55 |
extract_dir = "chroma_db2"
|
| 56 |
if os.path.exists(zip_path):
|
|
@@ -71,10 +60,10 @@ def initialize_vectorstore(_api_key):
|
|
| 71 |
|
| 72 |
# Initialize vectorstore and retriever
|
| 73 |
retriever = None
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
|
| 79 |
# Prompt template
|
| 80 |
prompt = ChatPromptTemplate.from_messages([
|
|
|
|
| 30 |
st.markdown("Ask financial questions about ITC Ltd. based on transcript data, powered by AI.")
|
| 31 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
|
| 35 |
+
# Load API key securely from Hugging Face secrets
|
| 36 |
+
GOOGLE_API_KEY = st.secrets.get("GOOGLE_API_KEY")
|
| 37 |
+
|
| 38 |
|
| 39 |
# Initialize Chroma DB
|
| 40 |
@st.cache_resource
|
| 41 |
+
def initialize_vectorstore(GOOGLE_API_KEY):
|
| 42 |
+
embedding = GoogleGenerativeAIEmbeddings(model="models/embedding-001", google_api_key=GOOGLE_API_KEY)
|
| 43 |
zip_path = "./chroma_db1.zip"
|
| 44 |
extract_dir = "chroma_db2"
|
| 45 |
if os.path.exists(zip_path):
|
|
|
|
| 60 |
|
| 61 |
# Initialize vectorstore and retriever
|
| 62 |
retriever = None
|
| 63 |
+
|
| 64 |
+
vectorstore = initialize_vectorstore(GOOGLE_API_KEY)
|
| 65 |
+
if vectorstore:
|
| 66 |
+
retriever = vectorstore.as_retriever(search_type="mmr", search_kwargs={"k": 3, "lambda_mult": 1})
|
| 67 |
|
| 68 |
# Prompt template
|
| 69 |
prompt = ChatPromptTemplate.from_messages([
|