-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.py
More file actions
90 lines (76 loc) · 3.22 KB
/
analytics.py
File metadata and controls
90 lines (76 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
analytics.py
This module contains functions to analyze inventory data using AI to generate insights, predict stock needs,
categorize products, and generate comprehensive reports.
"""
import google.generativeai as genai
from pandasai import Agent
def generate_insights(df):
"""
Generates key insights from the inventory data.
Args:
df (pd.DataFrame): The inventory data.
Returns:
str: Generated insights.
"""
description = (
"You are an expert in Data Analysis. Your main aim is to help non-technical people understand "
"the insights and data analysis of the product inventory and product trends."
)
insights_prompt = "Analyze this inventory data and provide key insights about stock levels, popular categories, and pricing trends."
insights_agent = genai.Agent(df, description=description)
insights = insights_agent.chat(insights_prompt)
return insights
def predict_stock_needs(df):
"""
Predicts which products are likely to run out of stock in the next month.
Args:
df (pd.DataFrame): The inventory data.
Returns:
str: Stock predictions.
"""
description = (
"You are an expert in Data Analysis. Your main aim is to help non-technical people understand "
"the insights and data analysis of the product inventory and product trends."
)
prediction_prompt = "Based on the current inventory data, predict which products are likely to run out of stock in the next month. Consider historical sales data if available."
predictions_agent = genai.Agent(df, description=description)
predictions = predictions_agent.chat(prediction_prompt)
return predictions
def categorize_product(df, product_name, product_description):
"""
Categorizes a product based on its name and description.
Args:
df (pd.DataFrame): The inventory data.
product_name (str): The product name.
product_description (str): The product description.
Returns:
str: The category of the product.
"""
description = (
"You are an expert in Data Analysis. Your main aim is to help non-technical people understand "
"the insights and data analysis of the product inventory and product trends."
)
categorization_prompt = f"Categorize this product: Name: {product_name}, Description: {product_description}"
category_agent = genai.Agent(df, description=description)
category = category_agent.chat(categorization_prompt)
return category
def generate_report(df):
"""
Generates a comprehensive inventory report.
Args:
df (pd.DataFrame): The inventory data.
Returns:
str: The inventory report.
"""
description = (
"You are an expert in Data Analysis. Your main aim is to help non-technical people understand "
"the insights and data analysis of the product inventory and product trends."
)
report_prompt = (
"Generate a comprehensive inventory report. Include total inventory value, top-selling products, "
"low stock alerts, and any notable trends."
)
report_agent = genai.Agent(df, description=description)
report = report_agent.chat(report_prompt)
return report