eabybabu commited on
Commit
301bbfc
Β·
verified Β·
1 Parent(s): 3cb032f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
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 # βœ… Fixed Import
5
- from langchain.llms import OpenAI
6
- from langchain_huggingface import HuggingFaceEndpoint # βœ… Corrected Import
7
- from langchain.embeddings import OpenAIEmbeddings
8
- from langchain_community.embeddings import HuggingFaceEmbeddings # βœ… Corrected Import
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, # βœ… Explicitly set temperature
45
- max_length=512, # βœ… Explicitly set max_length
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.run(question)
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