Spaces:
Sleeping
Sleeping
Update app.py
#3
by
Inni-23
- opened
app.py
CHANGED
@@ -34,6 +34,16 @@ class FinancialAnalyzer:
|
|
34 |
except:
|
35 |
return 0.0
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
def parse_financial_data(self, content):
|
38 |
"""Parse markdown content into structured data"""
|
39 |
try:
|
@@ -122,7 +132,8 @@ class FinancialAnalyzer:
|
|
122 |
def generate_analysis_prompt(self, metrics):
|
123 |
"""Create analysis prompt from metrics"""
|
124 |
try:
|
125 |
-
return f"""<human>
|
|
|
126 |
|
127 |
Revenue and Profitability:
|
128 |
- Total Revenue: ${metrics['Revenue']['2025']:,.1f}M
|
@@ -136,10 +147,8 @@ Balance Sheet Strength:
|
|
136 |
- Total Liabilities: ${metrics['Balance_Sheet']['Total_Liabilities_2025']:,.1f}M
|
137 |
- Shareholders' Equity: ${metrics['Balance_Sheet']['Equity_2025']:,.1f}M
|
138 |
|
139 |
-
|
140 |
-
|
141 |
-
2. Key Strengths and Weaknesses
|
142 |
-
3. Strategic Recommendations</human>"""
|
143 |
except Exception as e:
|
144 |
print(f"Error generating prompt: {str(e)}")
|
145 |
return ""
|
@@ -169,6 +178,10 @@ Provide a concise analysis of:
|
|
169 |
def analyze_financials(self, balance_sheet_file, income_stmt_file):
|
170 |
"""Main analysis function"""
|
171 |
try:
|
|
|
|
|
|
|
|
|
172 |
# Read files
|
173 |
with open(balance_sheet_file, 'r') as f:
|
174 |
balance_sheet = f.read()
|
@@ -219,4 +232,4 @@ def create_interface():
|
|
219 |
|
220 |
if __name__ == "__main__":
|
221 |
iface = create_interface()
|
222 |
-
iface.launch()
|
|
|
34 |
except:
|
35 |
return 0.0
|
36 |
|
37 |
+
def is_valid_markdown(self, file_path):
|
38 |
+
"""Check if a file is a valid Markdown file"""
|
39 |
+
try:
|
40 |
+
with open(file_path, 'r') as f:
|
41 |
+
content = f.read()
|
42 |
+
# Simple check for Markdown structure
|
43 |
+
return any(line.startswith('#') or '|' in line for line in content.split('\n'))
|
44 |
+
except:
|
45 |
+
return False
|
46 |
+
|
47 |
def parse_financial_data(self, content):
|
48 |
"""Parse markdown content into structured data"""
|
49 |
try:
|
|
|
132 |
def generate_analysis_prompt(self, metrics):
|
133 |
"""Create analysis prompt from metrics"""
|
134 |
try:
|
135 |
+
return f"""<human>
|
136 |
+
Analyze these financial metrics for 2025 with a focus on business performance, trends, and risks:
|
137 |
|
138 |
Revenue and Profitability:
|
139 |
- Total Revenue: ${metrics['Revenue']['2025']:,.1f}M
|
|
|
147 |
- Total Liabilities: ${metrics['Balance_Sheet']['Total_Liabilities_2025']:,.1f}M
|
148 |
- Shareholders' Equity: ${metrics['Balance_Sheet']['Equity_2025']:,.1f}M
|
149 |
|
150 |
+
Explain key financial ratios and their implications. Discuss strategies for growth and risk mitigation.
|
151 |
+
</human>"""
|
|
|
|
|
152 |
except Exception as e:
|
153 |
print(f"Error generating prompt: {str(e)}")
|
154 |
return ""
|
|
|
178 |
def analyze_financials(self, balance_sheet_file, income_stmt_file):
|
179 |
"""Main analysis function"""
|
180 |
try:
|
181 |
+
# Validate files
|
182 |
+
if not (self.is_valid_markdown(balance_sheet_file) and self.is_valid_markdown(income_stmt_file)):
|
183 |
+
return "Error: One or both files are invalid or not in Markdown format."
|
184 |
+
|
185 |
# Read files
|
186 |
with open(balance_sheet_file, 'r') as f:
|
187 |
balance_sheet = f.read()
|
|
|
232 |
|
233 |
if __name__ == "__main__":
|
234 |
iface = create_interface()
|
235 |
+
iface.launch()
|