Skip to content

Python scraper based on AI

refactoring of examples folder

VinciGit00a28ca993de64
diff --git a/examples/ScrapeGraphAI_generated_graph b/examples/ScrapeGraphAI_generated_graph
new file mode 100644
index 00000000..acc3232c
--- /dev/null
+++ b/examples/ScrapeGraphAI_generated_graph
@@ -0,0 +1,19 @@
+// ScrapeGraphAI Generated Graph
+digraph {
+ node [color=lightblue2 style=filled]
+ FetchHTMLNode [shape=doublecircle]
+ GetProbableTagsNode
+ ParseNode
+ RAGNode
+ GenerateAnswerNode
+ ConditionalNode
+ ImageToTextNode
+ TextToSpeechNode
+ FetchHTMLNode -> GetProbableTagsNode
+ GetProbableTagsNode -> ParseNode
+ ParseNode -> RAGNode
+ RAGNode -> GenerateAnswerNode
+ RAGNode -> ConditionalNode
+ ConditionalNode -> ImageToTextNode
+ ConditionalNode -> TextToSpeechNode
+}
diff --git a/examples/graph_examples/custom_graph_gemini.py b/examples/custom_graph_gemini.py
similarity index 100%
rename from examples/graph_examples/custom_graph_gemini.py
rename to examples/custom_graph_gemini.py
diff --git a/examples/graph_examples/custom_graph_openai.py b/examples/custom_graph_openai.py
similarity index 100%
rename from examples/graph_examples/custom_graph_openai.py
rename to examples/custom_graph_openai.py
diff --git a/examples/graph_examples/graph_builder_example.py b/examples/graph_builder_example.py
similarity index 100%
rename from examples/graph_examples/graph_builder_example.py
rename to examples/graph_builder_example.py
diff --git a/examples/graph_examples/graph_evaluation_example.py b/examples/graph_evaluation_example.py
similarity index 100%
rename from examples/graph_examples/graph_evaluation_example.py
rename to examples/graph_evaluation_example.py
diff --git a/examples/graph_examples/plain_html_example.txt b/examples/plain_html_example.txt
similarity index 100%
rename from examples/graph_examples/plain_html_example.txt
rename to examples/plain_html_example.txt
diff --git a/examples/graph_examples/result.csv b/examples/result.csv
similarity index 100%
rename from examples/graph_examples/result.csv
rename to examples/result.csv
diff --git a/examples/graph_examples/result.json b/examples/result.json
similarity index 100%
rename from examples/graph_examples/result.json
rename to examples/result.json
diff --git a/examples/graph_examples/scrape_plain_text.py b/examples/scrape_plain_text.py
similarity index 100%
rename from examples/graph_examples/scrape_plain_text.py
rename to examples/scrape_plain_text.py
diff --git a/examples/graph_examples/smart_scraper_example.py b/examples/smart_scraper_example.py
similarity index 100%
rename from examples/graph_examples/smart_scraper_example.py
rename to examples/smart_scraper_example.py
diff --git a/examples/graph_examples/speech_graph_example.py b/examples/speech_graph_example.py
similarity index 100%
rename from examples/graph_examples/speech_graph_example.py
rename to examples/speech_graph_example.py
diff --git a/examples/utils/convert_to_csv.example.py b/examples/utils/convert_to_csv.example.py
deleted file mode 100644
index 73f1efa9..00000000
--- a/examples/utils/convert_to_csv.example.py
+++ /dev/null
@@ -1,39 +0,0 @@
-"""
-Teest for convert_to_csv
-"""
-import os
-from scrapegraphai.utils.convert_to_csv import convert_to_csv
-
-
-def main():
- """
- Example usage of the convert_to_csv function.
- """
- # Example data
- data = {
- 'Name': ['John', 'Alice', 'Bob'],
- 'Age': [30, 25, 35],
- 'City': ['New York', 'San Francisco', 'Seattle']
- }
-
- # Example filename and position
- filename = "example_data"
- position = "./output"
-
- try:
- # Convert data to CSV and save
- convert_to_csv(data, filename, position)
- print(
- f"Data saved successfully to {os.path.join(position, filename)}.csv")
- except ValueError as ve:
- print(f"ValueError: {ve}")
- except FileNotFoundError as fnfe:
- print(f"FileNotFoundError: {fnfe}")
- except PermissionError as pe:
- print(f"PermissionError: {pe}")
- except Exception as e:
- print(f"An unexpected error occurred: {e}")
-
-
-if __name__ == "__main__":
- main()
diff --git a/examples/utils/convert_to_json_example.py b/examples/utils/convert_to_json_example.py
deleted file mode 100644
index 3859107c..00000000
--- a/examples/utils/convert_to_json_example.py
+++ /dev/null
@@ -1,28 +0,0 @@
-"""
-Example of using convert_to_json function to save data in JSON format.
-"""
-import os
-from scrapegraphai.utils.convert_to_json import convert_to_json
-
-# Data to save in JSON format
-data_to_save = {
- "name": "John Doe",
- "age": 30,
- "city": "New York"
-}
-
-FILENAME = "example_data"
-DIRECTORY = "data_output"
-
-try:
- convert_to_json(data_to_save, FILENAME, DIRECTORY)
- print(
- f"Data has been successfully saved to {os.path.join(DIRECTORY, FILENAME)}.json")
-except ValueError as value_error:
- print(value_error)
-except FileNotFoundError as file_not_found_error:
- print(file_not_found_error)
-except PermissionError as permission_error:
- print(permission_error)
-except Exception as exception:
- print(f"An error occurred: {exception}")
diff --git a/examples/utils/remover_example.py b/examples/utils/remover_example.py
deleted file mode 100644
index dbdca118..00000000
--- a/examples/utils/remover_example.py
+++ /dev/null
@@ -1,21 +0,0 @@
-"""
-Example of the remover method
-"""
-from scrapegraphai.utils.remover import remover
-
-HTML_CONTENT = """
-<html>
-<head>
- <title>Test Page</title>
-</head>
-<body>
- <h1>This is a Test</h1>
- <p>Hello, World!</p>
- <script>alert("This is a script");</script>
-</body>
-</html>
-"""
-
-parsed_content = remover(HTML_CONTENT)
-
-print(parsed_content)
diff --git a/examples/utils/save_audio_from_bytes_example.py b/examples/utils/save_audio_from_bytes_example.py
deleted file mode 100644
index c915aad6..00000000
--- a/examples/utils/save_audio_from_bytes_example.py
+++ /dev/null
@@ -1,10 +0,0 @@
-"""
-Example for th e file save_audio_from_bytes
-"""
-from scrapegraphai.utils.save_audio_from_bytes import save_audio_from_bytes
-
-BYTE_RESPONSE = b'\x12\x34\x56\x78\x90'
-
-OUTPUT_PATH = "generated_speech.wav"
-
-save_audio_from_bytes(BYTE_RESPONSE, OUTPUT_PATH)
diff --git a/examples/utils/token_calculator_example.py b/examples/utils/token_calculator_example.py
deleted file mode 100644
index 68ff25d2..00000000
--- a/examples/utils/token_calculator_example.py
+++ /dev/null
@@ -1,14 +0,0 @@
-"""
-Example for calclating the tokenizer
-"""
-from scrapegraphai.utils.token_calculator import truncate_text_tokens
-
-INPUT_TEXT = "http://nba.com"
-
-MODEL_NAME = "gpt-3.5-turbo"
-ENCODING_NAME = "EMBEDDING_ENCODING"
-
-tokenized_chunks = truncate_text_tokens(INPUT_TEXT, MODEL_NAME, ENCODING_NAME)
-
-for i, chunk in enumerate(tokenized_chunks):
- print(f"Chunk {i+1}: {chunk}")
diff --git a/examples/utils/vision_speech_example.py b/examples/utils/vision_speech_example.py
deleted file mode 100644
index 5c90dc25..00000000
--- a/examples/utils/vision_speech_example.py
+++ /dev/null
@@ -1,46 +0,0 @@
-"""
-Basic example of scraping pipeline using SmartScraper
-"""
-
-import os
-from dotenv import load_dotenv
-from scrapegraphai.models import OpenAIImageToText, OpenAITextToSpeech
-from scrapegraphai.utils import save_audio_from_bytes
-
-load_dotenv()
-openai_key = os.getenv("OPENAI_APIKEY")
-
-# Define the configuration for the graph
-config = {
- "itt_model": {
- "api_key": openai_key,
- "model": "gpt-4-vision-preview",
- },
- "tts_model": {
- "api_key": openai_key,
- "model": "tts-1",
- "voice": "alloy"
- },
-}
-
-itt_model = OpenAIImageToText(config["itt_model"])
-img_to_text_result = itt_model.run(
- "https://raw.githubusercontent.com/VinciGit00/Scrapegraph-ai/main/docs/assets/scrapegraphai_logo.png"
- )
-
-print(f"Image description: {img_to_text_result}")
-
-tts_model = OpenAITextToSpeech(config["tts_model"])
-
-audio = tts_model.run(
- img_to_text_result
- )
-
-# Save the audio to a file
-file_name = "image_description.mp3"
-curr_dir = os.path.dirname(os.path.realpath(__file__))
-output_path = os.path.join(curr_dir, file_name)
-
-save_audio_from_bytes(audio, output_path)
-
-print(f"Audio file saved to: {output_path}")
diff --git a/scrapegraphai/utils/test_node.py b/scrapegraphai/utils/test_node.py
deleted file mode 100644
index 4abf744c..00000000
--- a/scrapegraphai/utils/test_node.py
+++ /dev/null
@@ -1,58 +0,0 @@
-"""
-Module for making the tests
-"""
-import os
-from dotenv import load_dotenv
-from scrapegraphai.models import OpenAI
-from scrapegraphai.nodes import FetchNode, ParseNode, RAGNode, GenerateAnswerNode
-
-load_dotenv()
-
-# Define the configuration for the language model
-openai_key = os.getenv("OPENAI_APIKEY")
-
-llm_config = {
- "api_key": openai_key,
- "model_name": "gpt-3.5-turbo",
- "temperature": 0,
- "streaming": True
-}
-llm_model = OpenAI(llm_config)
-
-state = {
- "user_prompt": "List me all the projects",
- "url": "https://perinim.github.io/projects/",
-}
-
-fetch_node = FetchNode(
- input="url | local_dir",
- output=["doc"],
- node_name="fetch_html"
-)
-
-updated_state = fetch_node.execute(state)
-parse_node = ParseNode(
- input="doc",
- output=["parsed_doc"],
- node_name="parse_document"
-)
-
-updated_state = parse_node.execute(updated_state)
-
-rag_node = RAGNode(
- input="user_prompt & (parsed_doc | doc)",
- output=["relevant_chunks"],
- model_config={"llm_model": llm_model},
- node_name="rag_node"
-)
-
-updated_state = rag_node.execute(updated_state)
-
-generate_answer_node = GenerateAnswerNode(
- input="user_prompt & (relevant_chunks | parsed_doc | doc)",
- output=["answer"],
- model_config={"llm_model": llm_model},
- node_name="generate_answer"
-)
-
-print(generate_answer_node.execute(updated_state))