Skip to content

Commit 3640434

Browse files
committed
add utils
1 parent 60a2377 commit 3640434

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

examples/local_models/Ollama/smart_scraper_ollama.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Basic example of scraping pipeline using SmartScraper
33
"""
44
from scrapegraphai.graphs import SmartScraperGraph
5-
5+
from scrapegraphai.utils import prettify_exec_info
66
# ************************************************
77
# Define the configuration for the graph
88
# ************************************************
@@ -35,3 +35,10 @@
3535

3636
result = smart_scraper_graph.run()
3737
print(result)
38+
39+
# ************************************************
40+
# Get graph execution info
41+
# ************************************************
42+
43+
graph_exec_info = smart_scraper_graph.get_execution_info()
44+
print(prettify_exec_info(graph_exec_info))

scrapegraphai/utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
from .save_audio_from_bytes import save_audio_from_bytes
55
from .convert_to_csv import convert_to_csv
66
from .convert_to_json import convert_to_json
7+
from .prettify_exec_info import prettify_exec_info
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
Prettify the execution information of the graph.
3+
"""
4+
5+
import pandas as pd
6+
7+
8+
def prettify_exec_info(complete_result: dict) -> pd.DataFrame:
9+
"""
10+
Transform the execution information of the graph into a DataFrame for better visualization.
11+
12+
Args:
13+
- complete_result (dict): The complete execution information of the graph.
14+
15+
Returns:
16+
- pd.DataFrame: The execution information of the graph in a DataFrame.
17+
"""
18+
19+
nodes_info = complete_result['nodes_info']
20+
total_info = {
21+
'total_exec_time': complete_result['total_exec_time'],
22+
'total_model_info': complete_result['total_model_info']
23+
}
24+
25+
# Convert node-specific information to DataFrame
26+
flat_data = []
27+
for node_name, node_info in nodes_info.items():
28+
flat_data.append({
29+
'Node': node_name,
30+
'Execution Time': node_info['exec_time'],
31+
# Unpack the model_info dict into the row
32+
**node_info['model_info']
33+
})
34+
35+
df_nodes = pd.DataFrame(flat_data)
36+
37+
# Add a row for the total execution time and total model info
38+
total_row = {
39+
'Node': 'Total',
40+
'Execution Time': total_info['total_exec_time'],
41+
# Unpack the total_model_info dict into the row
42+
**total_info['total_model_info']
43+
}
44+
df_total = pd.DataFrame([total_row])
45+
46+
# Combine the nodes DataFrame with the total info DataFrame
47+
df_combined_with_total = pd.concat([df_nodes, df_total], ignore_index=True)
48+
return df_combined_with_total

0 commit comments

Comments
 (0)