mohammad2928git commited on
Commit
4e97d5b
·
verified ·
1 Parent(s): 7aab5ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -26,9 +26,9 @@ import os
26
  # Function to perform OCR
27
  def ocr(input_file, lang='fas'): # 'fas': Persian language (Farsi)
28
  extracted_text = ""
29
- if isinstance(input_file, Image.Image): # If the input is an image
30
- text = pytesseract.image_to_string(input_file, lang=lang)
31
- extracted_text = text
32
 
33
  return extracted_text
34
 
@@ -82,9 +82,16 @@ def ocr_with_easy(img):
82
  Generate OCR
83
  """
84
 
85
- def process(input_type, file, lang):
86
 
87
- # image = Image.open(file.name)
 
 
 
 
 
 
 
88
  image = file
89
  extracted_text = ocr(image, lang)
90
  return extracted_text
 
26
  # Function to perform OCR
27
  def ocr(input_file, lang='fas'): # 'fas': Persian language (Farsi)
28
  extracted_text = ""
29
+ # if isinstance(input_file, Image.Image): # If the input is an image
30
+ text = pytesseract.image_to_string(input_file, lang=lang)
31
+ extracted_text = text
32
 
33
  return extracted_text
34
 
 
82
  Generate OCR
83
  """
84
 
85
+ def process(input_type, gr_img, lang):
86
 
87
+ if isinstance(gr_img, np.ndarray):
88
+ # Create a temporary file to save the image
89
+ with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp_file:
90
+ temp_path = temp_file.name
91
+ # Save the NumPy array as an image file
92
+ Image.fromarray(gr_img).save(temp_path)
93
+
94
+ image = Image.open(temp_path)
95
  image = file
96
  extracted_text = ocr(image, lang)
97
  return extracted_text