Spaces:
Sleeping
Sleeping
Download tools/plot_generator.py from mgbam/BizIntel_AI: direct link, hf CLI and curl.
- Browser
- Download file 893 Bytes
-
https://huggingface.co/spaces/mgbam/BizIntel_AI/resolve/8a0173b3cd992857ab21632827e4ce5383feb481/tools/plot_generator.py
- Command line
-
hf download hf://spaces/mgbam/BizIntel_AI@8a0173b3cd992857ab21632827e4ce5383feb481/tools/plot_generator.py
-
curl -L -o plot_generator.py https://huggingface.co/spaces/mgbam/BizIntel_AI/resolve/8a0173b3cd992857ab21632827e4ce5383feb481/tools/plot_generator.py
893 Bytes
| import pandas as pd | |
| import plotly.graph_objects as go | |
| def plot_metric_tool(file_path: str, date_col: str, value_col: str): | |
| """ | |
| Generic interactive line chart for any numeric metric. | |
| Returns a Plotly Figure or error message string. | |
| """ | |
| df = pd.read_csv(file_path) | |
| if date_col not in df.columns or value_col not in df.columns: | |
| return f"❌ '{date_col}' or '{value_col}' column missing." | |
| df[date_col] = pd.to_datetime(df[date_col], errors="coerce") | |
| if df[date_col].isna().all(): | |
| return f"❌ '{date_col}' could not be parsed as dates." | |
| fig = go.Figure( | |
| go.Scatter( | |
| x=df[date_col], | |
| y=df[value_col], | |
| mode="lines+markers", | |
| line=dict(width=2), | |
| ) | |
| ) | |
| fig.update_layout(title=f"{value_col} Trend", template="plotly_dark") | |
| fig.write_image("metric_plot.png") | |
| return fig | |