mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-07-01 21:00:48 +08:00
fix(ScreenshotScraper): impose dynamic imports
This commit is contained in:
parent
08afc9292e
commit
b8ef93738e
@ -5,7 +5,6 @@ import asyncio
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from PIL import Image, ImageGrab
|
from PIL import Image, ImageGrab
|
||||||
from playwright.async_api import async_playwright
|
from playwright.async_api import async_playwright
|
||||||
import cv2 as cv
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
@ -42,6 +41,12 @@ def select_area_with_opencv(image):
|
|||||||
A tuple containing the LEFT, TOP, RIGHT, and BOTTOM coordinates of the selected area.
|
A tuple containing the LEFT, TOP, RIGHT, and BOTTOM coordinates of the selected area.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
import cv2 as cv
|
||||||
|
except ImportError:
|
||||||
|
raise ImportError("The dependencies for screenshot scraping are not installed. Please install them using `pip install scrapegraphai[screenshot_scraper]`.")
|
||||||
|
|
||||||
|
|
||||||
fullscreen_screenshot = ImageGrab.grab()
|
fullscreen_screenshot = ImageGrab.grab()
|
||||||
dw, dh = fullscreen_screenshot.size
|
dw, dh = fullscreen_screenshot.size
|
||||||
|
|
||||||
@ -116,8 +121,12 @@ def select_area_with_ipywidget(image):
|
|||||||
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from ipywidgets import interact, IntSlider
|
try:
|
||||||
import ipywidgets as widgets
|
from ipywidgets import interact, IntSlider
|
||||||
|
import ipywidgets as widgets
|
||||||
|
except:
|
||||||
|
raise ImportError("The dependencies for screenshot scraping are not installed. Please install them using `pip install scrapegraphai[screenshot_scraper]`.")
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
img_array = np.array(image)
|
img_array = np.array(image)
|
||||||
|
|||||||
@ -1,24 +1,29 @@
|
|||||||
"""
|
"""
|
||||||
text_detection_module
|
text_detection_module
|
||||||
"""
|
"""
|
||||||
from surya.ocr import run_ocr
|
|
||||||
from surya.model.detection.model import (load_model as load_det_model,
|
|
||||||
load_processor as load_det_processor)
|
|
||||||
from surya.model.recognition.model import load_model as load_rec_model
|
|
||||||
from surya.model.recognition.processor import load_processor as load_rec_processor
|
|
||||||
|
|
||||||
|
|
||||||
def detect_text(image, languages: list = ["en"]):
|
def detect_text(image, languages: list = ["en"]):
|
||||||
"""
|
"""
|
||||||
Detects and extracts text from a given image.
|
Detects and extracts text from a given image.
|
||||||
Parameters:
|
Parameters:
|
||||||
image (PIL Image): The input image to extract text from.
|
image (PIL Image): The input image to extract text from.
|
||||||
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
|
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
|
||||||
Returns:
|
Returns:
|
||||||
str: The extracted text from the image.
|
str: The extracted text from the image.
|
||||||
Notes:
|
Notes:
|
||||||
Model weights will automatically download the first time you run this function.
|
Model weights will automatically download the first time you run this function.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
from surya.ocr import run_ocr
|
||||||
|
from surya.model.detection.model import (load_model as load_det_model,
|
||||||
|
load_processor as load_det_processor)
|
||||||
|
from surya.model.recognition.model import load_model as load_rec_model
|
||||||
|
from surya.model.recognition.processor import load_processor as load_rec_processor
|
||||||
|
except:
|
||||||
|
raise ImportError("The dependencies for screenshot scraping are not installed. Please install them using `pip install scrapegraphai[screenshot_scraper]`.")
|
||||||
|
|
||||||
|
|
||||||
langs = languages
|
langs = languages
|
||||||
det_processor, det_model = load_det_processor(), load_det_model()
|
det_processor, det_model = load_det_processor(), load_det_model()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user