Sabari231024 commited on
Commit
ed1f536
·
1 Parent(s): 8d38173

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -7,6 +7,8 @@ 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 +39,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)
@@ -59,4 +72,4 @@ def operator(image_array, value, lang):
59
 
60
  # Create Gradio interface
61
  iface = gr.Interface(fn=operator, inputs=["image", "text", "text"], outputs="audio")
62
- iface.launch(share=True)
 
7
  import cv2
8
  import numpy as np
9
  import tempfile
10
+ import base64
11
+ from io import BytesIO
12
 
13
  def trans(text, lang='ta'):
14
  translator = Translator()
 
39
  return audio_file
40
 
41
  def ocr_detection(image_array, lang):
 
42
  image = Image.fromarray(image_array)
43
 
44
+ buffered = BytesIO()
45
+ image.save(buffered, format="PNG")
46
+ image_base64 = base64.b64encode(buffered.getvalue()).decode()
47
+
48
+ response = requests.post("https://pragnakalp-ocr-image-to-text.hf.space/run/predict", json={
49
+ "data": [
50
+ "PaddleOCR",
51
+ f"data:image/png;base64,{image_base64}",
52
+ ]
53
+ }).json()
54
+
55
+ data = response.get("data", [])
56
+
57
+ text = " ".join(data)
58
+ audio_file = trans(text, lang)
59
+
60
  return audio_file
61
 
62
+
63
  def operator(image_array, value, lang):
64
  if value == "1":
65
  audio_file = object_recognition(image_array, lang)
 
72
 
73
  # Create Gradio interface
74
  iface = gr.Interface(fn=operator, inputs=["image", "text", "text"], outputs="audio")
75
+ iface.launch(share=True)