mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-06-23 21:00:30 +08:00
Merge branch 'main' of https://github.com/VinciGit00/Scrapegraph-ai
This commit is contained in:
commit
51a28eb166
@ -1,2 +0,0 @@
|
||||
For having interacting examples visit the following collab notebook:
|
||||
[](https://colab.research.google.com/drive/1sEZBonBMGP44CtO6GQTwAlL0BGJXjtfd?usp=sharing)
|
||||
@ -1,54 +0,0 @@
|
||||
|
||||
"""
|
||||
Example of custom graph using existing nodes
|
||||
"""
|
||||
from scrapegraphai.nodes import FetchHTMLNode, ParseHTMLNode, GenerateAnswerNode
|
||||
from scrapegraphai.graphs import BaseGraph
|
||||
from scrapegraphai.models import OpenAI
|
||||
from scrapegraphai.helpers import nodes_metadata
|
||||
|
||||
OPENAI_API_KEY = "YOUR_API_KEY"
|
||||
|
||||
# check available nodes
|
||||
|
||||
nodes_metadata.keys()
|
||||
|
||||
# to get more information about a node
|
||||
print(nodes_metadata['ImageToTextNode'])
|
||||
|
||||
# Define the configuration for the language model
|
||||
llm_config = {
|
||||
"api_key": OPENAI_API_KEY,
|
||||
"model_name": "gpt-3.5-turbo",
|
||||
"temperature": 0,
|
||||
"streaming": True
|
||||
}
|
||||
model = OpenAI(llm_config)
|
||||
|
||||
# define the nodes for the graph
|
||||
fetch_html_node = FetchHTMLNode("fetch_html")
|
||||
parse_document_node = ParseHTMLNode("parse_document")
|
||||
generate_answer_node = GenerateAnswerNode(model, "generate_answer")
|
||||
|
||||
# create the graph
|
||||
graph = BaseGraph(
|
||||
nodes={
|
||||
fetch_html_node,
|
||||
parse_document_node,
|
||||
generate_answer_node
|
||||
},
|
||||
edges={
|
||||
(fetch_html_node, parse_document_node),
|
||||
(parse_document_node, generate_answer_node)
|
||||
},
|
||||
entry_point=fetch_html_node
|
||||
)
|
||||
|
||||
# execute the graph
|
||||
inputs = {"user_input": "What is the title of the page?",
|
||||
"url": "https://example.com"}
|
||||
result = graph.execute(inputs)
|
||||
|
||||
# get the answer from the result
|
||||
answer = result.get("answer", "No answer found.")
|
||||
print(answer)
|
||||
@ -1,23 +0,0 @@
|
||||
"""
|
||||
Example of graph building
|
||||
"""
|
||||
from scrapegraphai.builders import GraphBuilder
|
||||
OPENAI_API_KEY = "YOUR_API_KEY"
|
||||
|
||||
|
||||
llm_config = {
|
||||
"api_key": OPENAI_API_KEY,
|
||||
"model_name": "gpt-3.5-turbo",
|
||||
"temperature": 0,
|
||||
"streaming": True
|
||||
}
|
||||
|
||||
# Example usage of GraphBuilder
|
||||
USER_PROMPT = "Extract the news and generate a text summary with a voiceover."
|
||||
graph_builder = GraphBuilder(USER_PROMPT, llm_config)
|
||||
graph_json = graph_builder.build_graph()
|
||||
|
||||
# Convert the resulting JSON to Graphviz format
|
||||
graphviz_graph = graph_builder.convert_json_to_graphviz(graph_json)
|
||||
|
||||
print(graph_json)
|
||||
@ -1,17 +0,0 @@
|
||||
"""
|
||||
Basic example of scraping pipeline using SmartScraper
|
||||
"""
|
||||
from scrapegraphai.graphs import SmartScraperGraph
|
||||
OPENAI_API_KEY = "YOUR_API_KEY"
|
||||
|
||||
|
||||
llm_config = {
|
||||
"api_key": OPENAI_API_KEY,
|
||||
"model_name": "gpt-3.5-turbo",
|
||||
}
|
||||
|
||||
smart_scraper_graph = SmartScraperGraph("List me all the titles and project descriptions",
|
||||
"https://perinim.github.io/projects/", llm_config)
|
||||
|
||||
answer = smart_scraper_graph.run()
|
||||
print(answer["projects"][0])
|
||||
@ -1,20 +0,0 @@
|
||||
"""
|
||||
Basic example of scraping pipeline using SpeechSummaryGraph
|
||||
"""
|
||||
|
||||
from scrapegraphai.graphs import SpeechSummaryGraph
|
||||
OPENAI_API_KEY = "YOUR_API_KEY"
|
||||
|
||||
|
||||
llm_config = {
|
||||
"api_key": OPENAI_API_KEY
|
||||
}
|
||||
|
||||
# Save the audio to a file
|
||||
AUDIO_FILE = "website_summary.mp3"
|
||||
SPEECH_SUMMARY_GRAPH = SpeechSummaryGraph("Make a summary of the webpage to be converted to audio for blind people.",
|
||||
"https://perinim.github.io/projects/", llm_config,
|
||||
AUDIO_FILE)
|
||||
|
||||
final_state = SPEECH_SUMMARY_GRAPH.run()
|
||||
print(final_state.get("answer", "No answer found."))
|
||||
@ -1,3 +1,6 @@
|
||||
"""
|
||||
Module for evaluating the graph
|
||||
"""
|
||||
import os
|
||||
from scrapegraphai.evaluators import TrulensEvaluator
|
||||
from dotenv import load_dotenv
|
||||
@ -14,8 +17,10 @@ llm_config = {
|
||||
}
|
||||
|
||||
list_of_inputs = [
|
||||
("List me all the titles and project descriptions", "https://perinim.github.io/projects/", llm_config),
|
||||
("Who is the author of the project?", "https://perinim.github.io/projects/", llm_config),
|
||||
("List me all the titles and project descriptions",
|
||||
"https://perinim.github.io/projects/", llm_config),
|
||||
("Who is the author of the project?",
|
||||
"https://perinim.github.io/projects/", llm_config),
|
||||
("What is the project about?", "https://perinim.github.io/projects/", llm_config)
|
||||
]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user