hypeconqueror1 commited on
Commit
75aae0c
·
verified ·
1 Parent(s): 73e3631

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +13 -19
main.py CHANGED
@@ -2,13 +2,11 @@ from fastapi import FastAPI, File, UploadFile, Form
2
  import os
3
  import shutil
4
  import tempfile
5
- from langchain_community.document_loaders import PyMuPDFLoader
6
- from LoadLLM import Loadllm
7
- from langchain_community.embeddings import HuggingFaceEmbeddings
8
- from langchain_community.vectorstores import FAISS
9
- from langchain.chains import ConversationalRetrievalChain
10
 
11
- DB_FAISS_PATH = 'vectorstore/db_faiss'
12
 
13
  app = FastAPI()
14
 
@@ -25,23 +23,19 @@ async def PromptLLM(file: UploadFile = File(...), query: str = Form(...)):
25
  shutil.copyfileobj(file.file, f)
26
 
27
 
28
- loader = PyMuPDFLoader(file_path= temp_file_path)
29
  data = loader.load()
30
 
31
- # Create embeddings using Sentence Transformers
32
- embeddings = HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2')
33
 
34
- # Create a FAISS vector store and save embeddings
35
- db = FAISS.from_documents(data, embeddings)
36
- db.save_local(DB_FAISS_PATH)
 
37
 
38
- # Load the language model
39
- llm = Loadllm.load_llm()
40
 
41
- # Create a conversational chain
42
- chain = ConversationalRetrievalChain.from_llm(llm=llm, retriever=db.as_retriever())
43
-
44
- result = chain({"question": query, "chat_history": ''})
45
- return result['answer']
46
 
47
 
 
2
  import os
3
  import shutil
4
  import tempfile
5
+ from langchain.document_loaders import PyPDFLoader
6
+ from langchain_community.llms import CTransformers
7
+ from langchain.chains import LLMChain
8
+ from langchain.prompts import PromptTemplate
 
9
 
 
10
 
11
  app = FastAPI()
12
 
 
23
  shutil.copyfileobj(file.file, f)
24
 
25
 
26
+ loader = PyPDFLoader(temp_file_path)
27
  data = loader.load()
28
 
29
+ llm = CTransformers(model="llama-2-7b-chat.ggmlv3.q4_1.bin", model_type="llama",
30
+ config={'max_new_tokens': 1024, 'context_length': 2048, 'temperature': 0.01})
31
 
32
+ template = """Summarise the report {pages}
33
+ """
34
+ prompt_template = PromptTemplate(input_variables=["pages"], template=template)
35
+ chain = LLMChain(llm=llm, prompt=prompt_template)
36
 
 
 
37
 
38
+ result = chain.run(pages=data[0].page_content)
39
+ return result
 
 
 
40
 
41