Spaces:
Sleeping
Sleeping
Felipe Silva
commited on
Commit
·
c3bd22b
1
Parent(s):
315fbb4
ajsute
Browse files- app.py +1 -0
- rag_utils.py +5 -6
app.py
CHANGED
|
@@ -46,6 +46,7 @@ def process_file(file):
|
|
| 46 |
texto_extraido = "OCR não implementado neste exemplo."
|
| 47 |
return texto_extraido or "Não foi possível extrair texto."
|
| 48 |
|
|
|
|
| 49 |
def ask_question(texto_extraido, question):
|
| 50 |
|
| 51 |
# RAG
|
|
|
|
| 46 |
texto_extraido = "OCR não implementado neste exemplo."
|
| 47 |
return texto_extraido or "Não foi possível extrair texto."
|
| 48 |
|
| 49 |
+
@spaces.GPU
|
| 50 |
def ask_question(texto_extraido, question):
|
| 51 |
|
| 52 |
# RAG
|
rag_utils.py
CHANGED
|
@@ -34,7 +34,7 @@ def get_embedding_model():
|
|
| 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:
|
|
@@ -42,7 +42,7 @@ def get_model():
|
|
| 42 |
raise ValueError("⚠️ config.local_model_path ainda não foi inicializado!")
|
| 43 |
_model_instance = AutoModelForCausalLM.from_pretrained(
|
| 44 |
config.local_model_path,
|
| 45 |
-
|
| 46 |
device_map={"": "cuda"},
|
| 47 |
trust_remote_code=True
|
| 48 |
)
|
|
@@ -66,7 +66,7 @@ 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 +90,7 @@ Pergunta:
|
|
| 90 |
)
|
| 91 |
return prompt_template
|
| 92 |
|
| 93 |
-
@spaces.GPU
|
| 94 |
def create_rag_chain(vectorstore):
|
| 95 |
pipe = pipeline(
|
| 96 |
"text-generation",
|
|
@@ -98,8 +98,7 @@ def create_rag_chain(vectorstore):
|
|
| 98 |
tokenizer=get_tokenizer(),
|
| 99 |
max_new_tokens=512,
|
| 100 |
temperature=0.1,
|
| 101 |
-
do_sample=False
|
| 102 |
-
device=-1
|
| 103 |
)
|
| 104 |
|
| 105 |
# Adapta para LangChain
|
|
|
|
| 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:
|
|
|
|
| 42 |
raise ValueError("⚠️ config.local_model_path ainda não foi inicializado!")
|
| 43 |
_model_instance = AutoModelForCausalLM.from_pretrained(
|
| 44 |
config.local_model_path,
|
| 45 |
+
dtype=torch.float16,
|
| 46 |
device_map={"": "cuda"},
|
| 47 |
trust_remote_code=True
|
| 48 |
)
|
|
|
|
| 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 |
)
|
| 91 |
return prompt_template
|
| 92 |
|
| 93 |
+
# @spaces.GPU
|
| 94 |
def create_rag_chain(vectorstore):
|
| 95 |
pipe = pipeline(
|
| 96 |
"text-generation",
|
|
|
|
| 98 |
tokenizer=get_tokenizer(),
|
| 99 |
max_new_tokens=512,
|
| 100 |
temperature=0.1,
|
| 101 |
+
do_sample=False
|
|
|
|
| 102 |
)
|
| 103 |
|
| 104 |
# Adapta para LangChain
|