Spaces:
Sleeping
Sleeping
Update tools/plot_generator.py
Browse files- tools/plot_generator.py +22 -11
tools/plot_generator.py
CHANGED
@@ -1,14 +1,25 @@
|
|
1 |
-
|
2 |
import pandas as pd
|
3 |
-
import
|
4 |
|
5 |
-
def plot_sales_tool(file_path: str) -> str:
|
|
|
|
|
|
|
|
|
6 |
df = pd.read_csv(file_path)
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import pandas as pd
|
2 |
+
import plotly.graph_objects as go
|
3 |
|
4 |
+
def plot_sales_tool(file_path: str, date_col: str = "Month") -> str:
|
5 |
+
"""
|
6 |
+
Builds an interactive Plotly line chart for Sales.
|
7 |
+
Saves a PNG fallback (sales_plot.png) for Streamlit thumbnail.
|
8 |
+
"""
|
9 |
df = pd.read_csv(file_path)
|
10 |
+
|
11 |
+
if date_col not in df.columns or "Sales" not in df.columns:
|
12 |
+
return f"❌ '{date_col}' or 'Sales' column missing."
|
13 |
+
|
14 |
+
fig = go.Figure(
|
15 |
+
go.Scatter(
|
16 |
+
x=df[date_col],
|
17 |
+
y=df["Sales"],
|
18 |
+
mode="lines+markers",
|
19 |
+
line=dict(width=2),
|
20 |
+
)
|
21 |
+
)
|
22 |
+
fig.update_layout(title="Sales Trend", template="plotly_dark")
|
23 |
+
fig.write_image("sales_plot.png") # still save for PNG fallback
|
24 |
+
|
25 |
+
return fig
|