Spaces:
Sleeping
Sleeping
Download scripts/financial_utils.py from Shivam4096/FinancialAnalyzer: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/Shivam4096/FinancialAnalyzer/resolve/main/scripts/financial_utils.py
- Command line
-
hf download hf://spaces/Shivam4096/FinancialAnalyzer/scripts/financial_utils.py
-
curl -L -o financial_utils.py https://huggingface.co/spaces/Shivam4096/FinancialAnalyzer/resolve/main/scripts/financial_utils.py
1.17 kB
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import io | |
| from docx import Document | |
| from docx.shared import Inches | |
| def format_indian_units(value): | |
| """Converts a number to Crores or Lakhs string.""" | |
| try: | |
| val = float(value) | |
| if abs(val) >= 10**7: | |
| return f"{val / 10**7:.2f} Cr" | |
| elif abs(val) >= 10**5: | |
| return f"{val / 10**5:.2f} L" | |
| else: | |
| return f"{val:,.2f}" | |
| except (ValueError, TypeError): | |
| return value | |
| def create_styled_chart(df, title, ylabel, filename): | |
| """Creates a professional financial chart.""" | |
| plt.figure(figsize=(10, 6)) | |
| plt.style.use('ggplot') | |
| df.plot(kind='bar', ax=plt.gca()) | |
| plt.title(title, fontsize=14, fontweight='bold') | |
| plt.ylabel(ylabel) | |
| plt.xticks(rotation=45) | |
| plt.tight_layout() | |
| plt.savefig(filename, dpi=300) | |
| plt.close() | |
| def add_paragraph_with_insights(doc, heading, content): | |
| """Adds a heading and a multi-paragraph insight block.""" | |
| doc.add_heading(heading, level=2) | |
| doc.add_paragraph(content) | |
| # This script can be imported or used as a template by the agent. | |