krishbaresha commited on
Commit
026399a
·
verified ·
1 Parent(s): dbc37da

Update ocr_utils.py

Browse files
Files changed (1) hide show
  1. ocr_utils.py +14 -7
ocr_utils.py CHANGED
@@ -1,12 +1,19 @@
1
  import requests
2
 
3
  def extract_text_from_image(file_path, api_key):
4
- url = "https://api.ocr.space/parse/image"
5
- with open(file_path, "rb") as f:
6
- r = requests.post(url, files={"file": f}, data={"apikey": api_key})
7
- result = r.json()
8
  try:
9
- text = result['ParsedResults'][0]['ParsedText']
10
- return text
11
- except:
 
 
 
 
 
 
 
 
12
  return ""
 
1
  import requests
2
 
3
  def extract_text_from_image(file_path, api_key):
4
+ """
5
+ Extract text from image using OCR.space API
6
+ """
 
7
  try:
8
+ url = "https://api.ocr.space/parse/image"
9
+ with open(file_path, "rb") as f:
10
+ r = requests.post(
11
+ url,
12
+ files={"file": f},
13
+ data={"apikey": api_key, "language": "eng"}
14
+ )
15
+ result = r.json()
16
+ return result['ParsedResults'][0]['ParsedText']
17
+ except Exception as e:
18
+ print(f"OCR extraction error: {e}")
19
  return ""