Spaces:
Running
Running
Upload ocr_service.py
Browse files- ocr_service.py +5 -3
ocr_service.py
CHANGED
|
@@ -166,6 +166,7 @@ def _patch_deepseek_model_for_compatibility():
|
|
| 166 |
if "LlamaFlashAttention2 = LlamaAttention" in content:
|
| 167 |
print("✅ Model already patched")
|
| 168 |
return # Already patched
|
|
|
|
| 169 |
except Exception as e:
|
| 170 |
print(f"⚠️ Could not read model file to check patch status: {e}")
|
| 171 |
return
|
|
@@ -371,14 +372,15 @@ except ImportError:
|
|
| 371 |
])
|
| 372 |
new_lines.extend(lines_for_fallback[i+1:])
|
| 373 |
content = '\n'.join(new_lines)
|
| 374 |
-
with open(model_file, 'w', encoding='utf-8') as f:
|
| 375 |
-
f.write(content)
|
| 376 |
print(f"✅ Added fallback import block after line {i}")
|
| 377 |
patched = True
|
| 378 |
break
|
| 379 |
|
| 380 |
if patched:
|
| 381 |
-
#
|
|
|
|
|
|
|
|
|
|
| 382 |
print(f"✅ Successfully patched DeepSeek model file: {model_file}")
|
| 383 |
else:
|
| 384 |
print(f"⚠️ Could not find LlamaFlashAttention2 import to patch in {model_file}")
|
|
|
|
| 166 |
if "LlamaFlashAttention2 = LlamaAttention" in content:
|
| 167 |
print("✅ Model already patched")
|
| 168 |
return # Already patched
|
| 169 |
+
original_content = content # Save original for comparison
|
| 170 |
except Exception as e:
|
| 171 |
print(f"⚠️ Could not read model file to check patch status: {e}")
|
| 172 |
return
|
|
|
|
| 372 |
])
|
| 373 |
new_lines.extend(lines_for_fallback[i+1:])
|
| 374 |
content = '\n'.join(new_lines)
|
|
|
|
|
|
|
| 375 |
print(f"✅ Added fallback import block after line {i}")
|
| 376 |
patched = True
|
| 377 |
break
|
| 378 |
|
| 379 |
if patched:
|
| 380 |
+
# Write file if content was modified
|
| 381 |
+
# (fallback already writes immediately, regex patterns modify content then write here)
|
| 382 |
+
with open(model_file, 'w', encoding='utf-8') as f:
|
| 383 |
+
f.write(content)
|
| 384 |
print(f"✅ Successfully patched DeepSeek model file: {model_file}")
|
| 385 |
else:
|
| 386 |
print(f"⚠️ Could not find LlamaFlashAttention2 import to patch in {model_file}")
|