Update handler.py
Browse files- handler.py +3 -14
handler.py
CHANGED
|
@@ -4,7 +4,7 @@ from subprocess import run
|
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
run("pip install flash-attn --no-build-isolation", shell=True, check=True)
|
| 7 |
-
run("pip install -U bitsandbytes", shell=True, check=True)
|
| 8 |
|
| 9 |
from transformers import AutoModelForVision2Seq, AutoProcessor, BitsAndBytesConfig
|
| 10 |
|
|
@@ -19,26 +19,15 @@ bnb_config = BitsAndBytesConfig(
|
|
| 19 |
llm_int8_enable_fp32_cpu_offload=True
|
| 20 |
)
|
| 21 |
|
| 22 |
-
try:
|
| 23 |
-
import flash_attn
|
| 24 |
-
print("FlashAttention is installed")
|
| 25 |
-
USE_FLASH_ATTENTION = True
|
| 26 |
-
except ImportError:
|
| 27 |
-
print("FlashAttention is not installed")
|
| 28 |
-
USE_FLASH_ATTENTION = False
|
| 29 |
-
|
| 30 |
-
|
| 31 |
# check for GPU
|
| 32 |
device = 0 if torch.cuda.is_available() else -1
|
| 33 |
|
| 34 |
-
|
| 35 |
class Utils:
|
| 36 |
def convert_base64_to_jpg(base64_string):
|
| 37 |
image_data = base64.b64decode(base64_string)
|
| 38 |
with open("./do_img.jpg", 'wb') as f:
|
| 39 |
f.write(image_data)
|
| 40 |
|
| 41 |
-
|
| 42 |
class PromptSet:
|
| 43 |
system_message = "You are an expert in analyzing and extracting information from freight, shipment, or delivery orders. Please carefully read the provided order file and extract the following 10 key pieces of information. Ensure that the key names are exactly as listed below. Do not create any additional key names other than these. If any information is missing or unavailable, output '-'."
|
| 44 |
main_order_information_prompt = """#Key names and their descriptions:
|
|
@@ -120,6 +109,6 @@ class EndpointHandler():
|
|
| 120 |
tokenize=True, return_dict=True,return_tensors="pt").to(device)
|
| 121 |
|
| 122 |
|
| 123 |
-
output = model.generate(**model_inputs, max_new_tokens=512)
|
| 124 |
-
prediction = processor.decode(output[0], skip_special_tokens=True)
|
| 125 |
return prediction
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
run("pip install flash-attn --no-build-isolation", shell=True, check=True)
|
| 7 |
+
#run("pip install -U bitsandbytes", shell=True, check=True)
|
| 8 |
|
| 9 |
from transformers import AutoModelForVision2Seq, AutoProcessor, BitsAndBytesConfig
|
| 10 |
|
|
|
|
| 19 |
llm_int8_enable_fp32_cpu_offload=True
|
| 20 |
)
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
# check for GPU
|
| 23 |
device = 0 if torch.cuda.is_available() else -1
|
| 24 |
|
|
|
|
| 25 |
class Utils:
|
| 26 |
def convert_base64_to_jpg(base64_string):
|
| 27 |
image_data = base64.b64decode(base64_string)
|
| 28 |
with open("./do_img.jpg", 'wb') as f:
|
| 29 |
f.write(image_data)
|
| 30 |
|
|
|
|
| 31 |
class PromptSet:
|
| 32 |
system_message = "You are an expert in analyzing and extracting information from freight, shipment, or delivery orders. Please carefully read the provided order file and extract the following 10 key pieces of information. Ensure that the key names are exactly as listed below. Do not create any additional key names other than these. If any information is missing or unavailable, output '-'."
|
| 33 |
main_order_information_prompt = """#Key names and their descriptions:
|
|
|
|
| 109 |
tokenize=True, return_dict=True,return_tensors="pt").to(device)
|
| 110 |
|
| 111 |
|
| 112 |
+
output = self.model.generate(**model_inputs, max_new_tokens=512)
|
| 113 |
+
prediction = self.processor.decode(output[0], skip_special_tokens=True)
|
| 114 |
return prediction
|