Sabari231024 commited on
Commit
c9b1147
·
1 Parent(s): 3c3aa88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -7,6 +7,7 @@ from googletrans import Translator
7
  import cv2
8
  import numpy as np
9
  import tempfile
 
10
 
11
  def trans(text, lang='ta'):
12
  translator = Translator()
@@ -37,16 +38,27 @@ def object_recognition(image_array, lang):
37
  return audio_file
38
 
39
  def ocr_detection(image_array, lang):
40
- # Convert the NumPy array to PIL Image
41
  image = Image.fromarray(image_array)
42
 
43
- client = Client("https://kneelesh48-tesseract-ocr.hf.space/")
44
- result = client.predict(image, "afr", api_name="/tesseract-ocr")
45
- print(result)
46
- text = "OCR detection result for the captured image."
47
- audio_file = trans(result, lang)
 
 
 
 
 
 
 
 
 
 
 
48
  return audio_file
49
 
 
50
  def operator(image_array, value, lang):
51
  if value == "1":
52
  audio_file = object_recognition(image_array, lang)
 
7
  import cv2
8
  import numpy as np
9
  import tempfile
10
+ import base64
11
 
12
  def trans(text, lang='ta'):
13
  translator = Translator()
 
38
  return audio_file
39
 
40
  def ocr_detection(image_array, lang):
 
41
  image = Image.fromarray(image_array)
42
 
43
+ buffered = BytesIO()
44
+ image.save(buffered, format="PNG")
45
+ image_base64 = base64.b64encode(buffered.getvalue()).decode()
46
+
47
+ response = requests.post("https://pragnakalp-ocr-image-to-text.hf.space/run/predict", json={
48
+ "data": [
49
+ "PaddleOCR",
50
+ f"data:image/png;base64,{image_base64}",
51
+ ]
52
+ }).json()
53
+
54
+ data = response.get("data", [])
55
+
56
+ text = " ".join(data)
57
+ audio_file = trans(text, lang)
58
+
59
  return audio_file
60
 
61
+
62
  def operator(image_array, value, lang):
63
  if value == "1":
64
  audio_file = object_recognition(image_array, lang)