Skip to content

Commit

Permalink
clean refactor pre changes for using llm for nlp
Browse files Browse the repository at this point in the history
  • Loading branch information
rodfer0x80 committed May 24, 2024
1 parent 50d84b7 commit 0351b3f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
7 changes: 4 additions & 3 deletions llmpeg/capabilities/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .audio.audio_input import AudioInput
from .audio.audio_output import AudioOutput
from .networking.browser.webdriver.driver import Driver
from .networking.browser.webdriver.default_chrome_driver import DefaultChromeDriver
from .networking.networking import Networking
from .network.browser.webdriver.driver import Driver
from .network.browser.webdriver.default_chrome_driver import DefaultChromeDriver
from .network.browser.browser import Browser
from .network.network import Network
2 changes: 1 addition & 1 deletion llmpeg/capabilities/network/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .networking import Networking
from .network import Network
14 changes: 1 addition & 13 deletions llmpeg/capabilities/network/browser/browser.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from pathlib import Path
from dataclasses import dataclass
from typing import Union

from llmpeg.capabilities.networking.browser.webdriver import DefaultChromeDriver
from llmpeg.capabilities.networking import Networking
from llmpeg.capabilities.network.browser.webdriver import DefaultChromeDriver


@dataclass
Expand All @@ -14,10 +12,6 @@ def __post_init__(self):
self.cache_dir = self.cache_dir / 'browser'
Path.mkdir(self.cache_dir, exist_ok=True)
self.driver = DefaultChromeDriver(cache_dir=self.cache_dir, driver_flags={'headless': True, 'incognito': False})
self.networking = Networking()

def scrape(self, url: str) -> tuple[str, Union[str, None]]:
return self.networking.scrape(url)

# TODO: need to hide browser while doing this but headless is only screenshoting all the page on x11

Expand All @@ -30,9 +24,3 @@ def save_screenshot(self, url: str) -> str:
ss_path = self.driver.save_screenshot(url)
self.driver.close()
return ss_path

def scrape_url(self, url: str) -> tuple[Union[str, None], Union[str, None]]:
text_content, err = self.networking.scrape(url)
if err:
raise Exception(err)
return text_content
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from selenium.common.exceptions import TimeoutException as WebDriverTimeoutException
from selenium.webdriver.support import expected_conditions as EC

from llmpeg.capabilities.networking.browser.webdriver import Driver
from llmpeg.capabilities.network.browser.webdriver import Driver
from llmpeg.utils import CurrentDate, ScreenSize


Expand Down
6 changes: 6 additions & 0 deletions llmpeg/capabilities/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def scrape(self, url: str) -> tuple[str, Union[str, None]]:
except requests.RequestException as e:
return '', Error(e)

def scrape_url(self, url: str) -> tuple[Union[str, None], Union[str, None]]:
text_content, err = self.scrape(url)
if err:
raise Exception(err)
return text_content

def find_audio(self, query: str) -> tuple[Union[str, None], Union[str, None]]:
try:
# NOTE: ffmpeg is required for this to work
Expand Down

0 comments on commit 0351b3f

Please sign in to comment.