random2222 commited on
Commit
aa8d70a
·
verified ·
1 Parent(s): f3e1614

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -13
app.py CHANGED
@@ -5,7 +5,7 @@ from langchain_community.embeddings import HuggingFaceEmbeddings
5
  from langchain_community.document_loaders import PyMuPDFLoader
6
  from langchain_text_splitters import CharacterTextSplitter
7
  from langchain.chains import RetrievalQA
8
- from langchain_community.llms import HuggingFaceEndpoint
9
  from huggingface_hub import login
10
 
11
  # Authentication
@@ -40,14 +40,12 @@ def create_qa_system():
40
  # Build vector store
41
  db = FAISS.from_documents(texts, embeddings)
42
 
43
- # Initialize LLM
44
  llm = HuggingFaceEndpoint(
45
- repo_id="google/flan-t5-small",
46
  task="text2text-generation",
47
- model_kwargs={
48
- "temperature": 0.2,
49
- "max_length": 128
50
- },
51
  huggingfacehub_api_token=os.environ.get('HF_TOKEN')
52
  )
53
 
@@ -73,9 +71,4 @@ def chat_response(message, history):
73
  print(f"Error during query: {str(e)}")
74
  return f"⚠️ Error: {str(e)[:100]}"
75
 
76
- # Create interface
77
- gr.ChatInterface(
78
- chat_response,
79
- title="PDF Chat Assistant",
80
- description="Ask questions about your PDF document"
81
- ).launch()
 
5
  from langchain_community.document_loaders import PyMuPDFLoader
6
  from langchain_text_splitters import CharacterTextSplitter
7
  from langchain.chains import RetrievalQA
8
+ from langchain_huggingface import HuggingFaceEndpoint # Updated import
9
  from huggingface_hub import login
10
 
11
  # Authentication
 
40
  # Build vector store
41
  db = FAISS.from_documents(texts, embeddings)
42
 
43
+ # Initialize LLM with corrected parameters
44
  llm = HuggingFaceEndpoint(
45
+ endpoint_url="https://api-inference.huggingface.co/models/google/flan-t5-small",
46
  task="text2text-generation",
47
+ temperature=0.2, # Direct parameter
48
+ max_new_tokens=128, # Correct parameter name
 
 
49
  huggingfacehub_api_token=os.environ.get('HF_TOKEN')
50
  )
51
 
 
71
  print(f"Error during query: {str(e)}")
72
  return f"⚠️ Error: {str(e)[:100]}"
73
 
74
+ gr.ChatInterface(chat_response).launch()