Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -93,9 +93,9 @@ class FinancialAnalyzer:
|
|
93 |
|
94 |
def extract_metrics(self, income_data, balance_data):
|
95 |
"""Extract and calculate key financial metrics"""
|
96 |
-
|
97 |
# Get current and previous year values for growth calculations
|
98 |
-
|
99 |
"Revenue": {
|
100 |
"2025": self.get_nested_value(income_data, "Revenue", "Total Net Revenue", "2025"),
|
101 |
"2024": self.get_nested_value(income_data, "Revenue", "Total Net Revenue", "2024"),
|
@@ -124,8 +124,8 @@ class FinancialAnalyzer:
|
|
124 |
}
|
125 |
|
126 |
# Calculate financial ratios
|
127 |
-
|
128 |
-
|
129 |
# Profitability Ratios
|
130 |
metrics["Ratios"] = {
|
131 |
"Gross_Margin": (metrics["Profitability"]["Gross_Profit_2025"] / revenue_2025) * 100,
|
@@ -149,10 +149,10 @@ class FinancialAnalyzer:
|
|
149 |
"5Year_Revenue_CAGR": ((metrics["Revenue"]["2025"] / metrics["Revenue"]["2021"]) ** (1/4) - 1) * 100
|
150 |
}
|
151 |
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
|
157 |
def generate_analysis(self, prompt):
|
158 |
"""Generate analysis using TinyLlama"""
|
|
|
93 |
|
94 |
def extract_metrics(self, income_data, balance_data):
|
95 |
"""Extract and calculate key financial metrics"""
|
96 |
+
try:
|
97 |
# Get current and previous year values for growth calculations
|
98 |
+
metrics = {
|
99 |
"Revenue": {
|
100 |
"2025": self.get_nested_value(income_data, "Revenue", "Total Net Revenue", "2025"),
|
101 |
"2024": self.get_nested_value(income_data, "Revenue", "Total Net Revenue", "2024"),
|
|
|
124 |
}
|
125 |
|
126 |
# Calculate financial ratios
|
127 |
+
revenue_2025 = metrics["Revenue"]["2025"]
|
128 |
+
if revenue_2025 != 0:
|
129 |
# Profitability Ratios
|
130 |
metrics["Ratios"] = {
|
131 |
"Gross_Margin": (metrics["Profitability"]["Gross_Profit_2025"] / revenue_2025) * 100,
|
|
|
149 |
"5Year_Revenue_CAGR": ((metrics["Revenue"]["2025"] / metrics["Revenue"]["2021"]) ** (1/4) - 1) * 100
|
150 |
}
|
151 |
|
152 |
+
return metrics
|
153 |
+
except Exception as e:
|
154 |
+
print(f"Error extracting metrics: {str(e)}")
|
155 |
+
return {}
|
156 |
|
157 |
def generate_analysis(self, prompt):
|
158 |
"""Generate analysis using TinyLlama"""
|