Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
add openai and oneapi examples
Marco Vinciguerra1fe49753b9e6
diff --git a/examples/local_models/json_scraper_multi_ollama.py b/examples/local_models/json_scraper_multi_ollama.pyindex 2754425c..91f4fab4 100644--- a/examples/local_models/json_scraper_multi_ollama.py+++ b/examples/local_models/json_scraper_multi_ollama.py@@ -1,7 +1,7 @@"""Module for showing how PDFScraper multi works"""-import os+import osimport jsonfrom scrapegraphai.graphs import JSONScraperMultiGraphdiff --git a/examples/oneapi/json_scraper_multi_oneapi..py b/examples/oneapi/json_scraper_multi_oneapi..pynew file mode 100644index 00000000..5dc365aa--- /dev/null+++ b/examples/oneapi/json_scraper_multi_oneapi..py@@ -0,0 +1,32 @@+"""+Module for showing how PDFScraper multi works+"""+import os+import json+from scrapegraphai.graphs import JSONScraperMultiGraph++graph_config = {+ "llm": {+ "api_key": "***************************",+ "model": "oneapi/qwen-turbo",+ "base_url": "http://127.0.0.1:3000/v1", # 设置 OneAPI URL+ }+}+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()++sources = [text, text]++multiple_search_graph = JSONScraperMultiGraph(+ prompt= "List me all the authors, title and genres of the books",+ source= sources,+ schema=None,+ config=graph_config+)++result = multiple_search_graph.run()+print(json.dumps(result, indent=4))diff --git a/examples/oneapi/json_scraper_oneapi.py b/examples/oneapi/json_scraper_oneapi.pyindex 5f182594..87c7ea3c 100644--- a/examples/oneapi/json_scraper_oneapi.py+++ b/examples/oneapi/json_scraper_oneapi.py@@ -3,10 +3,8 @@ Basic example of scraping pipeline using JSONScraperGraph from JSON documents"""import os-from dotenv import load_dotenvfrom scrapegraphai.graphs import JSONScraperGraphfrom scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info-load_dotenv()# ************************************************# Read the JSON file@@ -23,8 +21,6 @@ with open(file_path, 'r', encoding="utf-8") as file:# Define the configuration for the graph# ************************************************-openai_key = os.getenv("OPENAI_APIKEY")-graph_config = {"llm": {"api_key": "***************************",diff --git a/examples/oneapi/pdf_scraper_multi_oneapi.py b/examples/oneapi/pdf_scraper_multi_oneapi.pynew file mode 100644index 00000000..8b6c57a1--- /dev/null+++ b/examples/oneapi/pdf_scraper_multi_oneapi.py@@ -0,0 +1,70 @@+"""+Module for showing how PDFScraper multi works+"""+import os+import json+from dotenv import load_dotenv+from scrapegraphai.graphs import PdfScraperMultiGraph++load_dotenv()++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "gpt-3.5-turbo",+ },+}++# Covert to list+sources = [+ "This paper provides evidence from a natural experiment on the relationship between positive affect and productivity. We link highly detailed administrative data on the behaviors and performance of all telesales workers at a large telecommunications company with survey reports of employee happiness that we collected on a weekly basis. We use variation in worker mood arising from visual exposure to weather—the interaction between call center architecture and outdoor weather conditions—in order to provide a quasi-experimental test of the effect of happiness on productivity. We find evidence of a positive impact on sales performance, which is driven by changes in labor productivity – largely through workers converting more calls into sales, and to a lesser extent by making more calls per hour and adhering more closely to their schedule. We find no evidence in our setting of effects on measures of high-frequency labor supply such as attendance and break-taking.",+ "This paper provides evidence from a natural experiment on the relationship between positive affect and productivity. We link highly detailed administrative data on the behaviors and performance of all telesales workers at a large telecommunications company with survey reports of employee happiness that we collected on a weekly basis. We use variation in worker mood arising from visual exposure to weather—the interaction between call center architecture and outdoor weather conditions—in order to provide a quasi-experimental test of the effect of happiness on productivity. We find evidence of a positive impact on sales performance, which is driven by changes in labor productivity – largely through workers converting more calls into sales, and to a lesser extent by making more calls per hour and adhering more closely to their schedule. We find no evidence in our setting of effects on measures of high-frequency labor supply such as attendance and break-taking.",+ "This paper provides evidence from a natural experiment on the relationship between positive affect and productivity. We link highly detailed administrative data on the behaviors and performance of all telesales workers at a large telecommunications company with survey reports of employee happiness that we collected on a weekly basis. We use variation in worker mood arising from visual exposure to weather—the interaction between call center architecture and outdoor weather conditions—in order to provide a quasi-experimental test of the effect of happiness on productivity. We find evidence of a positive impact on sales performance, which is driven by changes in labor productivity – largely through workers converting more calls into sales, and to a lesser extent by making more calls per hour and adhering more closely to their schedule. We find no evidence in our setting of effects on measures of high-frequency labor supply such as attendance and break-taking.",+ "This paper provides evidence from a natural experiment on the relationship between positive affect and productivity. We link highly detailed administrative data on the behaviors and performance of all telesales workers at a large telecommunications company with survey reports of employee happiness that we collected on a weekly basis. We use variation in worker mood arising from visual exposure to weather—the interaction between call center architecture and outdoor weather conditions—in order to provide a quasi-experimental test of the effect of happiness on productivity. We find evidence of a positive impact on sales performance, which is driven by changes in labor productivity – largely through workers converting more calls into sales, and to a lesser extent by making more calls per hour and adhering more closely to their schedule. We find no evidence in our setting of effects on measures of high-frequency labor supply such as attendance and break-taking.",+]++prompt = """+You are an expert in reviewing academic manuscripts. Please analyze the abstracts provided from an academic journal article to extract and clearly identify the following elements:++Independent Variable (IV): The variable that is manipulated or considered as the primary cause affecting other variables.+Dependent Variable (DV): The variable that is measured or observed, which is expected to change as a result of variations in the Independent Variable.+Exogenous Shock: Identify any external or unexpected events used in the study that serve as a natural experiment or provide a unique setting for observing the effects on the IV and DV.+Response Format: For each abstract, present your response in the following structured format:++Independent Variable (IV):+Dependent Variable (DV):+Exogenous Shock:++Example Queries and Responses:++Query: This paper provides evidence from a natural experiment on the relationship between positive affect and productivity. We link highly detailed administrative data on the behaviors and performance of all telesales workers at a large telecommunications company with survey reports of employee happiness that we collected on a weekly basis. We use variation in worker mood arising from visual exposure to weather the interaction between call center architecture and outdoor weather conditions in order to provide a quasi-experimental test of the effect of happiness on productivity. We find evidence of a positive impact on sales performance, which is driven by changes in labor productivity largely through workers converting more calls into sales, and to a lesser extent by making more calls per hour and adhering more closely to their schedule. We find no evidence in our setting of effects on measures of high-frequency labor supply such as attendance and break-taking.++Response:++Independent Variable (IV): Employee happiness.+Dependent Variable (DV): Overall firm productivity.+Exogenous Shock: Sudden company-wide increase in bonus payments.++Query: The diffusion of social media coincided with a worsening of mental health conditions among adolescents and young adults in the United States, giving rise to speculation that social media might be detrimental to mental health. In this paper, we provide quasi-experimental estimates of the impact of social media on mental health by leveraging a unique natural experiment: the staggered introduction of Facebook across U.S. colleges. Our analysis couples data on student mental health around the years of Facebook's expansion with a generalized difference-in-differences empirical strategy. We find that the roll-out of Facebook at a college increased symptoms of poor mental health, especially depression. We also find that, among students predicted to be most susceptible to mental illness, the introduction of Facebook led to increased utilization of mental healthcare services. Lastly, we find that, after the introduction of Facebook, students were more likely to report experiencing impairments to academic performance resulting from poor mental health. Additional evidence on mechanisms suggests that the results are due to Facebook fostering unfavorable social comparisons.++Response:++Independent Variable (IV): Exposure to social media.+Dependent Variable (DV): Mental health outcomes.+Exogenous Shock: staggered introduction of Facebook across U.S. colleges.+"""+# *******************************************************+# Create the SmartScraperMultiGraph instance and run it+# *******************************************************++multiple_search_graph = PdfScraperMultiGraph(+ prompt=prompt,+ source= sources,+ schema=None,+ config=graph_config+)++result = multiple_search_graph.run()+print(json.dumps(result, indent=4))diff --git a/examples/openai/deep_scraper_openai.py b/examples/openai/deep_scraper_openai.pyindex 6a2e1347..4860a31f 100644--- a/examples/openai/deep_scraper_openai.py+++ b/examples/openai/deep_scraper_openai.py@@ -9,7 +9,6 @@ from scrapegraphai.utils import prettify_exec_infoload_dotenv()-# ************************************************# Define the configuration for the graph# ************************************************diff --git a/examples/openai/json_scraper_multi_openai.py b/examples/openai/json_scraper_multi_openai.pynew file mode 100644index 00000000..5f3d9fc2--- /dev/null+++ b/examples/openai/json_scraper_multi_openai.py@@ -0,0 +1,37 @@+"""+Module for showing how PDFScraper multi works+"""+import os+import json+from dotenv import load_dotenv+from scrapegraphai.graphs import JSONScraperMultiGraph++load_dotenv()++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "gpt-3.5-turbo",+ },+}++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()++sources = [text, text]++multiple_search_graph = JSONScraperMultiGraph(+ prompt= "List me all the authors, title and genres of the books",+ source= sources,+ schema=None,+ config=graph_config+)++result = multiple_search_graph.run()+print(json.dumps(result, indent=4))diff --git a/examples/openai/pdf_scraper_multi_openai.py b/examples/openai/pdf_scraper_multi_openai.pynew file mode 100644index 00000000..8b6c57a1--- /dev/null+++ b/examples/openai/pdf_scraper_multi_openai.py@@ -0,0 +1,70 @@+"""+Module for showing how PDFScraper multi works+"""+import os+import json+from dotenv import load_dotenv+from scrapegraphai.graphs import PdfScraperMultiGraph++load_dotenv()++openai_key = os.getenv("OPENAI_APIKEY")++graph_config = {+ "llm": {+ "api_key": openai_key,+ "model": "gpt-3.5-turbo",+ },+}++# Covert to list+sources = [+ "This paper provides evidence from a natural experiment on the relationship between positive affect and productivity. We link highly detailed administrative data on the behaviors and performance of all telesales workers at a large telecommunications company with survey reports of employee happiness that we collected on a weekly basis. We use variation in worker mood arising from visual exposure to weather—the interaction between call center architecture and outdoor weather conditions—in order to provide a quasi-experimental test of the effect of happiness on productivity. We find evidence of a positive impact on sales performance, which is driven by changes in labor productivity – largely through workers converting more calls into sales, and to a lesser extent by making more calls per hour and adhering more closely to their schedule. We find no evidence in our setting of effects on measures of high-frequency labor supply such as attendance and break-taking.",+ "This paper provides evidence from a natural experiment on the relationship between positive affect and productivity. We link highly detailed administrative data on the behaviors and performance of all telesales workers at a large telecommunications company with survey reports of employee happiness that we collected on a weekly basis. We use variation in worker mood arising from visual exposure to weather—the interaction between call center architecture and outdoor weather conditions—in order to provide a quasi-experimental test of the effect of happiness on productivity. We find evidence of a positive impact on sales performance, which is driven by changes in labor productivity – largely through workers converting more calls into sales, and to a lesser extent by making more calls per hour and adhering more closely to their schedule. We find no evidence in our setting of effects on measures of high-frequency labor supply such as attendance and break-taking.",+ "This paper provides evidence from a natural experiment on the relationship between positive affect and productivity. We link highly detailed administrative data on the behaviors and performance of all telesales workers at a large telecommunications company with survey reports of employee happiness that we collected on a weekly basis. We use variation in worker mood arising from visual exposure to weather—the interaction between call center architecture and outdoor weather conditions—in order to provide a quasi-experimental test of the effect of happiness on productivity. We find evidence of a positive impact on sales performance, which is driven by changes in labor productivity – largely through workers converting more calls into sales, and to a lesser extent by making more calls per hour and adhering more closely to their schedule. We find no evidence in our setting of effects on measures of high-frequency labor supply such as attendance and break-taking.",+ "This paper provides evidence from a natural experiment on the relationship between positive affect and productivity. We link highly detailed administrative data on the behaviors and performance of all telesales workers at a large telecommunications company with survey reports of employee happiness that we collected on a weekly basis. We use variation in worker mood arising from visual exposure to weather—the interaction between call center architecture and outdoor weather conditions—in order to provide a quasi-experimental test of the effect of happiness on productivity. We find evidence of a positive impact on sales performance, which is driven by changes in labor productivity – largely through workers converting more calls into sales, and to a lesser extent by making more calls per hour and adhering more closely to their schedule. We find no evidence in our setting of effects on measures of high-frequency labor supply such as attendance and break-taking.",+]++prompt = """+You are an expert in reviewing academic manuscripts. Please analyze the abstracts provided from an academic journal article to extract and clearly identify the following elements:++Independent Variable (IV): The variable that is manipulated or considered as the primary cause affecting other variables.+Dependent Variable (DV): The variable that is measured or observed, which is expected to change as a result of variations in the Independent Variable.+Exogenous Shock: Identify any external or unexpected events used in the study that serve as a natural experiment or provide a unique setting for observing the effects on the IV and DV.+Response Format: For each abstract, present your response in the following structured format:++Independent Variable (IV):+Dependent Variable (DV):+Exogenous Shock:++Example Queries and Responses:++Query: This paper provides evidence from a natural experiment on the relationship between positive affect and productivity. We link highly detailed administrative data on the behaviors and performance of all telesales workers at a large telecommunications company with survey reports of employee happiness that we collected on a weekly basis. We use variation in worker mood arising from visual exposure to weather the interaction between call center architecture and outdoor weather conditions in order to provide a quasi-experimental test of the effect of happiness on productivity. We find evidence of a positive impact on sales performance, which is driven by changes in labor productivity largely through workers converting more calls into sales, and to a lesser extent by making more calls per hour and adhering more closely to their schedule. We find no evidence in our setting of effects on measures of high-frequency labor supply such as attendance and break-taking.++Response:++Independent Variable (IV): Employee happiness.+Dependent Variable (DV): Overall firm productivity.+Exogenous Shock: Sudden company-wide increase in bonus payments.++Query: The diffusion of social media coincided with a worsening of mental health conditions among adolescents and young adults in the United States, giving rise to speculation that social media might be detrimental to mental health. In this paper, we provide quasi-experimental estimates of the impact of social media on mental health by leveraging a unique natural experiment: the staggered introduction of Facebook across U.S. colleges. Our analysis couples data on student mental health around the years of Facebook's expansion with a generalized difference-in-differences empirical strategy. We find that the roll-out of Facebook at a college increased symptoms of poor mental health, especially depression. We also find that, among students predicted to be most susceptible to mental illness, the introduction of Facebook led to increased utilization of mental healthcare services. Lastly, we find that, after the introduction of Facebook, students were more likely to report experiencing impairments to academic performance resulting from poor mental health. Additional evidence on mechanisms suggests that the results are due to Facebook fostering unfavorable social comparisons.++Response:++Independent Variable (IV): Exposure to social media.+Dependent Variable (DV): Mental health outcomes.+Exogenous Shock: staggered introduction of Facebook across U.S. colleges.+"""+# *******************************************************+# Create the SmartScraperMultiGraph instance and run it+# *******************************************************++multiple_search_graph = PdfScraperMultiGraph(+ prompt=prompt,+ source= sources,+ schema=None,+ config=graph_config+)++result = multiple_search_graph.run()+print(json.dumps(result, indent=4))