alekn commited on
Commit
86b607f
·
verified ·
1 Parent(s): a26ec86

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +22 -0
tools.py CHANGED
@@ -1,4 +1,6 @@
1
  import cmath
 
 
2
  from langchain_core.tools import tool
3
  from langchain_community.document_loaders import WikipediaLoader
4
 
@@ -98,8 +100,28 @@ def wiki_search(query: str) -> str:
98
  )
99
  return {"wiki_results": formatted_search_docs}
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  alltools = [
102
  wiki_search,
 
103
  multiply,
104
  add,
105
  subtract,
 
1
  import cmath
2
+ import pytesseract
3
+ from PIL import Image
4
  from langchain_core.tools import tool
5
  from langchain_community.document_loaders import WikipediaLoader
6
 
 
100
  )
101
  return {"wiki_results": formatted_search_docs}
102
 
103
+ ## OCR
104
+ @tool
105
+ def get_text_from_image(image_path: str) -> str:
106
+ """
107
+ Extract text from an image using OCR pytesseract.
108
+ Args:
109
+ image_path (str): the path to the image file.
110
+ """
111
+ try:
112
+ # Open the image
113
+ image = Image.open(image_path)
114
+ # Extract text from the image
115
+ text = pytesseract.image_to_string(image)
116
+ return f"Extracted text from image:\n\n{text}"
117
+ except ModuleNotFoundError as e:
118
+ return f'There is not module installed: {str(e)}'
119
+ except Exception as e:
120
+ return f"Error extracting text from image: {str(e)}"
121
+
122
  alltools = [
123
  wiki_search,
124
+ get_text_from_image,
125
  multiply,
126
  add,
127
  subtract,