Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from langchain.chains import RetrievalQA
|
| 4 |
-
from langchain_community.vectorstores import Chroma
|
| 5 |
-
from
|
| 6 |
-
from langchain_huggingface import HuggingFaceEndpoint # β
|
| 7 |
-
from
|
| 8 |
-
from langchain_community.
|
| 9 |
-
from langchain_community.document_loaders import PyPDFLoader # β
Corrected Import
|
| 10 |
import time
|
| 11 |
|
| 12 |
# Define paths for cybersecurity training PDFs
|
|
@@ -41,8 +40,8 @@ vector_db = load_data()
|
|
| 41 |
# Load LLM from Hugging Face securely
|
| 42 |
llm = HuggingFaceEndpoint(
|
| 43 |
repo_id="google/flan-t5-large",
|
| 44 |
-
temperature=0.5, # β
|
| 45 |
-
|
| 46 |
huggingfacehub_api_token=HUGGINGFACE_API_KEY
|
| 47 |
)
|
| 48 |
|
|
@@ -52,7 +51,7 @@ qa_chain = RetrievalQA.from_chain_type(llm=llm, retriever=vector_db.as_retriever
|
|
| 52 |
# Function to simulate futuristic typing effect
|
| 53 |
def chatbot_response(question):
|
| 54 |
"""Handles chatbot queries with a typing effect"""
|
| 55 |
-
response = qa_chain.
|
| 56 |
displayed_response = ""
|
| 57 |
for char in response:
|
| 58 |
displayed_response += char
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from langchain.chains import RetrievalQA
|
| 4 |
+
from langchain_community.vectorstores import Chroma
|
| 5 |
+
from langchain_community.llms import OpenAI # β
Fixed Import
|
| 6 |
+
from langchain_huggingface import HuggingFaceEndpoint # β
Fixed Import
|
| 7 |
+
from langchain_community.embeddings import OpenAIEmbeddings, HuggingFaceEmbeddings # β
Fixed Import
|
| 8 |
+
from langchain_community.document_loaders import PyPDFLoader # β
Fixed Import
|
|
|
|
| 9 |
import time
|
| 10 |
|
| 11 |
# Define paths for cybersecurity training PDFs
|
|
|
|
| 40 |
# Load LLM from Hugging Face securely
|
| 41 |
llm = HuggingFaceEndpoint(
|
| 42 |
repo_id="google/flan-t5-large",
|
| 43 |
+
temperature=0.5, # β
Ensure temperature is explicit
|
| 44 |
+
max_new_tokens=250, # β
Ensure API limit is followed
|
| 45 |
huggingfacehub_api_token=HUGGINGFACE_API_KEY
|
| 46 |
)
|
| 47 |
|
|
|
|
| 51 |
# Function to simulate futuristic typing effect
|
| 52 |
def chatbot_response(question):
|
| 53 |
"""Handles chatbot queries with a typing effect"""
|
| 54 |
+
response = qa_chain.invoke(question) # β
Use invoke instead of deprecated `run`
|
| 55 |
displayed_response = ""
|
| 56 |
for char in response:
|
| 57 |
displayed_response += char
|