diff options
Diffstat (limited to '')
-rw-r--r-- | g4f/gui/__init__.py | 10 | ||||
-rw-r--r-- | g4f/gui/run.py | 8 | ||||
-rw-r--r-- | g4f/gui/server/internet.py | 12 |
3 files changed, 19 insertions, 11 deletions
diff --git a/g4f/gui/__init__.py b/g4f/gui/__init__.py index a8000e71..d2dfbbc5 100644 --- a/g4f/gui/__init__.py +++ b/g4f/gui/__init__.py @@ -1,6 +1,10 @@ -from .server.app import app -from .server.website import Website -from .server.backend import Backend_Api +try: + from .server.app import app + from .server.website import Website + from .server.backend import Backend_Api +except ImportError: + from g4f.errors import MissingRequirementsError + raise MissingRequirementsError('Install "flask" and "werkzeug" package for gui') def run_gui(host: str = '0.0.0.0', port: int = 80, debug: bool = False) -> None: config = { diff --git a/g4f/gui/run.py b/g4f/gui/run.py index 7ff769fd..6b7d423f 100644 --- a/g4f/gui/run.py +++ b/g4f/gui/run.py @@ -1,8 +1,5 @@ from argparse import ArgumentParser -from g4f.gui import run_gui - - def gui_parser(): parser = ArgumentParser(description="Run the GUI") parser.add_argument("-host", type=str, default="0.0.0.0", help="hostname") @@ -10,15 +7,14 @@ def gui_parser(): parser.add_argument("-debug", action="store_true", help="debug mode") return parser - def run_gui_args(args): + from g4f.gui import run_gui host = args.host port = args.port debug = args.debug run_gui(host, port, debug) - if __name__ == "__main__": parser = gui_parser() args = parser.parse_args() - run_gui_args(args) + run_gui_args(args)
\ No newline at end of file diff --git a/g4f/gui/server/internet.py b/g4f/gui/server/internet.py index 6c2e3a89..a6bfc885 100644 --- a/g4f/gui/server/internet.py +++ b/g4f/gui/server/internet.py @@ -1,8 +1,14 @@ from __future__ import annotations -from bs4 import BeautifulSoup from aiohttp import ClientSession, ClientTimeout -from duckduckgo_search import DDGS +try: + from duckduckgo_search import DDGS + from bs4 import BeautifulSoup + has_requirements = True +except ImportError: + has_requirements = False +from ...errors import MissingRequirementsError + import asyncio class SearchResults(): @@ -88,6 +94,8 @@ async def fetch_and_scrape(session: ClientSession, url: str, max_words: int = No return async def search(query: str, n_results: int = 5, max_words: int = 2500, add_text: bool = True) -> SearchResults: + if not has_requirements: + raise MissingRequirementsError('Install "duckduckgo-search" and "beautifulsoup4" package') with DDGS() as ddgs: results = [] for result in ddgs.text( |