YagndeepKukadiya commited on
Commit
d0595ee
·
verified ·
1 Parent(s): 07a8b7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -0
app.py CHANGED
@@ -7,6 +7,19 @@ import tempfile
7
  from PIL import Image, ImageDraw
8
  import re # Import thư viện regular expression
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # --- 1. Load Model and Tokenizer (Done only once at startup) ---
11
  print("Loading model and tokenizer...")
12
  model_name = "deepseek-ai/DeepSeek-OCR"
 
7
  from PIL import Image, ImageDraw
8
  import re # Import thư viện regular expression
9
 
10
+ # --- Monkey-Patch to Force CPU Execution ---
11
+ # ADD THIS BLOCK HERE
12
+ import torch
13
+ print("Applying monkey-patch to force CPU execution...")
14
+ original_cuda = torch.Tensor.cuda
15
+ def force_cpu_cuda(self, device=None, non_blocking=False, **kwargs):
16
+ # print(f"Intercepted .cuda() call. Forcing tensor to remain on CPU.")
17
+ return self.to("cpu") # Always move/keep on CPU
18
+
19
+ torch.Tensor.cuda = force_cpu_cuda
20
+ # --- End Monkey-Patch ---
21
+
22
+
23
  # --- 1. Load Model and Tokenizer (Done only once at startup) ---
24
  print("Loading model and tokenizer...")
25
  model_name = "deepseek-ai/DeepSeek-OCR"