Vinay15 commited on
Commit
802d2bc
·
verified ·
1 Parent(s): 1bc9a60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -1,11 +1,26 @@
1
  import gradio as gr
 
2
  from transformers import AutoModel, AutoTokenizer
3
  from PIL import Image
4
 
 
 
 
 
 
 
 
 
5
  # Load the tokenizer and model
6
  tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
7
- model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True, low_cpu_mem_usage=True, device_map='cuda', use_safetensors=True, pad_token_id=tokenizer.eos_token_id)
8
- model = model.eval().cuda()
 
 
 
 
 
 
9
 
10
  # Define the OCR function
11
  def perform_ocr(image):
 
1
  import gradio as gr
2
+ import torch
3
  from transformers import AutoModel, AutoTokenizer
4
  from PIL import Image
5
 
6
+ # Check GPU availability
7
+ if torch.cuda.is_available():
8
+ print("CUDA is available! GPU is present.")
9
+ print(f"Number of GPUs: {torch.cuda.device_count()}")
10
+ print(f"GPU Name: {torch.cuda.get_device_name(0)}")
11
+ else:
12
+ print("CUDA is not available. Running on CPU.")
13
+
14
  # Load the tokenizer and model
15
  tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
16
+
17
+ # Initialize the model
18
+ if torch.cuda.is_available():
19
+ model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True, low_cpu_mem_usage=True, device_map='cuda', use_safetensors=True, pad_token_id=tokenizer.eos_token_id)
20
+ model = model.eval().cuda()
21
+ else:
22
+ model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True, low_cpu_mem_usage=True, pad_token_id=tokenizer.eos_token_id)
23
+ model = model.eval() # Keep model on CPU
24
 
25
  # Define the OCR function
26
  def perform_ocr(image):