|
1 | 1 | """
|
2 | 2 | text_detection_module
|
3 | 3 | """
|
4 |
| -from surya.ocr import run_ocr |
5 |
| -from surya.model.detection.model import (load_model as load_det_model, |
6 |
| - load_processor as load_det_processor) |
7 |
| -from surya.model.recognition.model import load_model as load_rec_model |
8 |
| -from surya.model.recognition.processor import load_processor as load_rec_processor |
9 | 4 |
|
10 | 5 |
|
11 | 6 | def detect_text(image, languages: list = ["en"]):
|
12 | 7 | """
|
13 |
| - Detects and extracts text from a given image. |
14 |
| - Parameters: |
15 |
| - image (PIL Image): The input image to extract text from. |
16 |
| - lahguages (list): A list of languages to detect text in. Defaults to ["en"]. List of languages can be found here: https://github.com/VikParuchuri/surya/blob/master/surya/languages.py |
17 |
| - Returns: |
18 |
| - str: The extracted text from the image. |
19 |
| - Notes: |
20 |
| - Model weights will automatically download the first time you run this function. |
21 |
| - """ |
| 8 | + Detects and extracts text from a given image. |
| 9 | + Parameters: |
| 10 | + image (PIL Image): The input image to extract text from. |
| 11 | + lahguages (list): A list of languages to detect text in. Defaults to ["en"]. List of languages can be found here: https://github.com/VikParuchuri/surya/blob/master/surya/languages.py |
| 12 | + Returns: |
| 13 | + str: The extracted text from the image. |
| 14 | + Notes: |
| 15 | + Model weights will automatically download the first time you run this function. |
| 16 | + """ |
| 17 | + |
| 18 | + try: |
| 19 | + from surya.ocr import run_ocr |
| 20 | + from surya.model.detection.model import (load_model as load_det_model, |
| 21 | + load_processor as load_det_processor) |
| 22 | + from surya.model.recognition.model import load_model as load_rec_model |
| 23 | + from surya.model.recognition.processor import load_processor as load_rec_processor |
| 24 | + except: |
| 25 | + raise ImportError("The dependencies for screenshot scraping are not installed. Please install them using `pip install scrapegraphai[screenshot_scraper]`.") |
| 26 | + |
22 | 27 |
|
23 | 28 | langs = languages
|
24 | 29 | det_processor, det_model = load_det_processor(), load_det_model()
|
|
0 commit comments