Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions scrapegraphai/graphs/abstract_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,12 @@ def _create_llm(self, llm_config: dict) -> object:
If possible, try to use a model instance instead."""
)
llm_params["model_provider"] = possible_providers[0]
print(
(
f"Found providers {possible_providers} for model {llm_params['model']}, using {llm_params['model_provider']}.\n"
"If it was not intended please specify the model provider in the graph configuration"
)
logger.info(
"Found providers %s for model %s, using %s. "
"If it was not intended please specify the model provider in the graph configuration",
possible_providers,
llm_params["model"],
llm_params["model_provider"],
)

if llm_params["model_provider"] not in known_providers:
Expand All @@ -209,10 +210,12 @@ def _create_llm(self, llm_config: dict) -> object:
llm_params["model"]
]
except KeyError:
print(
f"""Max input tokens for model {llm_params["model_provider"]}/{llm_params["model"]} not found,
please specify the model_tokens parameter in the llm section of the graph configuration.
Using default token size: 8192"""
logger.warning(
"Max input tokens for model %s/%s not found, "
"please specify the model_tokens parameter in the llm section of the graph configuration. "
"Using default token size: 8192",
llm_params["model_provider"],
llm_params["model"],
)
self.model_token = 8192
else:
Expand Down
12 changes: 5 additions & 7 deletions scrapegraphai/graphs/base_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,16 @@ def execute(self, initial_state: dict) -> Tuple[dict, list]:
else:
state, exec_info = self._execute_standard(initial_state)

# Print the result first
if "answer" in state:
print(state["answer"])
logger.info(state["answer"])
elif "parsed_doc" in state:
print(state["parsed_doc"])
logger.info(state["parsed_doc"])
elif "generated_code" in state:
print(state["generated_code"])
logger.info(state["generated_code"])
elif "merged_script" in state:
print(state["merged_script"])
logger.info(state["merged_script"])

# Then show the message ONLY ONCE
print(f"✨ Try enhanced version of ScrapegraphAI at {CLICKABLE_URL} ✨")
logger.info("✨ Try enhanced version of ScrapegraphAI at %s ✨", CLICKABLE_URL)

return state, exec_info

Expand Down
5 changes: 4 additions & 1 deletion scrapegraphai/graphs/speech_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

from ..models import OpenAITextToSpeech
from ..nodes import FetchNode, GenerateAnswerNode, ParseNode, TextToSpeechNode
from ..utils.logging import get_logger
from ..utils.save_audio_from_bytes import save_audio_from_bytes
from .abstract_graph import AbstractGraph
from .base_graph import BaseGraph

logger = get_logger(__name__)


class SpeechGraph(AbstractGraph):
"""
Expand Down Expand Up @@ -112,6 +115,6 @@ def run(self) -> str:
if not audio:
raise ValueError("No audio generated from the text.")
save_audio_from_bytes(audio, self.config.get("output_path", "output.mp3"))
print(f"Audio saved to {self.config.get('output_path', 'output.mp3')}")
logger.info("Audio saved to %s", self.config.get("output_path", "output.mp3"))

return self.final_state.get("answer", "No answer found.")
8 changes: 6 additions & 2 deletions scrapegraphai/integrations/burr_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import uuid
from typing import Any, Dict, List, Tuple

from ..utils.logging import get_logger

logger = get_logger(__name__)

try:
from burr import tracking
from burr.core import (
Expand All @@ -32,10 +36,10 @@ class PrintLnHook(PostRunStepHook, PreRunStepHook):
"""

def pre_run_step(self, *, state: "State", action: "Action", **future_kwargs: Any):
print(f"Starting action: {action.name}")
logger.debug("Starting action: %s", action.name)

def post_run_step(self, *, state: "State", action: "Action", **future_kwargs: Any):
print(f"Finishing action: {action.name}")
logger.debug("Finishing action: %s", action.name)


class BurrNodeBridge(Action):
Expand Down
12 changes: 8 additions & 4 deletions scrapegraphai/utils/data_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import xml.etree.ElementTree as ET
from typing import Any, Dict, List

from .logging import get_logger

logger = get_logger(__name__)


def export_to_json(data: List[Dict[str, Any]], filename: str) -> None:
"""
Expand All @@ -18,7 +22,7 @@ def export_to_json(data: List[Dict[str, Any]], filename: str) -> None:
"""
with open(filename, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=4)
print(f"Data exported to {filename}")
logger.info("Data exported to %s", filename)


def export_to_csv(data: List[Dict[str, Any]], filename: str) -> None:
Expand All @@ -29,15 +33,15 @@ def export_to_csv(data: List[Dict[str, Any]], filename: str) -> None:
:param filename: Name of the file to save the CSV data
"""
if not data:
print("No data to export")
logger.warning("No data to export")
return

keys = data[0].keys()
with open(filename, "w", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=keys)
writer.writeheader()
writer.writerows(data)
print(f"Data exported to {filename}")
logger.info("Data exported to %s", filename)


def export_to_xml(
Expand All @@ -59,4 +63,4 @@ def export_to_xml(

tree = ET.ElementTree(root)
tree.write(filename, encoding="utf-8", xml_declaration=True)
print(f"Data exported to {filename}")
logger.info("Data exported to %s", filename)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import numpy as np
from playwright.async_api import async_playwright

from ..logging import get_logger

logger = get_logger(__name__)


async def take_screenshot(url: str, save_path: str = None, quality: int = 100):
"""
Expand Down Expand Up @@ -155,7 +159,7 @@ def select_area_with_ipywidget(image):

img_array = np.array(image)

print(img_array.shape)
logger.debug("Image array shape: %s", img_array.shape)

def update_plot(top_bottom, left_right, image_size):
plt.figure(figsize=(image_size, image_size))
Expand Down
Loading