yuragoithf commited on
Commit
170cbbb
·
verified ·
1 Parent(s): c547456

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -0
app.py CHANGED
@@ -6,6 +6,7 @@ from transformers import TrOCRProcessor, VisionEncoderDecoderModel
6
  import gradio as gr
7
  import numpy as np
8
  from PIL import Image
 
9
 
10
  # Load models on CPU (Hugging Face Spaces default)
11
  craft_model = Model.load("hezarai/CRAFT", device="cpu")
@@ -22,6 +23,10 @@ def recognize_handwritten_text(image):
22
  # Load image with hezar utils using file path
23
  processed_image = load_image(tmp_path)
24
 
 
 
 
 
25
  # Detect text regions with CRAFT
26
  outputs = craft_model.predict(processed_image)
27
  if not outputs or "boxes" not in outputs[0]:
 
6
  import gradio as gr
7
  import numpy as np
8
  from PIL import Image
9
+ import io
10
 
11
  # Load models on CPU (Hugging Face Spaces default)
12
  craft_model = Model.load("hezarai/CRAFT", device="cpu")
 
23
  # Load image with hezar utils using file path
24
  processed_image = load_image(tmp_path)
25
 
26
+ # Ensure processed_image is in a compatible format (convert to NumPy if needed)
27
+ if not isinstance(processed_image, np.ndarray):
28
+ processed_image = np.array(Image.open(tmp_path))
29
+
30
  # Detect text regions with CRAFT
31
  outputs = craft_model.predict(processed_image)
32
  if not outputs or "boxes" not in outputs[0]: