Spaces:
Sleeping
Sleeping
Update main.py
Browse files
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
|
| 6 |
-
from
|
| 7 |
-
from
|
| 8 |
-
from
|
| 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 =
|
| 29 |
data = loader.load()
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
-
# Load the language model
|
| 39 |
-
llm = Loadllm.load_llm()
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 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 |
|