Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- .gitattributes +1 -0
- Highway Traffic Act, R.S.O. 1990, c. H.8[465] - Copy.pdf +3 -0
- app.py +57 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
Highway[[:space:]]Traffic[[:space:]]Act,[[:space:]]R.S.O.[[:space:]]1990,[[:space:]]c.[[:space:]]H.8\[465\][[:space:]]-[[:space:]]Copy.pdf filter=lfs diff=lfs merge=lfs -text
|
Highway Traffic Act, R.S.O. 1990, c. H.8[465] - Copy.pdf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:24d51f28f6539f1adbb8ea9510a1414eb59c75a12c98739b8cd07128dc1fa043
|
3 |
+
size 1181819
|
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from langchain.vectorstores import FAISS
|
3 |
+
from langchain.document_loaders import PyPDFLoader
|
4 |
+
from langchain.chains.question_answering import load_qa_chain
|
5 |
+
from langchain.prompts import PromptTemplate
|
6 |
+
from langchain.memory import ConversationBufferMemory
|
7 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
8 |
+
from langchain.chains import RetrievalQA
|
9 |
+
from langchain.document_loaders import UnstructuredFileLoader
|
10 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
11 |
+
from langchain.chains import RetrievalQAWithSourcesChain
|
12 |
+
from huggingface_hub import notebook_login
|
13 |
+
from transformers import pipeline
|
14 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
15 |
+
from langchain import HuggingFacePipeline
|
16 |
+
from langchain.text_splitter import CharacterTextSplitter
|
17 |
+
import textwrap
|
18 |
+
import sys
|
19 |
+
import os
|
20 |
+
|
21 |
+
|
22 |
+
os.environ['HuggingFaceHub_API_Token']= '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'
|
23 |
+
loader = UnstructuredFileLoader('./Highway Traffic Act, R.S.O. 1990, c. H.8[465] - Copy.pdf')
|
24 |
+
documents = loader.load()
|
25 |
+
|
26 |
+
text_splitter=CharacterTextSplitter(separator='\n',
|
27 |
+
chunk_size=1000,
|
28 |
+
chunk_overlap=50)
|
29 |
+
text_chunks=text_splitter.split_documents(documents)
|
30 |
+
|
31 |
+
embeddings = HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2',model_kwargs={'device': 'cuda'})
|
32 |
+
|
33 |
+
vectorstore=FAISS.from_documents(text_chunks, embeddings)
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
from huggingface_hub import notebook_login
|
40 |
+
|
41 |
+
notebook_login()
|
42 |
+
|
43 |
+
import torch
|
44 |
+
os.environ['HuggingFaceHub_API_Token']= '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'
|
45 |
+
tokenizer = AutoTokenizer.from_pretrained("daryl149/llama-2-7b-chat-hf")
|
46 |
+
|
47 |
+
model = AutoModelForCausalLM.from_pretrained("daryl149/llama-2-7b-chat-hf", device_map='auto',torch_dtype=torch.float16,load_in_8bit=True, token=True )
|
48 |
+
pipe = pipeline("text-generation",model=model,tokenizer= tokenizer,torch_dtype=torch.bfloat16,device_map="auto",max_new_tokens = 1024,do_sample=True,top_k=10,num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)
|
49 |
+
|
50 |
+
llm=HuggingFacePipeline(pipeline=pipe, model_kwargs={'temperature':0})
|
51 |
+
chain = RetrievalQA.from_chain_type(llm=llm, chain_type = "stuff",return_source_documents=True, retriever=vectorstore.as_retriever())
|
52 |
+
|
53 |
+
query = "What happens when we drive under influence ?"
|
54 |
+
result=chain({"query": query}, return_only_outputs=True)
|
55 |
+
wrapped_text = textwrap.fill(result['result'], width=500)
|
56 |
+
wrapped_text
|
57 |
+
|