abinash73 commited on
Commit
35e4ed7
·
verified ·
1 Parent(s): 593638f

Fixed Image extraction

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -17,12 +17,26 @@ def extract_text_from_image(image):
17
 
18
  result = ocr.ocr(image)
19
 
 
 
 
 
20
  # Extract text with coordinates
21
  text_blocks = []
22
  for line in result[0]:
 
 
 
23
  bbox = line[0]
24
- text = line[1][0]
25
- confidence = line[1][1]
 
 
 
 
 
 
 
26
 
27
  # Calculate center point for positioning
28
  y_center = (bbox[0][1] + bbox[2][1]) / 2
@@ -346,6 +360,6 @@ if __name__ == "__main__":
346
  demo.launch(
347
  server_name="0.0.0.0",
348
  server_port=7860,
349
- share=False,
350
  show_api=True
351
  )
 
17
 
18
  result = ocr.ocr(image)
19
 
20
+ # Check if result is valid
21
+ if not result or not result[0]:
22
+ return []
23
+
24
  # Extract text with coordinates
25
  text_blocks = []
26
  for line in result[0]:
27
+ if not line or len(line) < 2:
28
+ continue
29
+
30
  bbox = line[0]
31
+ text_info = line[1]
32
+
33
+ # Handle different formats
34
+ if isinstance(text_info, tuple) or isinstance(text_info, list):
35
+ text = text_info[0]
36
+ confidence = text_info[1] if len(text_info) > 1 else 0.0
37
+ else:
38
+ text = str(text_info)
39
+ confidence = 0.0
40
 
41
  # Calculate center point for positioning
42
  y_center = (bbox[0][1] + bbox[2][1]) / 2
 
360
  demo.launch(
361
  server_name="0.0.0.0",
362
  server_port=7860,
363
+ share=True,
364
  show_api=True
365
  )