Download plugins/outputs/chart_generator.py from JatinAutonomousLabs/Excel_AI_Assistant: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/JatinAutonomousLabs/Excel_AI_Assistant/resolve/main/plugins/outputs/chart_generator.py
- Command line
-
hf download hf://spaces/JatinAutonomousLabs/Excel_AI_Assistant/plugins/outputs/chart_generator.py
-
curl -L -o chart_generator.py https://huggingface.co/spaces/JatinAutonomousLabs/Excel_AI_Assistant/resolve/main/plugins/outputs/chart_generator.py
1.31 kB
| #!/usr/bin/env python3 | |
| """Chart Generation Plugin""" | |
| import plotly.express as px | |
| import plotly.graph_objects as go | |
| from typing import Dict, Any | |
| import pandas as pd | |
| import json | |
| class ChartGenerator: | |
| """Generate interactive charts.""" | |
| def create_chart_html(self, data: pd.DataFrame, chart_type: str, x: str, y: str = None, | |
| title: str = "Chart", color: str = None, **kwargs) -> str: | |
| if data.empty or x not in data.columns: | |
| return json.dumps({"error": "Invalid data"}) | |
| try: | |
| if chart_type == "bar": | |
| fig = px.bar(data, x=x, y=y, title=title, color=color, **kwargs) | |
| elif chart_type == "line": | |
| fig = px.line(data, x=x, y=y, title=title, color=color, **kwargs) | |
| elif chart_type == "scatter": | |
| fig = px.scatter(data, x=x, y=y, title=title, color=color, **kwargs) | |
| elif chart_type == "pie": | |
| fig = px.pie(data, names=x, values=y, title=title, **kwargs) | |
| else: | |
| fig = px.bar(data, x=x, y=y, title=title) | |
| fig.update_layout(template="plotly_white", height=400) | |
| return fig.to_json() | |
| except Exception as e: | |
| return json.dumps({"error": str(e)}) | |