Spaces:
Sleeping
Sleeping
add cuda
Browse files
app.py
CHANGED
|
@@ -9,12 +9,16 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
| 9 |
|
| 10 |
# MODEL_NAME = "numind/NuExtract-1.5-tiny"
|
| 11 |
MODEL_NAME = "numind/NuExtract-1.5"
|
| 12 |
-
DEVICE = "
|
| 13 |
# MODEL = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.bfloat16, trust_remote_code=True).to(DEVICE).eval()
|
| 14 |
# TOKENIZER = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)
|
| 15 |
|
| 16 |
-
MODEL = AutoModelForCausalLM.from_pretrained(MODEL_NAME,
|
|
|
|
|
|
|
|
|
|
| 17 |
TOKENIZER = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)
|
|
|
|
| 18 |
|
| 19 |
MAX_INPUT_SIZE = 20_000
|
| 20 |
MAX_NEW_TOKENS = 6000
|
|
@@ -64,11 +68,6 @@ def process_and_generate(pdf_file):
|
|
| 64 |
print(template)
|
| 65 |
print(current)
|
| 66 |
|
| 67 |
-
# chunks = split_document(extracted_text)
|
| 68 |
-
# for chunk in chunks:
|
| 69 |
-
# current = send_chunk_to_model(chunk, template, current)
|
| 70 |
-
# return json.dumps(json.loads(current), indent=2, ensure_ascii=False)
|
| 71 |
-
|
| 72 |
pred_template = sliding_window_prediction(current, template, MODEL, TOKENIZER)
|
| 73 |
return pred_template
|
| 74 |
|
|
@@ -125,4 +124,4 @@ interface = gr.Interface(
|
|
| 125 |
description="Extrai informações do PDF, preenche um modelo JSON e gera perguntas sobre o conteúdo usando Mistral."
|
| 126 |
)
|
| 127 |
|
| 128 |
-
interface.launch(share=True)
|
|
|
|
| 9 |
|
| 10 |
# MODEL_NAME = "numind/NuExtract-1.5-tiny"
|
| 11 |
MODEL_NAME = "numind/NuExtract-1.5"
|
| 12 |
+
DEVICE = "cuda"
|
| 13 |
# MODEL = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.bfloat16, trust_remote_code=True).to(DEVICE).eval()
|
| 14 |
# TOKENIZER = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)
|
| 15 |
|
| 16 |
+
MODEL = AutoModelForCausalLM.from_pretrained(MODEL_NAME,
|
| 17 |
+
torch_dtype=torch.bfloat16,
|
| 18 |
+
trust_remote_code=True,
|
| 19 |
+
device_map="auto")
|
| 20 |
TOKENIZER = AutoTokenizer.from_pretrained(MODEL_NAME, trust_remote_code=True)
|
| 21 |
+
MODEL.eval()
|
| 22 |
|
| 23 |
MAX_INPUT_SIZE = 20_000
|
| 24 |
MAX_NEW_TOKENS = 6000
|
|
|
|
| 68 |
print(template)
|
| 69 |
print(current)
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
pred_template = sliding_window_prediction(current, template, MODEL, TOKENIZER)
|
| 72 |
return pred_template
|
| 73 |
|
|
|
|
| 124 |
description="Extrai informações do PDF, preenche um modelo JSON e gera perguntas sobre o conteúdo usando Mistral."
|
| 125 |
)
|
| 126 |
|
| 127 |
+
interface.launch(debug=True, share=True)
|