Spaces:
Running
on
Zero
Running
on
Zero
Felipe Silva
commited on
Commit
·
d4f3e2b
1
Parent(s):
6c3954c
removed comments
Browse files- app.py +2 -2
- rag_utils.py +0 -11
app.py
CHANGED
|
@@ -3,12 +3,12 @@ import spaces
|
|
| 3 |
import torch
|
| 4 |
import os
|
| 5 |
from huggingface_hub import snapshot_download
|
| 6 |
-
from utils import
|
| 7 |
from rag_utils import create_split_doc, store_docs, create_rag_chain
|
| 8 |
import config
|
| 9 |
|
| 10 |
zero = torch.Tensor([0]).cuda()
|
| 11 |
-
print(zero.device)
|
| 12 |
|
| 13 |
MAX_FILE_SIZE = 10 * 1024 * 1024 # 10MB
|
| 14 |
|
|
|
|
| 3 |
import torch
|
| 4 |
import os
|
| 5 |
from huggingface_hub import snapshot_download
|
| 6 |
+
from utils import doc_converter, MSG_NENHUM_ARQUIVO_ENVIADO, MSG_TEXTO_NAO_EXTRAIDO
|
| 7 |
from rag_utils import create_split_doc, store_docs, create_rag_chain
|
| 8 |
import config
|
| 9 |
|
| 10 |
zero = torch.Tensor([0]).cuda()
|
| 11 |
+
print(zero.device)
|
| 12 |
|
| 13 |
MAX_FILE_SIZE = 10 * 1024 * 1024 # 10MB
|
| 14 |
|
rag_utils.py
CHANGED
|
@@ -5,11 +5,8 @@ from langchain.prompts import PromptTemplate
|
|
| 5 |
|
| 6 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 7 |
from langchain.llms import HuggingFacePipeline
|
| 8 |
-
|
| 9 |
-
from langchain.chat_models import ChatOpenAI
|
| 10 |
from langchain.chains import RetrievalQA
|
| 11 |
|
| 12 |
-
import spaces
|
| 13 |
import config
|
| 14 |
import torch
|
| 15 |
print(torch.cuda.is_available())
|
|
@@ -18,7 +15,6 @@ device = f'cuda:{torch.cuda.current_device()}' if torch.cuda.is_available() else
|
|
| 18 |
|
| 19 |
import os
|
| 20 |
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "0"
|
| 21 |
-
# cache_dir = "/home/user/.cache/huggingface" #"./model/qwen-awq" #"/home/felipe/.cache/huggingface/transformers" #"/home/user/.cache/huggingface"
|
| 22 |
|
| 23 |
_embedding_instance = None
|
| 24 |
_model_instance = None
|
|
@@ -32,9 +28,6 @@ def get_embedding_model():
|
|
| 32 |
_embedding_instance = HuggingFaceEmbeddings(model_name=config.local_emb_path, model_kwargs={"device": "cpu"})
|
| 33 |
return _embedding_instance
|
| 34 |
|
| 35 |
-
# model_name = "Qwen/Qwen2.5-7B-Instruct-GPTQ-Int8" #"Qwen/Qwen2.5-7B-Instruct-AWQ" #"Qwen/Qwen2.5-7B-Instruct"
|
| 36 |
-
|
| 37 |
-
# @spaces.GPU
|
| 38 |
def get_model():
|
| 39 |
global _model_instance
|
| 40 |
if _model_instance is None:
|
|
@@ -49,8 +42,6 @@ def get_model():
|
|
| 49 |
|
| 50 |
return _model_instance
|
| 51 |
|
| 52 |
-
# _model_instance.to(device)
|
| 53 |
-
|
| 54 |
def get_tokenizer():
|
| 55 |
global _tokenizer
|
| 56 |
if _tokenizer is None:
|
|
@@ -66,7 +57,6 @@ def create_split_doc(raw_text):
|
|
| 66 |
|
| 67 |
return docs
|
| 68 |
|
| 69 |
-
# @spaces.GPU
|
| 70 |
def store_docs(docs):
|
| 71 |
embedding_model = get_embedding_model()
|
| 72 |
vectorstore = FAISS.from_documents(docs, embedding_model)
|
|
@@ -90,7 +80,6 @@ Pergunta:
|
|
| 90 |
)
|
| 91 |
return prompt_template
|
| 92 |
|
| 93 |
-
# @spaces.GPU
|
| 94 |
def create_rag_chain(vectorstore):
|
| 95 |
pipe = pipeline(
|
| 96 |
"text-generation",
|
|
|
|
| 5 |
|
| 6 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 7 |
from langchain.llms import HuggingFacePipeline
|
|
|
|
|
|
|
| 8 |
from langchain.chains import RetrievalQA
|
| 9 |
|
|
|
|
| 10 |
import config
|
| 11 |
import torch
|
| 12 |
print(torch.cuda.is_available())
|
|
|
|
| 15 |
|
| 16 |
import os
|
| 17 |
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "0"
|
|
|
|
| 18 |
|
| 19 |
_embedding_instance = None
|
| 20 |
_model_instance = None
|
|
|
|
| 28 |
_embedding_instance = HuggingFaceEmbeddings(model_name=config.local_emb_path, model_kwargs={"device": "cpu"})
|
| 29 |
return _embedding_instance
|
| 30 |
|
|
|
|
|
|
|
|
|
|
| 31 |
def get_model():
|
| 32 |
global _model_instance
|
| 33 |
if _model_instance is None:
|
|
|
|
| 42 |
|
| 43 |
return _model_instance
|
| 44 |
|
|
|
|
|
|
|
| 45 |
def get_tokenizer():
|
| 46 |
global _tokenizer
|
| 47 |
if _tokenizer is None:
|
|
|
|
| 57 |
|
| 58 |
return docs
|
| 59 |
|
|
|
|
| 60 |
def store_docs(docs):
|
| 61 |
embedding_model = get_embedding_model()
|
| 62 |
vectorstore = FAISS.from_documents(docs, embedding_model)
|
|
|
|
| 80 |
)
|
| 81 |
return prompt_template
|
| 82 |
|
|
|
|
| 83 |
def create_rag_chain(vectorstore):
|
| 84 |
pipe = pipeline(
|
| 85 |
"text-generation",
|