Skip to content

Python scraper based on AI

implemented graphbuilder

PeriniM20db549d0889
diff --git a/examples/custom_graph.py b/examples/custom_graph_example.py
similarity index 100%
rename from examples/custom_graph.py
rename to examples/custom_graph_example.py
diff --git a/examples/schema_example.py b/examples/graph_builder_example.py
similarity index 73%
rename from examples/schema_example.py
rename to examples/graph_builder_example.py
index a29d270d..f006404e 100644
--- a/examples/schema_example.py
+++ b/examples/graph_builder_example.py
@@ -16,10 +16,15 @@ llm_config = {
}
# Example usage of GraphBuilder
-user_prompt = "I want to scrape all the links related to the cinema UCI and return me a JSON with the results."
+user_prompt = "Give me all the titles of the page"
graph_builder = GraphBuilder(user_prompt, llm_config)
graph_json = graph_builder.build_graph()
# Convert the resulting JSON to Graphviz format
graphviz_graph = graph_builder.convert_json_to_graphviz(graph_json)
-graphviz_graph.render('custom_graph', view=True)
+
+# save on current directory
+curr_dir = os.path.dirname(os.path.realpath(__file__))
+file_path = os.path.join(curr_dir, 'custom_graph')
+
+graphviz_graph.render(file_path, view=True)
diff --git a/examples/smart_scraper.py b/examples/smart_scraper_example.py
similarity index 100%
rename from examples/smart_scraper.py
rename to examples/smart_scraper_example.py
diff --git a/poetry.lock b/poetry.lock
index 56b10311..39061b9a 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -477,6 +477,22 @@ files = [
{file = "frozenlist-1.4.1.tar.gz", hash = "sha256:c037a86e8513059a2613aaba4d817bb90b9d9b6b69aace3ce9c877e8c8ed402b"},
]
+[[package]]
+name = "graphviz"
+version = "0.20.1"
+description = "Simple Python interface for Graphviz"
+optional = false
+python-versions = ">=3.7"
+files = [
+ {file = "graphviz-0.20.1-py3-none-any.whl", hash = "sha256:587c58a223b51611c0cf461132da386edd896a029524ca61a1462b880bf97977"},
+ {file = "graphviz-0.20.1.zip", hash = "sha256:8c58f14adaa3b947daf26c19bc1e98c4e0702cdc31cf99153e6f06904d492bf8"},
+]
+
+[package.extras]
+dev = ["flake8", "pep8-naming", "tox (>=3)", "twine", "wheel"]
+docs = ["sphinx (>=5)", "sphinx-autodoc-typehints", "sphinx-rtd-theme"]
+test = ["coverage", "mock (>=4)", "pytest (>=7)", "pytest-cov", "pytest-mock (>=3)"]
+
[[package]]
name = "greenlet"
version = "3.0.3"
@@ -1978,13 +1994,13 @@ files = [
[[package]]
name = "urllib3"
-version = "2.2.0"
+version = "2.2.1"
description = "HTTP library with thread-safe connection pooling, file post, and more."
optional = false
python-versions = ">=3.8"
files = [
- {file = "urllib3-2.2.0-py3-none-any.whl", hash = "sha256:ce3711610ddce217e6d113a2732fafad960a03fd0318c91faa79481e35c11224"},
- {file = "urllib3-2.2.0.tar.gz", hash = "sha256:051d961ad0c62a94e50ecf1af379c3aba230c66c710493493560c0c223c49f20"},
+ {file = "urllib3-2.2.1-py3-none-any.whl", hash = "sha256:450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d"},
+ {file = "urllib3-2.2.1.tar.gz", hash = "sha256:d0570876c61ab9e520d776c38acbbb5b05a776d3f9ff98a5c8fd5162a444cf19"},
]
[package.extras]
@@ -2114,4 +2130,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p
[metadata]
lock-version = "2.0"
python-versions = "^3.9"
-content-hash = "45611b95eca49cd9cf82691a86090436df7fafaa86e55f27f64c273c73e738dc"
+content-hash = "330c57979a84fd249f57565ea4b9b2416a3946aea12af06a72be84f3b19737e1"
diff --git a/pyproject.toml b/pyproject.toml
index 97e2f405..ede3db01 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -31,6 +31,7 @@ pandas = "2.0.3"
python-dotenv = "1.0.1"
tiktoken = {version = ">=0.5.2,<0.6.0"}
tqdm = "4.66.1"
+graphviz = "0.20.1"
[tool.poetry.dev-dependencies]
pytest = "8.0.0"
diff --git a/scrapegraphai/builders/graph_builder.py b/scrapegraphai/builders/graph_builder.py
index 19e07403..087a7f26 100644
--- a/scrapegraphai/builders/graph_builder.py
+++ b/scrapegraphai/builders/graph_builder.py
@@ -2,7 +2,6 @@ from langchain_core.prompts import ChatPromptTemplate
from langchain.chains import create_extraction_chain
from langchain_openai import ChatOpenAI
from scrapegraphai.utils import nodes_metadata, graph_schema
-import graphviz
class GraphBuilder:
"""
@@ -114,7 +113,8 @@ class GraphBuilder:
Returns:
graphviz.Digraph: A Graphviz object representing the graph configuration.
"""
-
+ import graphviz
+
graph = graphviz.Digraph(comment='ScrapeGraphAI Generated Graph', format=format,
node_attr={'color': 'lightblue2', 'style': 'filled'})