Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -45,24 +45,19 @@ with open(formatter_path, "w") as f:
|
|
| 45 |
|
| 46 |
print("β
result_formatter.py fixed")
|
| 47 |
|
| 48 |
-
# ββ STEP 3:
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
"zai-org/GLM-OCR",
|
| 62 |
-
torch_dtype=torch.bfloat16,
|
| 63 |
-
device_map="auto",
|
| 64 |
-
)
|
| 65 |
-
print(f"β
Model ready on {next(model.parameters()).device}")
|
| 66 |
|
| 67 |
# ββ STEP 4: OCR one image βββββββββββββββββββββββββββββββββββββ
|
| 68 |
def ocr_image(img_path):
|
|
@@ -107,8 +102,6 @@ def run_ocr(uploaded_file):
|
|
| 107 |
return "Please upload a file.", "No regions detected."
|
| 108 |
|
| 109 |
try:
|
| 110 |
-
load_model()
|
| 111 |
-
|
| 112 |
path = uploaded_file.name if hasattr(uploaded_file, "name") else str(uploaded_file)
|
| 113 |
|
| 114 |
if path.lower().endswith(".pdf"):
|
|
|
|
| 45 |
|
| 46 |
print("β
result_formatter.py fixed")
|
| 47 |
|
| 48 |
+
# ββ STEP 3: Load model at startup ββββββββββββββββββββββββββββ
|
| 49 |
+
from transformers import AutoProcessor, GlmOcrForConditionalGeneration
|
| 50 |
+
|
| 51 |
+
print("Loading model at startup...")
|
| 52 |
+
processor = AutoProcessor.from_pretrained("zai-org/GLM-OCR")
|
| 53 |
+
model = GlmOcrForConditionalGeneration.from_pretrained(
|
| 54 |
+
"zai-org/GLM-OCR",
|
| 55 |
+
torch_dtype=torch.bfloat16,
|
| 56 |
+
device_map="auto",
|
| 57 |
+
)
|
| 58 |
+
print(f"β
Model ready on {next(model.parameters()).device}")
|
| 59 |
+
|
| 60 |
+
ABANDON = set(config["pipeline"]["result_formatter"]["abandon"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
# ββ STEP 4: OCR one image βββββββββββββββββββββββββββββββββββββ
|
| 63 |
def ocr_image(img_path):
|
|
|
|
| 102 |
return "Please upload a file.", "No regions detected."
|
| 103 |
|
| 104 |
try:
|
|
|
|
|
|
|
| 105 |
path = uploaded_file.name if hasattr(uploaded_file, "name") else str(uploaded_file)
|
| 106 |
|
| 107 |
if path.lower().endswith(".pdf"):
|