-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsight_generator.py
More file actions
58 lines (49 loc) · 2.17 KB
/
Copy pathinsight_generator.py
File metadata and controls
58 lines (49 loc) · 2.17 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
import os
import time
import pandas as pd
from groq import Groq
from dotenv import load_dotenv
load_dotenv()
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
# ── 1. Load Data ───────────────────────────────────────────
def load_data(csv_path):
df = pd.read_csv(csv_path)
print(f"✅ Loaded {len(df)} rows and {len(df.columns)} columns")
print(f" Columns: {list(df.columns)}\n")
return df
# ── 2. Generate Report ─────────────────────────────────────
def generate_report(df, report_type="executive summary", custom_focus=""):
print(f"⏳ Generating {report_type} report...")
response = client.chat.completions.create(
model="llama-3.3-70b-versatile",
messages=[
{
"role": "system",
"content": "You are an elite business intelligence analyst. Structure reports with: Data Overview, Key Findings, Trend Analysis, Risk Signals, Recommendations, Executive Takeaway."
},
{
"role": "user",
"content": f"""Generate a {report_type} report.
Stats:
{df.describe().round(1).to_string()}
{f'Focus: {custom_focus}' if custom_focus else ''}"""
}
]
)
return response.choices[0].message.content
# ── 3. Save Report ─────────────────────────────────────────
def save_report(report, filename="report_output.md"):
with open(filename, "w") as f:
f.write(report)
print(f"✅ Report saved to {filename}")
# ── 4. Run ─────────────────────────────────────────────────
if __name__ == "__main__":
CSV_FILE = "data.csv"
REPORT_TYPE = "executive summary"
FOCUS = "Focus on regional performance gaps"
df = load_data(CSV_FILE)
report = generate_report(df, REPORT_TYPE, FOCUS)
print("\n" + "="*60)
print(report)
print("="*60 + "\n")
save_report(report)