Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
| 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
|