NeonSamurai commited on
Commit
2dfcda0
·
verified ·
1 Parent(s): 50e96a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -10,8 +10,6 @@ from langchain.prompts.chat import ChatPromptTemplate, MessagesPlaceholder
10
  from langchain_core.messages import HumanMessage, AIMessage
11
  from langchain.schema.output_parser import StrOutputParser
12
 
13
- import os
14
-
15
  st.set_page_config(page_title="ITC Financial Analysis ChatBot", layout="centered")
16
 
17
  # API key
@@ -19,7 +17,7 @@ API_key = os.environ.get("GOOGLE_API_KEY")
19
  if not API_key:
20
  st.error("❌ GOOGLE_API_KEY not found. Please set it in your Hugging Face Secrets.")
21
  st.stop()
22
-
23
  st.markdown("""
24
  <h1 style='text-align: center; color: white; font-size: 42px;'>
25
  📊 ITC Financials with AI
@@ -61,10 +59,13 @@ st.markdown(new_chat_button, unsafe_allow_html=True)
61
  if st.button("New Chat"):
62
  memory_buffer["chat_history"] = []
63
 
 
 
64
  # Load Chroma vector DB from zip
65
- # with zipfile.ZipFile('database/chroma_db_32_backup.zip', 'r') as zip_ref:
66
  # zip_ref.extractall('chroma_db')
67
 
 
68
  # Embeddings and vector store
69
  embedding = HuggingFaceEmbeddings(model_name='all-MiniLM-L6-v2')
70
  vectorstore = Chroma(persist_directory='database/chroma_db', embedding_function=embedding)
@@ -163,9 +164,10 @@ if user_input:
163
 
164
  # Show sources
165
  if output.get("source_documents"):
166
- st.markdown("**Sources:**")
167
- for doc in output["source_documents"]:
168
- st.markdown(f"- {doc.metadata.get('source', 'Unknown document')}")
 
169
 
170
  st.markdown(
171
  """
@@ -174,8 +176,7 @@ st.markdown(
174
  background-image: url("https://cdn-uploads.huggingface.co/production/uploads/673f5e166c2774fcc8a82f0b/i8t_a-SuqlO3MVVZv-Y0O.jpeg");
175
  background-size: cover;
176
  background-position: center;
177
- background-repeat: no-repeat;
178
- background-attachment: fixed;
179
  }
180
 
181
  /* Semi-transparent overlay */
@@ -191,4 +192,5 @@ st.markdown(
191
  }
192
  </style>
193
  """,
194
- unsafe_allow_html=True)
 
 
10
  from langchain_core.messages import HumanMessage, AIMessage
11
  from langchain.schema.output_parser import StrOutputParser
12
 
 
 
13
  st.set_page_config(page_title="ITC Financial Analysis ChatBot", layout="centered")
14
 
15
  # API key
 
17
  if not API_key:
18
  st.error("❌ GOOGLE_API_KEY not found. Please set it in your Hugging Face Secrets.")
19
  st.stop()
20
+
21
  st.markdown("""
22
  <h1 style='text-align: center; color: white; font-size: 42px;'>
23
  📊 ITC Financials with AI
 
59
  if st.button("New Chat"):
60
  memory_buffer["chat_history"] = []
61
 
62
+ # import zipfile
63
+
64
  # Load Chroma vector DB from zip
65
+ # with zipfile.ZipFile(r"C:\Users\hi\Desktop\Neuzen AI\chroma_db_backup.zip", 'r') as zip_ref:
66
  # zip_ref.extractall('chroma_db')
67
 
68
+
69
  # Embeddings and vector store
70
  embedding = HuggingFaceEmbeddings(model_name='all-MiniLM-L6-v2')
71
  vectorstore = Chroma(persist_directory='database/chroma_db', embedding_function=embedding)
 
164
 
165
  # Show sources
166
  if output.get("source_documents"):
167
+ st.markdown("#### Source Documents", unsafe_allow_html=True)
168
+ for i, doc in enumerate(output["source_documents"], 1):
169
+ source_name = doc.metadata.get("source", f"Document {i}")
170
+ st.markdown(f"*{i}. {source_name}*")
171
 
172
  st.markdown(
173
  """
 
176
  background-image: url("https://cdn-uploads.huggingface.co/production/uploads/673f5e166c2774fcc8a82f0b/i8t_a-SuqlO3MVVZv-Y0O.jpeg");
177
  background-size: cover;
178
  background-position: center;
179
+ height: 100vh;
 
180
  }
181
 
182
  /* Semi-transparent overlay */
 
192
  }
193
  </style>
194
  """,
195
+ unsafe_allow_html=True
196
+ )