Vinay15 commited on
Commit
33ba818
·
verified ·
1 Parent(s): 3534c83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  from transformers import AutoModel, AutoTokenizer
3
  from PIL import Image
4
- import numpy as np
5
 
6
  # Load the tokenizer and model
7
  tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
@@ -15,11 +15,12 @@ def perform_ocr(image):
15
  if image.mode != "RGB":
16
  image = image.convert("RGB")
17
 
18
- # Convert the image to a format suitable for the model (if needed)
19
- image_array = np.array(image)
 
20
 
21
- # Perform OCR using the model
22
- res = model.chat(tokenizer, image_array, ocr_type='ocr') # Adjusted to pass the image array
23
 
24
  return res
25
  except Exception as e:
 
1
  import gradio as gr
2
  from transformers import AutoModel, AutoTokenizer
3
  from PIL import Image
4
+ import tempfile
5
 
6
  # Load the tokenizer and model
7
  tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
 
15
  if image.mode != "RGB":
16
  image = image.convert("RGB")
17
 
18
+ # Save the image to a temporary file
19
+ with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as temp_file:
20
+ image.save(temp_file.name)
21
 
22
+ # Perform OCR using the model
23
+ res = model.chat(tokenizer, temp_file.name, ocr_type='ocr') # Pass the file path
24
 
25
  return res
26
  except Exception as e: