naman1102 commited on
Commit
305d4ff
·
1 Parent(s): 37188c1

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +6 -9
tools.py CHANGED
@@ -3,7 +3,7 @@
3
  import pandas as pd
4
 
5
  from pathlib import Path
6
-
7
  import regex as re
8
  import time
9
  import os
@@ -32,6 +32,7 @@ def _download_file_for_task(task_id: str, ext: str) -> str:
32
  f.write(resp.content)
33
  return local_path
34
  except Exception:
 
35
  pass
36
 
37
  # If we get here, either 404 or download error
@@ -66,18 +67,14 @@ def ocr_image_tool(args: dict) -> str:
66
  with open(local_img, "rb") as f:
67
  image_bytes = f.read()
68
  except Exception as e:
69
- return {
70
- "ocr_path": None,
71
- "ocr_result": f"Error reading image file: {e}"
72
- }
73
 
74
  # 3) Prepare HF Inference headers
75
  hf_token = os.getenv("HF_TOKEN")
76
  if not hf_token:
77
- return {
78
- "ocr_path": None,
79
- "ocr_result": "Error: HUGGINGFACE_API_KEY not set in environment."
80
- }
81
 
82
  headers = {"Authorization": f"Bearer {hf_token}"}
83
 
 
3
  import pandas as pd
4
 
5
  from pathlib import Path
6
+ import requests
7
  import regex as re
8
  import time
9
  import os
 
32
  f.write(resp.content)
33
  return local_path
34
  except Exception:
35
+ print(f"Error downloading file from {url} to {local_path}")
36
  pass
37
 
38
  # If we get here, either 404 or download error
 
67
  with open(local_img, "rb") as f:
68
  image_bytes = f.read()
69
  except Exception as e:
70
+ return f"Error reading image file: {e}"
71
+
 
 
72
 
73
  # 3) Prepare HF Inference headers
74
  hf_token = os.getenv("HF_TOKEN")
75
  if not hf_token:
76
+ return "Error: HUGGINGFACE_API_KEY not set in environment."
77
+
 
 
78
 
79
  headers = {"Authorization": f"Bearer {hf_token}"}
80