eabybabu commited on
Commit
40d8e16
Β·
verified Β·
1 Parent(s): 6e9ad17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -7,6 +7,7 @@ from langchain_huggingface import HuggingFaceEndpoint, HuggingFaceEmbeddings #
7
  from langchain_community.document_loaders import PyPDFLoader # βœ… Fixed Import
8
  import time
9
 
 
10
  os.system("pip install -U huggingface_hub langchain_huggingface langchain_core langchain")
11
 
12
  # Define paths for cybersecurity training PDFs
@@ -19,7 +20,7 @@ PDF_FILES = [
19
 
20
  # Fetch Hugging Face API token securely from environment variables
21
  HUGGINGFACE_API_KEY = os.getenv("HUGGINGFACEHUB_API_TOKEN")
22
- if HUGGINGFACE_API_KEY is None:
23
  raise ValueError("❌ Hugging Face API token is missing! Set it in Hugging Face Spaces Secrets.")
24
 
25
  # Load PDFs into ChromaDB
@@ -53,6 +54,11 @@ qa_chain = RetrievalQA.from_chain_type(llm=llm, retriever=vector_db.as_retriever
53
  def chatbot_response(question):
54
  """Handles chatbot queries with a typing effect"""
55
  response = qa_chain.invoke(question) # βœ… Use `invoke` instead of deprecated `run`
 
 
 
 
 
56
  displayed_response = ""
57
  for char in response:
58
  displayed_response += char
 
7
  from langchain_community.document_loaders import PyPDFLoader # βœ… Fixed Import
8
  import time
9
 
10
+ # Ensure required packages are up-to-date
11
  os.system("pip install -U huggingface_hub langchain_huggingface langchain_core langchain")
12
 
13
  # Define paths for cybersecurity training PDFs
 
20
 
21
  # Fetch Hugging Face API token securely from environment variables
22
  HUGGINGFACE_API_KEY = os.getenv("HUGGINGFACEHUB_API_TOKEN")
23
+ if not HUGGINGFACE_API_KEY:
24
  raise ValueError("❌ Hugging Face API token is missing! Set it in Hugging Face Spaces Secrets.")
25
 
26
  # Load PDFs into ChromaDB
 
54
  def chatbot_response(question):
55
  """Handles chatbot queries with a typing effect"""
56
  response = qa_chain.invoke(question) # βœ… Use `invoke` instead of deprecated `run`
57
+
58
+ # Ensure response is a string to avoid errors
59
+ if not isinstance(response, str):
60
+ response = str(response)
61
+
62
  displayed_response = ""
63
  for char in response:
64
  displayed_response += char