Spaces:
Build error
Build error
Romain Lembo
commited on
Commit
·
f6453f6
1
Parent(s):
b48e08c
Add extract_text_from_image tool and update requirements
Browse files- agent.py +2 -0
- requirements.txt +2 -1
- tools/extract_text_from_image.py +21 -0
agent.py
CHANGED
|
@@ -28,6 +28,7 @@ from tools.square_root import square_root
|
|
| 28 |
from tools.execute_code_multilang import execute_code_multilang
|
| 29 |
from tools.save_read_file import save_read_file
|
| 30 |
from tools.download_file import download_file
|
|
|
|
| 31 |
# from tools.audio_transcription import audio_transcription
|
| 32 |
|
| 33 |
load_dotenv()
|
|
@@ -71,6 +72,7 @@ tools = [
|
|
| 71 |
square_root,
|
| 72 |
save_read_file,
|
| 73 |
download_file,
|
|
|
|
| 74 |
# audio_transcription,
|
| 75 |
]
|
| 76 |
|
|
|
|
| 28 |
from tools.execute_code_multilang import execute_code_multilang
|
| 29 |
from tools.save_read_file import save_read_file
|
| 30 |
from tools.download_file import download_file
|
| 31 |
+
from tools.extract_text_from_image import extract_text_from_image
|
| 32 |
# from tools.audio_transcription import audio_transcription
|
| 33 |
|
| 34 |
load_dotenv()
|
|
|
|
| 72 |
square_root,
|
| 73 |
save_read_file,
|
| 74 |
download_file,
|
| 75 |
+
extract_text_from_image,
|
| 76 |
# audio_transcription,
|
| 77 |
]
|
| 78 |
|
requirements.txt
CHANGED
|
@@ -21,4 +21,5 @@ pymupdf
|
|
| 21 |
wikipedia
|
| 22 |
pgvector
|
| 23 |
python-dotenv
|
| 24 |
-
matplotlib
|
|
|
|
|
|
| 21 |
wikipedia
|
| 22 |
pgvector
|
| 23 |
python-dotenv
|
| 24 |
+
matplotlib
|
| 25 |
+
pytesseract
|
tools/extract_text_from_image.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytesseract
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from langchain_core.tools import tool
|
| 4 |
+
|
| 5 |
+
@tool
|
| 6 |
+
def extract_text_from_image(image_path: str) -> str:
|
| 7 |
+
"""
|
| 8 |
+
Extract text from an image in using the pytesseract library.
|
| 9 |
+
Args:
|
| 10 |
+
image_path (str): the path to the image file.
|
| 11 |
+
"""
|
| 12 |
+
try:
|
| 13 |
+
# Open the image
|
| 14 |
+
image = Image.open(image_path)
|
| 15 |
+
|
| 16 |
+
# Extract text from the image
|
| 17 |
+
text = pytesseract.image_to_string(image)
|
| 18 |
+
|
| 19 |
+
return f"Extracted text from image:\n\n{text}"
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return f"Error extracting text from image: {str(e)}"
|