Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,21 @@ from langchain.llms import OpenAI, HuggingFaceHub
|
|
| 6 |
from langchain.embeddings import OpenAIEmbeddings, HuggingFaceEmbeddings
|
| 7 |
from langchain.document_loaders import PyPDFLoader
|
| 8 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Define paths for cybersecurity training PDFs
|
| 11 |
PDF_FILES = [
|
|
|
|
| 6 |
from langchain.embeddings import OpenAIEmbeddings, HuggingFaceEmbeddings
|
| 7 |
from langchain.document_loaders import PyPDFLoader
|
| 8 |
import time
|
| 9 |
+
from langchain_huggingface import HuggingFaceEndpoint
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# Fetch API token securely from environment variables
|
| 13 |
+
HUGGINGFACE_API_KEY = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
| 14 |
+
|
| 15 |
+
if HUGGINGFACE_API_KEY is None:
|
| 16 |
+
raise ValueError("Hugging Face API token is missing! Set it as a secret in Hugging Face Spaces.")
|
| 17 |
+
|
| 18 |
+
# Load LLM securely
|
| 19 |
+
llm = HuggingFaceEndpoint(
|
| 20 |
+
repo_id="google/flan-t5-large",
|
| 21 |
+
model_kwargs={"temperature": 0.5, "max_length": 512},
|
| 22 |
+
huggingfacehub_api_token=HUGGINGFACE_API_KEY # β
Secure API key usage
|
| 23 |
+
)
|
| 24 |
|
| 25 |
# Define paths for cybersecurity training PDFs
|
| 26 |
PDF_FILES = [
|