Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
add new examples
Marco Vinciguerra3b90ebd9a810
diff --git a/examples/anthropic/.env.example b/examples/anthropic/.env.examplenew file mode 100644index 00000000..2789e380--- /dev/null+++ b/examples/anthropic/.env.example@@ -0,0 +1 @@+ANTHROPIC_API_KEY="YOUR ANTHROPIC API KEY"\ No newline at end of filediff --git a/examples/anthropic/csv_scraper_haiku.py b/examples/anthropic/csv_scraper_haiku.pynew file mode 100644index 00000000..2e0ebe81--- /dev/null+++ b/examples/anthropic/csv_scraper_haiku.py@@ -0,0 +1,62 @@+"""+Basic example of scraping pipeline using CSVScraperGraph from CSV documents+"""++import os+from dotenv import load_dotenv+import pandas as pd+from scrapegraphai.graphs import CSVScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++load_dotenv()++# ************************************************+# Read the CSV file+# ************************************************++FILE_NAME = "inputs/username.csv"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++text = pd.read_csv(file_path)++# ************************************************+# Define the configuration for the graph+# ************************************************++# required environment variables in .env+# HUGGINGFACEHUB_API_TOKEN+# ANTHROPIC_API_KEY+load_dotenv()++graph_config = {+ "llm": {+ "api_key": os.getenv("ANTHROPIC_API_KEY"),+ "model": "claude-3-haiku-20240307",+ "max_tokens": 4000+ },+}++# ************************************************+# Create the CSVScraperGraph instance and run it+# ************************************************++csv_scraper_graph = CSVScraperGraph(+ prompt="List me all the last names",+ source=str(text), # Pass the content of the file, not the file object+ config=graph_config+)++result = csv_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = csv_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/anthropic/custom_graph_haiku.py b/examples/anthropic/custom_graph_haiku.pynew file mode 100644index 00000000..9580e88a--- /dev/null+++ b/examples/anthropic/custom_graph_haiku.py@@ -0,0 +1,110 @@+"""+Example of custom graph using existing nodes+"""++import os+from dotenv import load_dotenv++from langchain_openai import OpenAIEmbeddings+from scrapegraphai.models import OpenAI+from scrapegraphai.graphs import BaseGraph+from scrapegraphai.nodes import FetchNode, ParseNode, RAGNode, GenerateAnswerNode, RobotsNode+load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "api_key": os.getenv("ANTHROPIC_API_KEY"),+ "model": "claude-3-haiku-20240307",+ "max_tokens": 4000+ },+}++# ************************************************+# Define the graph nodes+# ************************************************++llm_model = OpenAI(graph_config["llm"])+embedder = OpenAIEmbeddings(api_key=llm_model.openai_api_key)++# define the nodes for the graph+robot_node = RobotsNode(+ input="url",+ output=["is_scrapable"],+ node_config={+ "llm_model": llm_model,+ "force_scraping": True,+ "verbose": True,+ }+)++fetch_node = FetchNode(+ input="url | local_dir",+ output=["doc", "link_urls", "img_urls"],+ node_config={+ "verbose": True,+ "headless": True,+ }+)+parse_node = ParseNode(+ input="doc",+ output=["parsed_doc"],+ node_config={+ "chunk_size": 4096,+ "verbose": True,+ }+)+rag_node = RAGNode(+ input="user_prompt & (parsed_doc | doc)",+ output=["relevant_chunks"],+ node_config={+ "llm_model": llm_model,+ "embedder_model": embedder,+ "verbose": True,+ }+)+generate_answer_node = GenerateAnswerNode(+ input="user_prompt & (relevant_chunks | parsed_doc | doc)",+ output=["answer"],+ node_config={+ "llm_model": llm_model,+ "verbose": True,+ }+)++# ************************************************+# Create the graph by defining the connections+# ************************************************++graph = BaseGraph(+ nodes=[+ robot_node,+ fetch_node,+ parse_node,+ rag_node,+ generate_answer_node,+ ],+ edges=[+ (robot_node, fetch_node),+ (fetch_node, parse_node),+ (parse_node, rag_node),+ (rag_node, generate_answer_node)+ ],+ entry_point=robot_node+)++# ************************************************+# Execute the graph+# ************************************************++result, execution_info = graph.execute({+ "user_prompt": "Describe the content",+ "url": "https://example.com/"+})++# get the answer from the result+result = result.get("answer", "No answer found.")+print(result)diff --git a/examples/anthropic/inputs/books.xml b/examples/anthropic/inputs/books.xmlnew file mode 100644index 00000000..e3d1fe87--- /dev/null+++ b/examples/anthropic/inputs/books.xml@@ -0,0 +1,120 @@+<?xml version="1.0"?>+<catalog>+ <book id="bk101">+ <author>Gambardella, Matthew</author>+ <title>XML Developer's Guide</title>+ <genre>Computer</genre>+ <price>44.95</price>+ <publish_date>2000-10-01</publish_date>+ <description>An in-depth look at creating applications+ with XML.</description>+ </book>+ <book id="bk102">+ <author>Ralls, Kim</author>+ <title>Midnight Rain</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2000-12-16</publish_date>+ <description>A former architect battles corporate zombies,+ an evil sorceress, and her own childhood to become queen+ of the world.</description>+ </book>+ <book id="bk103">+ <author>Corets, Eva</author>+ <title>Maeve Ascendant</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2000-11-17</publish_date>+ <description>After the collapse of a nanotechnology+ society in England, the young survivors lay the+ foundation for a new society.</description>+ </book>+ <book id="bk104">+ <author>Corets, Eva</author>+ <title>Oberon's Legacy</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2001-03-10</publish_date>+ <description>In post-apocalypse England, the mysterious+ agent known only as Oberon helps to create a new life+ for the inhabitants of London. Sequel to Maeve+ Ascendant.</description>+ </book>+ <book id="bk105">+ <author>Corets, Eva</author>+ <title>The Sundered Grail</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2001-09-10</publish_date>+ <description>The two daughters of Maeve, half-sisters,+ battle one another for control of England. Sequel to+ Oberon's Legacy.</description>+ </book>+ <book id="bk106">+ <author>Randall, Cynthia</author>+ <title>Lover Birds</title>+ <genre>Romance</genre>+ <price>4.95</price>+ <publish_date>2000-09-02</publish_date>+ <description>When Carla meets Paul at an ornithology+ conference, tempers fly as feathers get ruffled.</description>+ </book>+ <book id="bk107">+ <author>Thurman, Paula</author>+ <title>Splish Splash</title>+ <genre>Romance</genre>+ <price>4.95</price>+ <publish_date>2000-11-02</publish_date>+ <description>A deep sea diver finds true love twenty+ thousand leagues beneath the sea.</description>+ </book>+ <book id="bk108">+ <author>Knorr, Stefan</author>+ <title>Creepy Crawlies</title>+ <genre>Horror</genre>+ <price>4.95</price>+ <publish_date>2000-12-06</publish_date>+ <description>An anthology of horror stories about roaches,+ centipedes, scorpions and other insects.</description>+ </book>+ <book id="bk109">+ <author>Kress, Peter</author>+ <title>Paradox Lost</title>+ <genre>Science Fiction</genre>+ <price>6.95</price>+ <publish_date>2000-11-02</publish_date>+ <description>After an inadvertant trip through a Heisenberg+ Uncertainty Device, James Salway discovers the problems+ of being quantum.</description>+ </book>+ <book id="bk110">+ <author>O'Brien, Tim</author>+ <title>Microsoft .NET: The Programming Bible</title>+ <genre>Computer</genre>+ <price>36.95</price>+ <publish_date>2000-12-09</publish_date>+ <description>Microsoft's .NET initiative is explored in+ detail in this deep programmer's reference.</description>+ </book>+ <book id="bk111">+ <author>O'Brien, Tim</author>+ <title>MSXML3: A Comprehensive Guide</title>+ <genre>Computer</genre>+ <price>36.95</price>+ <publish_date>2000-12-01</publish_date>+ <description>The Microsoft MSXML3 parser is covered in+ detail, with attention to XML DOM interfaces, XSLT processing,+ SAX and more.</description>+ </book>+ <book id="bk112">+ <author>Galos, Mike</author>+ <title>Visual Studio 7: A Comprehensive Guide</title>+ <genre>Computer</genre>+ <price>49.95</price>+ <publish_date>2001-04-16</publish_date>+ <description>Microsoft Visual Studio 7 is explored in depth,+ looking at how Visual Basic, Visual C++, C#, and ASP+ are+ integrated into a comprehensive development+ environment.</description>+ </book>+</catalog>\ No newline at end of filediff --git a/examples/anthropic/inputs/example.json b/examples/anthropic/inputs/example.jsonnew file mode 100644index 00000000..2263184c--- /dev/null+++ b/examples/anthropic/inputs/example.json@@ -0,0 +1,182 @@+{+ "kind":"youtube#searchListResponse",+ "etag":"q4ibjmYp1KA3RqMF4jFLl6PBwOg",+ "nextPageToken":"CAUQAA",+ "regionCode":"NL",+ "pageInfo":{+ "totalResults":1000000,+ "resultsPerPage":5+ },+ "items":[+ {+ "kind":"youtube#searchResult",+ "etag":"QCsHBifbaernVCbLv8Cu6rAeaDQ",+ "id":{+ "kind":"youtube#video",+ "videoId":"TvWDY4Mm5GM"+ },+ "snippet":{+ "publishedAt":"2023-07-24T14:15:01Z",+ "channelId":"UCwozCpFp9g9x0wAzuFh0hwQ",+ "title":"3 Football Clubs Kylian Mbappe Should Avoid Signing ✍️❌⚽️ #football #mbappe #shorts",+ "description":"",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"FC Motivate",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T14:15:01Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"0NG5QHdtIQM_V-DBJDEf-jK_Y9k",+ "id":{+ "kind":"youtube#video",+ "videoId":"aZM_42CcNZ4"+ },+ "snippet":{+ "publishedAt":"2023-07-24T16:09:27Z",+ "channelId":"UCM5gMM_HqfKHYIEJ3lstMUA",+ "title":"Which Football Club Could Cristiano Ronaldo Afford To Buy? 💰",+ "description":"Sign up to Sorare and get a FREE card: https://sorare.pxf.io/NellisShorts Give Soraredata a go for FREE: ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"John Nellis",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T16:09:27Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"WbBz4oh9I5VaYj91LjeJvffrBVY",+ "id":{+ "kind":"youtube#video",+ "videoId":"wkP3XS3aNAY"+ },+ "snippet":{+ "publishedAt":"2023-07-24T16:00:50Z",+ "channelId":"UC4EP1dxFDPup_aFLt0ElsDw",+ "title":"PAULO DYBALA vs THE WORLD'S LONGEST FREEKICK WALL",+ "description":"Can Paulo Dybala curl a football around the World's longest free kick wall? We met up with the World Cup winner and put him to ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"Shoot for Love",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T16:00:50Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"juxv_FhT_l4qrR05S1QTrb4CGh8",+ "id":{+ "kind":"youtube#video",+ "videoId":"rJkDZ0WvfT8"+ },+ "snippet":{+ "publishedAt":"2023-07-24T10:00:39Z",+ "channelId":"UCO8qj5u80Ga7N_tP3BZWWhQ",+ "title":"TOP 10 DEFENDERS 2023",+ "description":"SoccerKingz https://soccerkingz.nl Use code: 'ILOVEHOF' to get 10% off. TOP 10 DEFENDERS 2023 Follow us! • Instagram ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"Home of Football",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T10:00:39Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"wtuknXTmI1txoULeH3aWaOuXOow",+ "id":{+ "kind":"youtube#video",+ "videoId":"XH0rtu4U6SE"+ },+ "snippet":{+ "publishedAt":"2023-07-21T16:30:05Z",+ "channelId":"UCwozCpFp9g9x0wAzuFh0hwQ",+ "title":"3 Things You Didn't Know About Erling Haaland ⚽️🇳🇴 #football #haaland #shorts",+ "description":"",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"FC Motivate",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-21T16:30:05Z"+ }+ }+ ]+}\ No newline at end of filediff --git a/examples/anthropic/inputs/plain_html_example.txt b/examples/anthropic/inputs/plain_html_example.txtnew file mode 100644index 00000000..78f814ae--- /dev/null+++ b/examples/anthropic/inputs/plain_html_example.txt@@ -0,0 +1,105 @@+<body class="fixed-top-nav " style="padding-top: 57px;">+ <header>+ <nav id="navbar" class="navbar navbar-light navbar-expand-sm fixed-top">+ <div class="container">+ <a class="navbar-brand title font-weight-lighter" href="/"><span class="font-weight-bold">Marco </span>Perini</a> <button class="navbar-toggler collapsed ml-auto" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar top-bar"></span> <span class="icon-bar middle-bar"></span> <span class="icon-bar bottom-bar"></span> </button>+ <div class="collapse navbar-collapse text-right" id="navbarNav">+ <ul class="navbar-nav ml-auto flex-nowrap">+ <li class="nav-item "> <a class="nav-link" href="/">About</a> </li>+ <li class="nav-item dropdown active">+ <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Projects<span class="sr-only">(current)</span></a>+ <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">+ <a class="dropdown-item" href="/projects/">Projects</a>+ <div class="dropdown-divider"></div>+ <a class="dropdown-item" href="/competitions/">Competitions</a>+ </div>+ </li>+ <li class="nav-item "> <a class="nav-link" href="/cv/">CV</a> </li>+ <li class="toggle-container"> <button id="light-toggle" title="Change theme"> <i class="fa-solid fa-moon"></i> <i class="fa-solid fa-sun"></i> </button> </li>+ </ul>+ </div>+ </div>+ </nav>+ <progress id="progress" value="0" max="284" style="top: 57px;">+ <div class="progress-container"> <span class="progress-bar"></span> </div>+ </progress>+ </header>+ <div class="container mt-5">+ <div class="post">+ <header class="post-header">+ <h1 class="post-title">Projects</h1>+ <p class="post-description"></p>+ </header>+ <article>+ <div class="projects">+ <div class="grid" style="position: relative; height: 861.992px;">+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 0px; top: 0px;">+ <a href="/projects/rotary-pendulum-rl/">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/rotary_pybullet.jpg" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">Rotary Pendulum RL</h4>+ <p class="card-text">Open Source project aimed at controlling a real life rotary pendulum using RL algorithms</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 260px; top: 0px;">+ <a href="https://github.com/PeriniM/DQN-SwingUp" rel="external nofollow noopener" target="_blank">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/value-policy-heatmaps.jpg" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">DQN Implementation from scratch</h4>+ <p class="card-text">Developed a Deep Q-Network algorithm to train a simple and double pendulum</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 0px; top: 447.414px;">+ <a href="https://github.com/PeriniM/Multi-Agents-HAED" rel="external nofollow noopener" target="_blank">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/multi_agents_haed.gif" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">Multi Agents HAED</h4>+ <p class="card-text">University project which focuses on simulating a multi-agent system to perform environment mapping. Agents, equipped with sensors, explore and record their surroundings, considering uncertainties in their readings.</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 260px; top: 370.172px;">+ <a href="/projects/wireless-esc-drone/">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/wireless_esc.gif" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">Wireless ESC for Modular Drones</h4>+ <p class="card-text">Modular drone architecture proposal and proof of concept. The project received maximum grade.</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ </div>+ </div>+ </article>+ </div>+ </div>+ <footer class="fixed-bottom">+ <div class="container mt-0"> © Copyright 2023 Marco Perini. Powered by <a href="https://jekyllrb.com/" target="_blank" rel="external nofollow noopener">Jekyll</a> with <a href="https://github.com/alshedivat/al-folio" rel="external nofollow noopener" target="_blank">al-folio</a> theme. Hosted by <a href="https://pages.github.com/" target="_blank" rel="external nofollow noopener">GitHub Pages</a>. </div>+ </footer>+ <div class="hiddendiv common"></div>+</body>\ No newline at end of filediff --git a/examples/anthropic/inputs/username.csv b/examples/anthropic/inputs/username.csvnew file mode 100644index 00000000..006ac8e6--- /dev/null+++ b/examples/anthropic/inputs/username.csv@@ -0,0 +1,7 @@+Username; Identifier;First name;Last name+booker12;9012;Rachel;Booker+grey07;2070;Laura;Grey+johnson81;4081;Craig;Johnson+jenkins46;9346;Mary;Jenkins+smith79;5079;Jamie;Smith+diff --git a/examples/anthropic/json_scraper_haiku.py b/examples/anthropic/json_scraper_haiku.pynew file mode 100644index 00000000..2610b658--- /dev/null+++ b/examples/anthropic/json_scraper_haiku.py@@ -0,0 +1,57 @@+"""+Basic example of scraping pipeline using JSONScraperGraph from JSON documents+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import JSONScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+load_dotenv()++# ************************************************+# Read the JSON file+# ************************************************++FILE_NAME = "inputs/example.json"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "api_key": os.getenv("ANTHROPIC_API_KEY"),+ "model": "claude-3-haiku-20240307",+ "max_tokens": 4000+ },+}++# ************************************************+# Create the JSONScraperGraph instance and run it+# ************************************************++json_scraper_graph = JSONScraperGraph(+ prompt="List me all the authors, title and genres of the books",+ source=text, # Pass the content of the file, not the file object+ config=graph_config+)++result = json_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = json_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")+diff --git a/examples/anthropic/pdf_scraper_graph_haiku.py b/examples/anthropic/pdf_scraper_graph_haiku.pynew file mode 100644index 00000000..cf7e8326--- /dev/null+++ b/examples/anthropic/pdf_scraper_graph_haiku.py@@ -0,0 +1,56 @@+import os, json+from dotenv import load_dotenv+from scrapegraphai.graphs import PDFScraperGraph++load_dotenv()+++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "api_key": os.getenv("ANTHROPIC_API_KEY"),+ "model": "claude-3-haiku-20240307",+ "max_tokens": 4000+ },+}++source = """+ The Divine Comedy, Italian La Divina Commedia, original name La commedia, long narrative poem written in Italian+ circa 1308/21 by Dante. It is usually held to be one of the world s great works of literature.+ Divided into three major sections—Inferno, Purgatorio, and Paradiso—the narrative traces the journey of Dante+ from darkness and error to the revelation of the divine light, culminating in the Beatific Vision of God.+ Dante is guided by the Roman poet Virgil, who represents the epitome of human knowledge, from the dark wood+ through the descending circles of the pit of Hell (Inferno). He then climbs the mountain of Purgatory, guided+ by the Roman poet Statius, who represents the fulfilment of human knowledge, and is finally led by his lifelong love,+ the Beatrice of his earlier poetry, through the celestial spheres of Paradise.+"""++schema = """+ {+ "type": "object",+ "properties": {+ "summary": {+ "type": "string"+ },+ "topics": {+ "type": "array",+ "items": {+ "type": "string"+ }+ }+ }+ }+"""++pdf_scraper_graph = PDFScraperGraph(+ prompt="Summarize the text and find the main topics",+ source=source,+ config=graph_config,+ schema=schema,+)+result = pdf_scraper_graph.run()++print(json.dumps(result, indent=4))diff --git a/examples/anthropic/scrape_plain_text_haiku.py b/examples/anthropic/scrape_plain_text_haiku.pynew file mode 100644index 00000000..d3f36638--- /dev/null+++ b/examples/anthropic/scrape_plain_text_haiku.py@@ -0,0 +1,54 @@+"""+Basic example of scraping pipeline using SmartScraper from text+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import SmartScraperGraph+from scrapegraphai.utils import prettify_exec_info++load_dotenv()++# ************************************************+# Read the text file+# ************************************************++FILE_NAME = "inputs/plain_html_example.txt"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++# It could be also a http request using the request model+with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "api_key": os.getenv("ANTHROPIC_API_KEY"),+ "model": "claude-3-haiku-20240307",+ "max_tokens": 4000+ },+}++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++smart_scraper_graph = SmartScraperGraph(+ prompt="List me all the projects with their description.",+ source=text,+ config=graph_config+)++result = smart_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = smart_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))diff --git a/examples/anthropic/script_generator_haiku.py b/examples/anthropic/script_generator_haiku.pynew file mode 100644index 00000000..889ce0b5--- /dev/null+++ b/examples/anthropic/script_generator_haiku.py@@ -0,0 +1,44 @@+"""+Basic example of scraping pipeline using ScriptCreatorGraph+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import ScriptCreatorGraph+from scrapegraphai.utils import prettify_exec_info++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "api_key": os.getenv("ANTHROPIC_API_KEY"),+ "model": "claude-3-haiku-20240307",+ "max_tokens": 4000+ },+}++# ************************************************+# Create the ScriptCreatorGraph instance and run it+# ************************************************++script_creator_graph = ScriptCreatorGraph(+ prompt="List me all the projects with their description.",+ # also accepts a string with the already downloaded HTML code+ source="https://perinim.github.io/projects",+ config=graph_config+)++result = script_creator_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = script_creator_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))+diff --git a/examples/anthropic/search_graph_haiku.py b/examples/anthropic/search_graph_haiku.pynew file mode 100644index 00000000..f90d7598--- /dev/null+++ b/examples/anthropic/search_graph_haiku.py@@ -0,0 +1,44 @@+"""+Example of Search Graph+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "api_key": os.getenv("ANTHROPIC_API_KEY"),+ "model": "claude-3-haiku-20240307",+ "max_tokens": 4000+ },+}++# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me Chioggia's famous dishes",+ config=graph_config+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/anthropic/smart_scraper_haiku.py b/examples/anthropic/smart_scraper_haiku.pyindex 909e031f..8d2cf05c 100644--- a/examples/anthropic/smart_scraper_haiku.py+++ b/examples/anthropic/smart_scraper_haiku.py@@ -6,8 +6,6 @@ import osfrom dotenv import load_dotenvfrom scrapegraphai.graphs import SmartScraperGraphfrom scrapegraphai.utils import prettify_exec_info-from langchain_community.llms import HuggingFaceEndpoint-from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings# required environment variables in .env@@ -15,16 +13,6 @@ from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings# ANTHROPIC_API_KEYload_dotenv()-HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')-# ************************************************-# Initialize the model instances-# ************************************************---embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(- api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"-)-# ************************************************# Create the SmartScraperGraph instance and run it# ************************************************@@ -33,8 +21,8 @@ graph_config = {"llm": {"api_key": os.getenv("ANTHROPIC_API_KEY"),"model": "claude-3-haiku-20240307",- "max_tokens": 4000},- "embeddings": {"model_instance": embedder_model_instance}+ "max_tokens": 4000+ },}smart_scraper_graph = SmartScraperGraph(diff --git a/examples/anthropic/smart_scraper_multi_haiku.py b/examples/anthropic/smart_scraper_multi_haiku.pynew file mode 100644index 00000000..61b4bbe0--- /dev/null+++ b/examples/anthropic/smart_scraper_multi_haiku.py@@ -0,0 +1,74 @@+"""+Basic example of scraping pipeline using SmartScraper+"""++import os, json+from dotenv import load_dotenv+from scrapegraphai.graphs import SmartScraperMultiGraph++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")++"""+Basic example of scraping pipeline using SmartScraper+"""++import os, json+from dotenv import load_dotenv+from scrapegraphai.graphs import SmartScraperMultiGraph++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "gpt-4o",+ },+ "verbose": True,+ "headless": False,+}++# *******************************************************+# Create the SmartScraperMultiGraph instance and run it+# *******************************************************++multiple_search_graph = SmartScraperMultiGraph(+ prompt="Who is Marco Perini?",+ source= [+ "https://perinim.github.io/",+ "https://perinim.github.io/cv/"+ ],+ schema=None,+ config=graph_config+)++result = multiple_search_graph.run()+print(json.dumps(result, indent=4))++# *******************************************************+# Create the SmartScraperMultiGraph instance and run it+# *******************************************************++multiple_search_graph = SmartScraperMultiGraph(+ prompt="Who is Marco Perini?",+ source= [+ "https://perinim.github.io/",+ "https://perinim.github.io/cv/"+ ],+ schema=None,+ config=graph_config+)++result = multiple_search_graph.run()+print(json.dumps(result, indent=4))diff --git a/examples/anthropic/smart_scraper_schema_haiku.py b/examples/anthropic/smart_scraper_schema_haiku.pyindex e4f7d5e6..587eb8c2 100644--- a/examples/anthropic/smart_scraper_schema_haiku.py+++ b/examples/anthropic/smart_scraper_schema_haiku.py@@ -6,8 +6,6 @@ import osfrom dotenv import load_dotenvfrom scrapegraphai.graphs import SmartScraperGraphfrom scrapegraphai.utils import prettify_exec_info-from langchain_community.llms import HuggingFaceEndpoint-from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings# required environment variables in .env@@ -15,16 +13,6 @@ from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings# ANTHROPIC_API_KEYload_dotenv()-HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')-# ************************************************-# Initialize the model instances-# ************************************************---embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(- api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"-)-# ************************************************# Define the output schema for the graph# ************************************************@@ -55,7 +43,6 @@ graph_config = {"api_key": os.getenv("ANTHROPIC_API_KEY"),"model": "claude-3-haiku-20240307","max_tokens": 4000},- "embeddings": {"model_instance": embedder_model_instance}}smart_scraper_graph = SmartScraperGraph(diff --git a/examples/anthropic/xml_scraper_haiku.py b/examples/anthropic/xml_scraper_haiku.pynew file mode 100644index 00000000..dd64f571--- /dev/null+++ b/examples/anthropic/xml_scraper_haiku.py@@ -0,0 +1,56 @@+"""+Basic example of scraping pipeline using XMLScraperGraph from XML documents+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import XMLScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+load_dotenv()++# ************************************************+# Read the XML file+# ************************************************++FILE_NAME = "inputs/books.xml"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "api_key": os.getenv("ANTHROPIC_API_KEY"),+ "model": "claude-3-haiku-20240307",+ "max_tokens": 4000+ },+}++# ************************************************+# Create the XMLScraperGraph instance and run it+# ************************************************++xml_scraper_graph = XMLScraperGraph(+ prompt="List me all the authors, title and genres of the books",+ source=text, # Pass the content of the file, not the file object+ config=graph_config+)++result = xml_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = xml_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/azure/csv_scraper_azure.py b/examples/azure/csv_scraper_azure.pynew file mode 100644index 00000000..3124498e--- /dev/null+++ b/examples/azure/csv_scraper_azure.py@@ -0,0 +1,68 @@+"""+Basic example of scraping pipeline using CSVScraperGraph from CSV documents+"""++import os+from dotenv import load_dotenv+import pandas as pd+from langchain_openai import AzureChatOpenAI+from langchain_openai import AzureOpenAIEmbeddings+from scrapegraphai.graphs import CSVScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+load_dotenv()++# ************************************************+# Read the CSV file+# ************************************************++FILE_NAME = "inputs/username.csv"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++text = pd.read_csv(file_path)++# ************************************************+# Define the configuration for the graph+# ************************************************++llm_model_instance = AzureChatOpenAI(+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+ azure_deployment=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"]+)++embedder_model_instance = AzureOpenAIEmbeddings(+ azure_deployment=os.environ["AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME"],+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+)++# ************************************************+# Create the JSONScraperGraph instance and run it+# ************************************************++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}+# ************************************************+# Create the CSVScraperGraph instance and run it+# ************************************************++csv_scraper_graph = CSVScraperGraph(+ prompt="List me all the last names",+ source=str(text), # Pass the content of the file, not the file object+ config=graph_config+)++result = csv_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = csv_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/azure/custom_graph_azure.py b/examples/azure/custom_graph_azure.pynew file mode 100644index 00000000..33ac1703--- /dev/null+++ b/examples/azure/custom_graph_azure.py@@ -0,0 +1,117 @@+"""+Example of custom graph using existing nodes+"""++import os+from dotenv import load_dotenv+from langchain_openai import OpenAIEmbeddings+from langchain_openai import AzureChatOpenAI+from langchain_openai import AzureOpenAIEmbeddings+from scrapegraphai.graphs import BaseGraph+from scrapegraphai.nodes import FetchNode, ParseNode, RAGNode, GenerateAnswerNode, RobotsNode+load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++# ************************************************+# Define the configuration for the graph+# ************************************************++llm_model_instance = AzureChatOpenAI(+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+ azure_deployment=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"]+)++embedder_model_instance = AzureOpenAIEmbeddings(+ azure_deployment=os.environ["AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME"],+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+)++# ************************************************+# Create the JSONScraperGraph instance and run it+# ************************************************++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}+# define the nodes for the graph+robot_node = RobotsNode(+ input="url",+ output=["is_scrapable"],+ node_config={+ "llm_model": llm_model_instance,+ "force_scraping": True,+ "verbose": True,+ }+)++fetch_node = FetchNode(+ input="url | local_dir",+ output=["doc", "link_urls", "img_urls"],+ node_config={+ "verbose": True,+ "headless": True,+ }+)+parse_node = ParseNode(+ input="doc",+ output=["parsed_doc"],+ node_config={+ "chunk_size": 4096,+ "verbose": True,+ }+)+rag_node = RAGNode(+ input="user_prompt & (parsed_doc | doc)",+ output=["relevant_chunks"],+ node_config={+ "llm_model": llm_model_instance,+ "embedder_model": embedder_model_instance,+ "verbose": True,+ }+)+generate_answer_node = GenerateAnswerNode(+ input="user_prompt & (relevant_chunks | parsed_doc | doc)",+ output=["answer"],+ node_config={+ "llm_model": llm_model_instance,+ "verbose": True,+ }+)++# ************************************************+# Create the graph by defining the connections+# ************************************************++graph = BaseGraph(+ nodes=[+ robot_node,+ fetch_node,+ parse_node,+ rag_node,+ generate_answer_node,+ ],+ edges=[+ (robot_node, fetch_node),+ (fetch_node, parse_node),+ (parse_node, rag_node),+ (rag_node, generate_answer_node)+ ],+ entry_point=robot_node+)++# ************************************************+# Execute the graph+# ************************************************++result, execution_info = graph.execute({+ "user_prompt": "Describe the content",+ "url": "https://example.com/"+})++# get the answer from the result+result = result.get("answer", "No answer found.")+print(result)diff --git a/examples/azure/pdf_scraper_azure.py b/examples/azure/pdf_scraper_azure.pynew file mode 100644index 00000000..0a522c79--- /dev/null+++ b/examples/azure/pdf_scraper_azure.py@@ -0,0 +1,62 @@+import os, json+from dotenv import load_dotenv+from langchain_openai import AzureChatOpenAI+from langchain_openai import AzureOpenAIEmbeddings+from scrapegraphai.graphs import PDFScraperGraph++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************+llm_model_instance = AzureChatOpenAI(+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+ azure_deployment=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"]+)++embedder_model_instance = AzureOpenAIEmbeddings(+ azure_deployment=os.environ["AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME"],+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+)+graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}++source = """+ The Divine Comedy, Italian La Divina Commedia, original name La commedia, long narrative poem written in Italian+ circa 1308/21 by Dante. It is usually held to be one of the world s great works of literature.+ Divided into three major sections—Inferno, Purgatorio, and Paradiso—the narrative traces the journey of Dante+ from darkness and error to the revelation of the divine light, culminating in the Beatific Vision of God.+ Dante is guided by the Roman poet Virgil, who represents the epitome of human knowledge, from the dark wood+ through the descending circles of the pit of Hell (Inferno). He then climbs the mountain of Purgatory, guided+ by the Roman poet Statius, who represents the fulfilment of human knowledge, and is finally led by his lifelong love,+ the Beatrice of his earlier poetry, through the celestial spheres of Paradise.+"""++schema = """+ {+ "type": "object",+ "properties": {+ "summary": {+ "type": "string"+ },+ "topics": {+ "type": "array",+ "items": {+ "type": "string"+ }+ }+ }+ }+"""++pdf_scraper_graph = PDFScraperGraph(+ prompt="Summarize the text and find the main topics",+ source=source,+ config=graph_config,+ schema=schema,+)+result = pdf_scraper_graph.run()++print(json.dumps(result, indent=4))diff --git a/examples/azure/scrape_plain_text_azure.py b/examples/azure/scrape_plain_text_azure.pynew file mode 100644index 00000000..df8cab79--- /dev/null+++ b/examples/azure/scrape_plain_text_azure.py@@ -0,0 +1,67 @@+"""+Basic example of scraping pipeline using SmartScraper from text+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import SmartScraperGraph+from langchain_openai import AzureChatOpenAI+from langchain_openai import AzureOpenAIEmbeddings+from scrapegraphai.utils import prettify_exec_info++load_dotenv()++# ************************************************+# Read the text file+# ************************************************++FILE_NAME = "inputs/plain_html_example.txt"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++# It could be also a http request using the request model+with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************++llm_model_instance = AzureChatOpenAI(+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+ azure_deployment=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"]+)++embedder_model_instance = AzureOpenAIEmbeddings(+ azure_deployment=os.environ["AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME"],+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+)++# ************************************************+# Create the JSONScraperGraph instance and run it+# ************************************************++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++smart_scraper_graph = SmartScraperGraph(+ prompt="List me all the projects with their description.",+ source=text,+ config=graph_config+)++result = smart_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = smart_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))diff --git a/examples/azure/script_generator_azure.py b/examples/azure/script_generator_azure.pynew file mode 100644index 00000000..0fe29c6d--- /dev/null+++ b/examples/azure/script_generator_azure.py@@ -0,0 +1,51 @@+"""+Basic example of scraping pipeline using ScriptCreatorGraph+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import ScriptCreatorGraph+from langchain_openai import AzureChatOpenAI+from langchain_openai import AzureOpenAIEmbeddings+from scrapegraphai.utils import prettify_exec_info++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************+llm_model_instance = AzureChatOpenAI(+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+ azure_deployment=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"]+)++embedder_model_instance = AzureOpenAIEmbeddings(+ azure_deployment=os.environ["AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME"],+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+)+graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}++# ************************************************+# Create the ScriptCreatorGraph instance and run it+# ************************************************++script_creator_graph = ScriptCreatorGraph(+ prompt="List me all the projects with their description.",+ # also accepts a string with the already downloaded HTML code+ source="https://perinim.github.io/projects",+ config=graph_config+)++result = script_creator_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = script_creator_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))+diff --git a/examples/azure/smart_scraper_azure_openai.py b/examples/azure/smart_scraper_azure.pysimilarity index 100%rename from examples/azure/smart_scraper_azure_openai.pyrename to examples/azure/smart_scraper_azure.pydiff --git a/examples/azure/smart_scraper_schema_azure.py b/examples/azure/smart_scraper_schema_azure.pynew file mode 100644index 00000000..1df69610--- /dev/null+++ b/examples/azure/smart_scraper_schema_azure.py@@ -0,0 +1,68 @@+"""+Basic example of scraping pipeline using SmartScraper with schema+"""++import os, json+from dotenv import load_dotenv+from langchain_openai import AzureChatOpenAI+from langchain_openai import AzureOpenAIEmbeddings+from scrapegraphai.graphs import SmartScraperGraph++load_dotenv()++# ************************************************+# Define the output schema for the graph+# ************************************************++schema= """+ {+ "Projects": [+ "Project #":+ {+ "title": "...",+ "description": "...",+ },+ "Project #":+ {+ "title": "...",+ "description": "...",+ }+ ]+ }+"""++# ************************************************+# Initialize the model instances+# ************************************************++llm_model_instance = AzureChatOpenAI(+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+ azure_deployment=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"]+)++embedder_model_instance = AzureOpenAIEmbeddings(+ azure_deployment=os.environ["AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME"],+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+)++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}+# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++smart_scraper_graph = SmartScraperGraph(+ prompt="List me all the projects with their description",+ source="https://perinim.github.io/projects/",+ schema=schema,+ config=graph_config+)++result = smart_scraper_graph.run()+print(json.dumps(result, indent=4))diff --git a/examples/mixed_models/smart_scraper_mixed.py b/examples/groq/script_generator_groq.pysimilarity index 59%rename from examples/mixed_models/smart_scraper_mixed.pyrename to examples/groq/script_generator_groq.pyindex 95dec64c..9e280e2b 100644--- a/examples/mixed_models/smart_scraper_mixed.py+++ b/examples/groq/script_generator_groq.py@@ -1,17 +1,17 @@"""-Basic example of scraping pipeline using SmartScraper+Basic example of scraping pipeline using ScriptCreatorGraph"""import osfrom dotenv import load_dotenv-from scrapegraphai.graphs import SmartScraperGraph+from scrapegraphai.graphs import ScriptCreatorGraphfrom scrapegraphai.utils import prettify_exec_info+load_dotenv()# ************************************************# Define the configuration for the graph# ************************************************-groq_key = os.getenv("GROQ_APIKEY")graph_config = {@@ -20,32 +20,26 @@ graph_config = {"api_key": groq_key,"temperature": 0},- "embeddings": {- "model": "ollama/nomic-embed-text",- "temperature": 0,- "base_url": "http://localhost:11434", # set ollama URL arbitrarily- },- "headless": False,- "verbose": True,+ "library": "beautifulsoup"}-# ************************************************-# Create the SmartScraperGraph instance and run it+# Create the ScriptCreatorGraph instance and run it# ************************************************-smart_scraper_graph = SmartScraperGraph(- prompt="List me all the projects with their description and the author.",+script_creator_graph = ScriptCreatorGraph(+ prompt="List me all the projects with their description.",# also accepts a string with the already downloaded HTML codesource="https://perinim.github.io/projects",config=graph_config)-result = smart_scraper_graph.run()+result = script_creator_graph.run()print(result)# ************************************************# Get graph execution info# ************************************************-graph_exec_info = smart_scraper_graph.get_execution_info()+graph_exec_info = script_creator_graph.get_execution_info()print(prettify_exec_info(graph_exec_info))+diff --git a/examples/huggingfacehub/csv_scraper_huggingfacehub.py b/examples/huggingfacehub/csv_scraper_huggingfacehub.pynew file mode 100644index 00000000..9d1dbe0b--- /dev/null+++ b/examples/huggingfacehub/csv_scraper_huggingfacehub.py@@ -0,0 +1,71 @@+"""+Basic example of scraping pipeline using CSVScraperGraph from CSV documents+"""++import os+from dotenv import load_dotenv+import pandas as pd+from scrapegraphai.graphs import CSVScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+from langchain_community.llms import HuggingFaceEndpoint+from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings++load_dotenv()++# ************************************************+# Read the CSV file+# ************************************************++FILE_NAME = "inputs/username.csv"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++text = pd.read_csv(file_path)++# ************************************************+# Define the configuration for the graph+# ************************************************+HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')++repo_id = "mistralai/Mistral-7B-Instruct-v0.2"++llm_model_instance = HuggingFaceEndpoint(+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN+)++embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(+ api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"+)++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}++# ************************************************+# Create the CSVScraperGraph instance and run it+# ************************************************++csv_scraper_graph = CSVScraperGraph(+ prompt="List me all the last names",+ source=str(text), # Pass the content of the file, not the file object+ config=graph_config+)++result = csv_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = csv_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/huggingfacehub/custom_graph_huggingfacehub.py b/examples/huggingfacehub/custom_graph_huggingfacehub.pynew file mode 100644index 00000000..ad903b5d--- /dev/null+++ b/examples/huggingfacehub/custom_graph_huggingfacehub.py@@ -0,0 +1,123 @@+"""+Example of custom graph using existing nodes+"""++import os+from dotenv import load_dotenv++from langchain_openai import OpenAIEmbeddings+from scrapegraphai.models import OpenAI+from scrapegraphai.graphs import BaseGraph+from scrapegraphai.nodes import FetchNode, ParseNode, RAGNode, GenerateAnswerNode, RobotsNode+from langchain_community.llms import HuggingFaceEndpoint+from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************+++HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')++repo_id = "mistralai/Mistral-7B-Instruct-v0.2"++llm_model_instance = HuggingFaceEndpoint(+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN+)++embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(+ api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"+)++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}++# ************************************************+# Define the graph nodes+# ************************************************++llm_model = OpenAI(graph_config["llm"])+embedder = OpenAIEmbeddings(api_key=llm_model.openai_api_key)++# define the nodes for the graph+robot_node = RobotsNode(+ input="url",+ output=["is_scrapable"],+ node_config={+ "llm_model": llm_model,+ "force_scraping": True,+ "verbose": True,+ }+)++fetch_node = FetchNode(+ input="url | local_dir",+ output=["doc", "link_urls", "img_urls"],+ node_config={+ "verbose": True,+ "headless": True,+ }+)+parse_node = ParseNode(+ input="doc",+ output=["parsed_doc"],+ node_config={+ "chunk_size": 4096,+ "verbose": True,+ }+)+rag_node = RAGNode(+ input="user_prompt & (parsed_doc | doc)",+ output=["relevant_chunks"],+ node_config={+ "llm_model": llm_model,+ "embedder_model": embedder,+ "verbose": True,+ }+)+generate_answer_node = GenerateAnswerNode(+ input="user_prompt & (relevant_chunks | parsed_doc | doc)",+ output=["answer"],+ node_config={+ "llm_model": llm_model,+ "verbose": True,+ }+)++# ************************************************+# Create the graph by defining the connections+# ************************************************++graph = BaseGraph(+ nodes=[+ robot_node,+ fetch_node,+ parse_node,+ rag_node,+ generate_answer_node,+ ],+ edges=[+ (robot_node, fetch_node),+ (fetch_node, parse_node),+ (parse_node, rag_node),+ (rag_node, generate_answer_node)+ ],+ entry_point=robot_node+)++# ************************************************+# Execute the graph+# ************************************************++result, execution_info = graph.execute({+ "user_prompt": "Describe the content",+ "url": "https://example.com/"+})++# get the answer from the result+result = result.get("answer", "No answer found.")+print(result)diff --git a/examples/huggingfacehub/inputs/books.xml b/examples/huggingfacehub/inputs/books.xmlnew file mode 100644index 00000000..e3d1fe87--- /dev/null+++ b/examples/huggingfacehub/inputs/books.xml@@ -0,0 +1,120 @@+<?xml version="1.0"?>+<catalog>+ <book id="bk101">+ <author>Gambardella, Matthew</author>+ <title>XML Developer's Guide</title>+ <genre>Computer</genre>+ <price>44.95</price>+ <publish_date>2000-10-01</publish_date>+ <description>An in-depth look at creating applications+ with XML.</description>+ </book>+ <book id="bk102">+ <author>Ralls, Kim</author>+ <title>Midnight Rain</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2000-12-16</publish_date>+ <description>A former architect battles corporate zombies,+ an evil sorceress, and her own childhood to become queen+ of the world.</description>+ </book>+ <book id="bk103">+ <author>Corets, Eva</author>+ <title>Maeve Ascendant</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2000-11-17</publish_date>+ <description>After the collapse of a nanotechnology+ society in England, the young survivors lay the+ foundation for a new society.</description>+ </book>+ <book id="bk104">+ <author>Corets, Eva</author>+ <title>Oberon's Legacy</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2001-03-10</publish_date>+ <description>In post-apocalypse England, the mysterious+ agent known only as Oberon helps to create a new life+ for the inhabitants of London. Sequel to Maeve+ Ascendant.</description>+ </book>+ <book id="bk105">+ <author>Corets, Eva</author>+ <title>The Sundered Grail</title>+ <genre>Fantasy</genre>+ <price>5.95</price>+ <publish_date>2001-09-10</publish_date>+ <description>The two daughters of Maeve, half-sisters,+ battle one another for control of England. Sequel to+ Oberon's Legacy.</description>+ </book>+ <book id="bk106">+ <author>Randall, Cynthia</author>+ <title>Lover Birds</title>+ <genre>Romance</genre>+ <price>4.95</price>+ <publish_date>2000-09-02</publish_date>+ <description>When Carla meets Paul at an ornithology+ conference, tempers fly as feathers get ruffled.</description>+ </book>+ <book id="bk107">+ <author>Thurman, Paula</author>+ <title>Splish Splash</title>+ <genre>Romance</genre>+ <price>4.95</price>+ <publish_date>2000-11-02</publish_date>+ <description>A deep sea diver finds true love twenty+ thousand leagues beneath the sea.</description>+ </book>+ <book id="bk108">+ <author>Knorr, Stefan</author>+ <title>Creepy Crawlies</title>+ <genre>Horror</genre>+ <price>4.95</price>+ <publish_date>2000-12-06</publish_date>+ <description>An anthology of horror stories about roaches,+ centipedes, scorpions and other insects.</description>+ </book>+ <book id="bk109">+ <author>Kress, Peter</author>+ <title>Paradox Lost</title>+ <genre>Science Fiction</genre>+ <price>6.95</price>+ <publish_date>2000-11-02</publish_date>+ <description>After an inadvertant trip through a Heisenberg+ Uncertainty Device, James Salway discovers the problems+ of being quantum.</description>+ </book>+ <book id="bk110">+ <author>O'Brien, Tim</author>+ <title>Microsoft .NET: The Programming Bible</title>+ <genre>Computer</genre>+ <price>36.95</price>+ <publish_date>2000-12-09</publish_date>+ <description>Microsoft's .NET initiative is explored in+ detail in this deep programmer's reference.</description>+ </book>+ <book id="bk111">+ <author>O'Brien, Tim</author>+ <title>MSXML3: A Comprehensive Guide</title>+ <genre>Computer</genre>+ <price>36.95</price>+ <publish_date>2000-12-01</publish_date>+ <description>The Microsoft MSXML3 parser is covered in+ detail, with attention to XML DOM interfaces, XSLT processing,+ SAX and more.</description>+ </book>+ <book id="bk112">+ <author>Galos, Mike</author>+ <title>Visual Studio 7: A Comprehensive Guide</title>+ <genre>Computer</genre>+ <price>49.95</price>+ <publish_date>2001-04-16</publish_date>+ <description>Microsoft Visual Studio 7 is explored in depth,+ looking at how Visual Basic, Visual C++, C#, and ASP+ are+ integrated into a comprehensive development+ environment.</description>+ </book>+</catalog>\ No newline at end of filediff --git a/examples/huggingfacehub/inputs/example.json b/examples/huggingfacehub/inputs/example.jsonnew file mode 100644index 00000000..2263184c--- /dev/null+++ b/examples/huggingfacehub/inputs/example.json@@ -0,0 +1,182 @@+{+ "kind":"youtube#searchListResponse",+ "etag":"q4ibjmYp1KA3RqMF4jFLl6PBwOg",+ "nextPageToken":"CAUQAA",+ "regionCode":"NL",+ "pageInfo":{+ "totalResults":1000000,+ "resultsPerPage":5+ },+ "items":[+ {+ "kind":"youtube#searchResult",+ "etag":"QCsHBifbaernVCbLv8Cu6rAeaDQ",+ "id":{+ "kind":"youtube#video",+ "videoId":"TvWDY4Mm5GM"+ },+ "snippet":{+ "publishedAt":"2023-07-24T14:15:01Z",+ "channelId":"UCwozCpFp9g9x0wAzuFh0hwQ",+ "title":"3 Football Clubs Kylian Mbappe Should Avoid Signing ✍️❌⚽️ #football #mbappe #shorts",+ "description":"",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/TvWDY4Mm5GM/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"FC Motivate",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T14:15:01Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"0NG5QHdtIQM_V-DBJDEf-jK_Y9k",+ "id":{+ "kind":"youtube#video",+ "videoId":"aZM_42CcNZ4"+ },+ "snippet":{+ "publishedAt":"2023-07-24T16:09:27Z",+ "channelId":"UCM5gMM_HqfKHYIEJ3lstMUA",+ "title":"Which Football Club Could Cristiano Ronaldo Afford To Buy? 💰",+ "description":"Sign up to Sorare and get a FREE card: https://sorare.pxf.io/NellisShorts Give Soraredata a go for FREE: ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/aZM_42CcNZ4/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"John Nellis",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T16:09:27Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"WbBz4oh9I5VaYj91LjeJvffrBVY",+ "id":{+ "kind":"youtube#video",+ "videoId":"wkP3XS3aNAY"+ },+ "snippet":{+ "publishedAt":"2023-07-24T16:00:50Z",+ "channelId":"UC4EP1dxFDPup_aFLt0ElsDw",+ "title":"PAULO DYBALA vs THE WORLD'S LONGEST FREEKICK WALL",+ "description":"Can Paulo Dybala curl a football around the World's longest free kick wall? We met up with the World Cup winner and put him to ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/wkP3XS3aNAY/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"Shoot for Love",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T16:00:50Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"juxv_FhT_l4qrR05S1QTrb4CGh8",+ "id":{+ "kind":"youtube#video",+ "videoId":"rJkDZ0WvfT8"+ },+ "snippet":{+ "publishedAt":"2023-07-24T10:00:39Z",+ "channelId":"UCO8qj5u80Ga7N_tP3BZWWhQ",+ "title":"TOP 10 DEFENDERS 2023",+ "description":"SoccerKingz https://soccerkingz.nl Use code: 'ILOVEHOF' to get 10% off. TOP 10 DEFENDERS 2023 Follow us! • Instagram ...",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/rJkDZ0WvfT8/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"Home of Football",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-24T10:00:39Z"+ }+ },+ {+ "kind":"youtube#searchResult",+ "etag":"wtuknXTmI1txoULeH3aWaOuXOow",+ "id":{+ "kind":"youtube#video",+ "videoId":"XH0rtu4U6SE"+ },+ "snippet":{+ "publishedAt":"2023-07-21T16:30:05Z",+ "channelId":"UCwozCpFp9g9x0wAzuFh0hwQ",+ "title":"3 Things You Didn't Know About Erling Haaland ⚽️🇳🇴 #football #haaland #shorts",+ "description":"",+ "thumbnails":{+ "default":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/default.jpg",+ "width":120,+ "height":90+ },+ "medium":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/mqdefault.jpg",+ "width":320,+ "height":180+ },+ "high":{+ "url":"https://i.ytimg.com/vi/XH0rtu4U6SE/hqdefault.jpg",+ "width":480,+ "height":360+ }+ },+ "channelTitle":"FC Motivate",+ "liveBroadcastContent":"none",+ "publishTime":"2023-07-21T16:30:05Z"+ }+ }+ ]+}\ No newline at end of filediff --git a/examples/huggingfacehub/inputs/plain_html_example.txt b/examples/huggingfacehub/inputs/plain_html_example.txtnew file mode 100644index 00000000..78f814ae--- /dev/null+++ b/examples/huggingfacehub/inputs/plain_html_example.txt@@ -0,0 +1,105 @@+<body class="fixed-top-nav " style="padding-top: 57px;">+ <header>+ <nav id="navbar" class="navbar navbar-light navbar-expand-sm fixed-top">+ <div class="container">+ <a class="navbar-brand title font-weight-lighter" href="/"><span class="font-weight-bold">Marco </span>Perini</a> <button class="navbar-toggler collapsed ml-auto" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar top-bar"></span> <span class="icon-bar middle-bar"></span> <span class="icon-bar bottom-bar"></span> </button>+ <div class="collapse navbar-collapse text-right" id="navbarNav">+ <ul class="navbar-nav ml-auto flex-nowrap">+ <li class="nav-item "> <a class="nav-link" href="/">About</a> </li>+ <li class="nav-item dropdown active">+ <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Projects<span class="sr-only">(current)</span></a>+ <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">+ <a class="dropdown-item" href="/projects/">Projects</a>+ <div class="dropdown-divider"></div>+ <a class="dropdown-item" href="/competitions/">Competitions</a>+ </div>+ </li>+ <li class="nav-item "> <a class="nav-link" href="/cv/">CV</a> </li>+ <li class="toggle-container"> <button id="light-toggle" title="Change theme"> <i class="fa-solid fa-moon"></i> <i class="fa-solid fa-sun"></i> </button> </li>+ </ul>+ </div>+ </div>+ </nav>+ <progress id="progress" value="0" max="284" style="top: 57px;">+ <div class="progress-container"> <span class="progress-bar"></span> </div>+ </progress>+ </header>+ <div class="container mt-5">+ <div class="post">+ <header class="post-header">+ <h1 class="post-title">Projects</h1>+ <p class="post-description"></p>+ </header>+ <article>+ <div class="projects">+ <div class="grid" style="position: relative; height: 861.992px;">+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 0px; top: 0px;">+ <a href="/projects/rotary-pendulum-rl/">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/rotary_pybullet.jpg" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">Rotary Pendulum RL</h4>+ <p class="card-text">Open Source project aimed at controlling a real life rotary pendulum using RL algorithms</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 260px; top: 0px;">+ <a href="https://github.com/PeriniM/DQN-SwingUp" rel="external nofollow noopener" target="_blank">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/value-policy-heatmaps.jpg" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">DQN Implementation from scratch</h4>+ <p class="card-text">Developed a Deep Q-Network algorithm to train a simple and double pendulum</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 0px; top: 447.414px;">+ <a href="https://github.com/PeriniM/Multi-Agents-HAED" rel="external nofollow noopener" target="_blank">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/multi_agents_haed.gif" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">Multi Agents HAED</h4>+ <p class="card-text">University project which focuses on simulating a multi-agent system to perform environment mapping. Agents, equipped with sensors, explore and record their surroundings, considering uncertainties in their readings.</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ <div class="grid-sizer"></div>+ <div class="grid-item" style="position: absolute; left: 260px; top: 370.172px;">+ <a href="/projects/wireless-esc-drone/">+ <div class="card hoverable">+ <figure>+ <picture> <img src="/assets/img/wireless_esc.gif" width="auto" height="auto" alt="project thumbnail" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"> </picture>+ </figure>+ <div class="card-body">+ <h4 class="card-title">Wireless ESC for Modular Drones</h4>+ <p class="card-text">Modular drone architecture proposal and proof of concept. The project received maximum grade.</p>+ <div class="row ml-1 mr-1 p-0"> </div>+ </div>+ </div>+ </a>+ </div>+ </div>+ </div>+ </article>+ </div>+ </div>+ <footer class="fixed-bottom">+ <div class="container mt-0"> © Copyright 2023 Marco Perini. Powered by <a href="https://jekyllrb.com/" target="_blank" rel="external nofollow noopener">Jekyll</a> with <a href="https://github.com/alshedivat/al-folio" rel="external nofollow noopener" target="_blank">al-folio</a> theme. Hosted by <a href="https://pages.github.com/" target="_blank" rel="external nofollow noopener">GitHub Pages</a>. </div>+ </footer>+ <div class="hiddendiv common"></div>+</body>\ No newline at end of filediff --git a/examples/huggingfacehub/inputs/username.csv b/examples/huggingfacehub/inputs/username.csvnew file mode 100644index 00000000..006ac8e6--- /dev/null+++ b/examples/huggingfacehub/inputs/username.csv@@ -0,0 +1,7 @@+Username; Identifier;First name;Last name+booker12;9012;Rachel;Booker+grey07;2070;Laura;Grey+johnson81;4081;Craig;Johnson+jenkins46;9346;Mary;Jenkins+smith79;5079;Jamie;Smith+diff --git a/examples/huggingfacehub/json_scraper_huggingfacehub.py b/examples/huggingfacehub/json_scraper_huggingfacehub.pynew file mode 100644index 00000000..3a9a163d--- /dev/null+++ b/examples/huggingfacehub/json_scraper_huggingfacehub.py@@ -0,0 +1,72 @@+"""+Basic example of scraping pipeline using JSONScraperGraph from JSON documents+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import JSONScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+from langchain_community.llms import HuggingFaceEndpoint+from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings++load_dotenv()++# ************************************************+# Read the JSON file+# ************************************************++FILE_NAME = "inputs/example.json"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************+HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')++repo_id = "mistralai/Mistral-7B-Instruct-v0.2"++llm_model_instance = HuggingFaceEndpoint(+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN+)++embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(+ api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"+)++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}++# ************************************************+# Create the JSONScraperGraph instance and run it+# ************************************************++json_scraper_graph = JSONScraperGraph(+ prompt="List me all the authors, title and genres of the books",+ source=text, # Pass the content of the file, not the file object+ config=graph_config+)++result = json_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = json_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")+diff --git a/examples/huggingfacehub/pdf_scraper_graph_huggingfacehub.py b/examples/huggingfacehub/pdf_scraper_graph_huggingfacehub.pynew file mode 100644index 00000000..9b506cb1--- /dev/null+++ b/examples/huggingfacehub/pdf_scraper_graph_huggingfacehub.py@@ -0,0 +1,67 @@+import os, json+from dotenv import load_dotenv+from scrapegraphai.graphs import PDFScraperGraph+from langchain_community.llms import HuggingFaceEndpoint+from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings++load_dotenv()+++# ************************************************+# Define the configuration for the graph+# ************************************************++HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')++repo_id = "mistralai/Mistral-7B-Instruct-v0.2"++llm_model_instance = HuggingFaceEndpoint(+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN+)++embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(+ api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"+)++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}++source = """+ The Divine Comedy, Italian La Divina Commedia, original name La commedia, long narrative poem written in Italian+ circa 1308/21 by Dante. It is usually held to be one of the world s great works of literature.+ Divided into three major sections—Inferno, Purgatorio, and Paradiso—the narrative traces the journey of Dante+ from darkness and error to the revelation of the divine light, culminating in the Beatific Vision of God.+ Dante is guided by the Roman poet Virgil, who represents the epitome of human knowledge, from the dark wood+ through the descending circles of the pit of Hell (Inferno). He then climbs the mountain of Purgatory, guided+ by the Roman poet Statius, who represents the fulfilment of human knowledge, and is finally led by his lifelong love,+ the Beatrice of his earlier poetry, through the celestial spheres of Paradise.+"""++schema = """+ {+ "type": "object",+ "properties": {+ "summary": {+ "type": "string"+ },+ "topics": {+ "type": "array",+ "items": {+ "type": "string"+ }+ }+ }+ }+"""++pdf_scraper_graph = PDFScraperGraph(+ prompt="Summarize the text and find the main topics",+ source=source,+ config=graph_config,+ schema=schema,+)+result = pdf_scraper_graph.run()++print(json.dumps(result, indent=4))diff --git a/examples/huggingfacehub/scrape_plain_text_huggingfacehub.py b/examples/huggingfacehub/scrape_plain_text_huggingfacehub.pynew file mode 100644index 00000000..f07e5666--- /dev/null+++ b/examples/huggingfacehub/scrape_plain_text_huggingfacehub.py@@ -0,0 +1,69 @@+"""+Basic example of scraping pipeline using SmartScraper from text+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import SmartScraperGraph+from scrapegraphai.utils import prettify_exec_info+from langchain_community.llms import HuggingFaceEndpoint+from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings++load_dotenv()++# ************************************************+# Read the text file+# ************************************************++FILE_NAME = "inputs/plain_html_example.txt"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++# It could be also a http request using the request model+with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************++HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')++repo_id = "mistralai/Mistral-7B-Instruct-v0.2"++llm_model_instance = HuggingFaceEndpoint(+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN+)++embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(+ api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"+)++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++smart_scraper_graph = SmartScraperGraph(+ prompt="List me all the projects with their description.",+ source=text,+ config=graph_config+)++result = smart_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = smart_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))diff --git a/examples/huggingfacehub/script_generator_huggingfacehub.py b/examples/huggingfacehub/script_generator_huggingfacehub.pynew file mode 100644index 00000000..4804db93--- /dev/null+++ b/examples/huggingfacehub/script_generator_huggingfacehub.py@@ -0,0 +1,61 @@+"""+Basic example of scraping pipeline using ScriptCreatorGraph+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import ScriptCreatorGraph+from scrapegraphai.utils import prettify_exec_info+from langchain_community.llms import HuggingFaceEndpoint+from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')+# ************************************************+# Initialize the model instances+# ************************************************++repo_id = "mistralai/Mistral-7B-Instruct-v0.2"++llm_model_instance = HuggingFaceEndpoint(+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN+)++embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(+ api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"+)++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}+# ************************************************+# Create the ScriptCreatorGraph instance and run it+# ************************************************++script_creator_graph = ScriptCreatorGraph(+ prompt="List me all the projects with their description.",+ # also accepts a string with the already downloaded HTML code+ source="https://perinim.github.io/projects",+ config=graph_config+)++result = script_creator_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = script_creator_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))+diff --git a/examples/huggingfacehub/search_graph_huggingfacehub.py b/examples/huggingfacehub/search_graph_huggingfacehub.pynew file mode 100644index 00000000..b3c58ce5--- /dev/null+++ b/examples/huggingfacehub/search_graph_huggingfacehub.py@@ -0,0 +1,56 @@+"""+Example of Search Graph+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+from langchain_community.llms import HuggingFaceEndpoint+from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')++repo_id = "mistralai/Mistral-7B-Instruct-v0.2"++llm_model_instance = HuggingFaceEndpoint(+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN+)++embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(+ api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"+)++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}++# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me Chioggia's famous dishes",+ config=graph_config+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/huggingfacehub/smart_scraper_huggingfacehub.py b/examples/huggingfacehub/smart_scraper_huggingfacehub.pyindex 082ce59c..bd415d41 100644--- a/examples/huggingfacehub/smart_scraper_huggingfacehub.py+++ b/examples/huggingfacehub/smart_scraper_huggingfacehub.py@@ -28,8 +28,6 @@ llm_model_instance = HuggingFaceEndpoint()--embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2")diff --git a/examples/huggingfacehub/smart_scraper_multi_huggingfacehub.py b/examples/huggingfacehub/smart_scraper_multi_huggingfacehub.pynew file mode 100644index 00000000..e1a332f9--- /dev/null+++ b/examples/huggingfacehub/smart_scraper_multi_huggingfacehub.py@@ -0,0 +1,49 @@+"""+Basic example of scraping pipeline using SmartScraper+"""++import os, json+from dotenv import load_dotenv+from scrapegraphai.graphs import SmartScraperMultiGraph+from langchain_community.llms import HuggingFaceEndpoint+from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')++repo_id = "mistralai/Mistral-7B-Instruct-v0.2"++llm_model_instance = HuggingFaceEndpoint(+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN+)++embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(+ api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"+)++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}++# *******************************************************+# Create the SmartScraperMultiGraph instance and run it+# *******************************************************++multiple_search_graph = SmartScraperMultiGraph(+ prompt="Who is Marco Perini?",+ source= [+ "https://perinim.github.io/",+ "https://perinim.github.io/cv/"+ ],+ schema=None,+ config=graph_config+)++result = multiple_search_graph.run()+print(json.dumps(result, indent=4))diff --git a/examples/huggingfacehub/smart_scraper_schema_huggingfacehub.py b/examples/huggingfacehub/smart_scraper_schema_huggingfacehub.pyindex 91adad77..1e0c94d6 100644--- a/examples/huggingfacehub/smart_scraper_schema_huggingfacehub.py+++ b/examples/huggingfacehub/smart_scraper_schema_huggingfacehub.py@@ -45,8 +45,6 @@ llm_model_instance = HuggingFaceEndpoint(repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN)--embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2")diff --git a/examples/huggingfacehub/xml_scraper_huggingfacehub.py b/examples/huggingfacehub/xml_scraper_huggingfacehub.pynew file mode 100644index 00000000..cc8a4425--- /dev/null+++ b/examples/huggingfacehub/xml_scraper_huggingfacehub.py@@ -0,0 +1,69 @@+"""+Basic example of scraping pipeline using XMLScraperGraph from XML documents+"""++import os+from dotenv import load_dotenv+from scrapegraphai.graphs import XMLScraperGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+from langchain_community.llms import HuggingFaceEndpoint+from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings++load_dotenv()++# ************************************************+# Read the XML file+# ************************************************++FILE_NAME = "inputs/books.xml"+curr_dir = os.path.dirname(os.path.realpath(__file__))+file_path = os.path.join(curr_dir, FILE_NAME)++with open(file_path, 'r', encoding="utf-8") as file:+ text = file.read()++# ************************************************+# Define the configuration for the graph+# ************************************************++HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')++repo_id = "mistralai/Mistral-7B-Instruct-v0.2"++llm_model_instance = HuggingFaceEndpoint(+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN+)++embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(+ api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"+)++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}++# ************************************************+# Create the XMLScraperGraph instance and run it+# ************************************************++xml_scraper_graph = XMLScraperGraph(+ prompt="List me all the authors, title and genres of the books",+ source=text, # Pass the content of the file, not the file object+ config=graph_config+)++result = xml_scraper_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = xml_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json or csv+convert_to_csv(result, "result")+convert_to_json(result, "result")+diff --git a/examples/oneapi/script_generator_oneapi.py b/examples/oneapi/script_generator_oneapi.pynew file mode 100644index 00000000..42222635--- /dev/null+++ b/examples/oneapi/script_generator_oneapi.py@@ -0,0 +1,44 @@+"""+Basic example of scraping pipeline using ScriptCreatorGraph+"""++from dotenv import load_dotenv+from scrapegraphai.graphs import ScriptCreatorGraph+from scrapegraphai.utils import prettify_exec_info++load_dotenv()++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "api_key": "***************************",+ "model": "oneapi/qwen-turbo",+ "base_url": "http://127.0.0.1:3000/v1", # 设置 OneAPI URL+ },+ "library": "beautifulsoup"+}++# ************************************************+# Create the ScriptCreatorGraph instance and run it+# ************************************************++script_creator_graph = ScriptCreatorGraph(+ prompt="List me all the projects with their description.",+ # also accepts a string with the already downloaded HTML code+ source="https://perinim.github.io/projects",+ config=graph_config+)++result = script_creator_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = script_creator_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))+diff --git a/examples/openai/custom_graph_openai.py b/examples/openai/custom_graph_openai.pyindex baaeaa3f..9580e88a 100644--- a/examples/openai/custom_graph_openai.py+++ b/examples/openai/custom_graph_openai.py@@ -15,15 +15,12 @@ load_dotenv()# Define the configuration for the graph# ************************************************-openai_key = os.getenv("OPENAI_APIKEY")-graph_config = {"llm": {- "api_key": openai_key,- "model": "gpt-3.5-turbo",- "temperature": 0,- "streaming": False- },+ "api_key": os.getenv("ANTHROPIC_API_KEY"),+ "model": "claude-3-haiku-20240307",+ "max_tokens": 4000+ },}# ************************************************