Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -336,162 +336,66 @@ def analyze_statements(income_statement, balance_sheet):
|
|
336 |
3. Use consistent number formatting
|
337 |
4. Are not corrupted"""
|
338 |
|
339 |
-
# Create Gradio interface with
|
340 |
iface = gr.Interface(
|
341 |
fn=analyze_statements,
|
342 |
inputs=[
|
343 |
gr.File(
|
344 |
label="Upload Income Statement (CSV)",
|
345 |
file_types=[".csv"],
|
346 |
-
file_count="single"
|
347 |
-
info="Upload your income statement in CSV format"
|
348 |
),
|
349 |
gr.File(
|
350 |
label="Upload Balance Sheet (CSV)",
|
351 |
file_types=[".csv"],
|
352 |
-
file_count="single"
|
353 |
-
info="Upload your balance sheet in CSV format"
|
354 |
-
)
|
355 |
-
],
|
356 |
-
outputs=[
|
357 |
-
gr.Markdown(
|
358 |
-
label="Financial Analysis Report",
|
359 |
-
show_label=True
|
360 |
)
|
361 |
],
|
|
|
362 |
title="Advanced Financial Statement Analyzer",
|
363 |
description="""## Professional Financial Analysis Tool
|
364 |
|
365 |
-
### Key Features:
|
366 |
-
- Comprehensive financial analysis using AI
|
367 |
-
- Sentiment analysis of financial performance
|
368 |
-
- Key ratio calculations and trend analysis
|
369 |
-
- Strategic recommendations
|
370 |
-
|
371 |
### Supported Financial Statement Formats:
|
372 |
|
373 |
-
#### Income Statement
|
374 |
- Revenue/Sales information
|
375 |
- Cost and Expense details
|
376 |
- Profit/Income figures
|
377 |
- Operating metrics
|
378 |
- Period/Year information
|
379 |
|
380 |
-
#### Balance Sheet
|
381 |
- Asset information (Current & Non-current)
|
382 |
- Liability details (Current & Long-term)
|
383 |
- Equity components
|
384 |
- Period/Year information
|
385 |
|
386 |
-
### Analysis Output:
|
387 |
1. Overall Financial Health Assessment
|
388 |
2. Key Performance Metrics & Ratios
|
389 |
3. Trend Analysis
|
390 |
4. Risk Assessment
|
391 |
5. Strategic Recommendations
|
392 |
-
""",
|
393 |
-
article="""### Usage Tips:
|
394 |
-
1. Ensure your CSV files are properly formatted
|
395 |
-
2. Data should be in chronological order
|
396 |
-
3. Numbers can include commas and currency symbols
|
397 |
-
4. Negative numbers can be in parentheses
|
398 |
-
5. Common headers will be automatically recognized
|
399 |
|
400 |
-
###
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
""",
|
406 |
-
|
407 |
-
["sample_income_statement.csv", "sample_balance_sheet.csv"]
|
408 |
-
],
|
409 |
-
theme=gr.themes.Soft(
|
410 |
-
primary_hue="blue",
|
411 |
-
secondary_hue="purple",
|
412 |
-
),
|
413 |
-
css="""
|
414 |
-
.gradio-container {
|
415 |
-
font-family: 'IBM Plex Sans', sans-serif;
|
416 |
-
}
|
417 |
-
.gr-button {
|
418 |
-
color: white;
|
419 |
-
border-radius: 8px;
|
420 |
-
background: linear-gradient(45deg, #1f6feb, #4688f1);
|
421 |
-
}
|
422 |
-
.gr-button:hover {
|
423 |
-
background: linear-gradient(45deg, #1856c5, #3b78e7);
|
424 |
-
}
|
425 |
-
.gr-form {
|
426 |
-
border-radius: 12px;
|
427 |
-
background: white;
|
428 |
-
padding: 24px;
|
429 |
-
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
|
430 |
-
}
|
431 |
-
.gr-box {
|
432 |
-
border-radius: 8px;
|
433 |
-
}
|
434 |
-
"""
|
435 |
)
|
436 |
|
437 |
-
# Add custom error handling
|
438 |
-
def custom_error_handler(err):
|
439 |
-
logger.error(f"Application error: {str(err)}")
|
440 |
-
return """### Error in Analysis
|
441 |
-
|
442 |
-
An error occurred while processing your financial statements. Please check:
|
443 |
-
1. File format is correct CSV
|
444 |
-
2. Contains required financial metrics
|
445 |
-
3. Data is properly formatted
|
446 |
-
4. No corrupted or missing values
|
447 |
-
|
448 |
-
If the problem persists, try:
|
449 |
-
- Removing any special formatting
|
450 |
-
- Ensuring consistent date/period format
|
451 |
-
- Checking for missing required fields
|
452 |
-
|
453 |
-
Error details: {str(err)}
|
454 |
-
"""
|
455 |
-
|
456 |
-
iface.error_handler = custom_error_handler
|
457 |
-
|
458 |
# Launch configurations
|
459 |
-
|
460 |
try:
|
461 |
-
#
|
462 |
-
|
463 |
-
|
464 |
-
# Configure Gradio
|
465 |
-
gr.close_all()
|
466 |
-
|
467 |
-
# Launch with custom configurations
|
468 |
-
iface.queue(concurrency_count=1)
|
469 |
iface.launch(
|
470 |
server_name="0.0.0.0",
|
471 |
server_port=7860,
|
472 |
-
share=False
|
473 |
-
enable_queue=True,
|
474 |
-
max_threads=4,
|
475 |
-
auth=None, # Add authentication if needed
|
476 |
-
ssl_keyfile=None, # Add SSL if needed
|
477 |
-
ssl_certfile=None,
|
478 |
-
ssl_keyfile_password=None,
|
479 |
-
show_error=True,
|
480 |
-
show_tips=True,
|
481 |
-
analytics_enabled=False,
|
482 |
-
debug=False
|
483 |
)
|
484 |
-
|
485 |
except Exception as e:
|
486 |
logger.error(f"Launch error: {str(e)}")
|
487 |
-
|
488 |
-
|
489 |
-
if __name__ == "__main__":
|
490 |
-
try:
|
491 |
-
main()
|
492 |
-
except KeyboardInterrupt:
|
493 |
-
logger.info("Shutting down gracefully...")
|
494 |
-
gr.close_all()
|
495 |
-
except Exception as e:
|
496 |
-
logger.error(f"Fatal error: {str(e)}")
|
497 |
-
sys.exit(1)
|
|
|
336 |
3. Use consistent number formatting
|
337 |
4. Are not corrupted"""
|
338 |
|
339 |
+
# Create Gradio interface with compatible parameters
|
340 |
iface = gr.Interface(
|
341 |
fn=analyze_statements,
|
342 |
inputs=[
|
343 |
gr.File(
|
344 |
label="Upload Income Statement (CSV)",
|
345 |
file_types=[".csv"],
|
346 |
+
file_count="single"
|
|
|
347 |
),
|
348 |
gr.File(
|
349 |
label="Upload Balance Sheet (CSV)",
|
350 |
file_types=[".csv"],
|
351 |
+
file_count="single"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
)
|
353 |
],
|
354 |
+
outputs=gr.Markdown(),
|
355 |
title="Advanced Financial Statement Analyzer",
|
356 |
description="""## Professional Financial Analysis Tool
|
357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
### Supported Financial Statement Formats:
|
359 |
|
360 |
+
#### Income Statement Requirements:
|
361 |
- Revenue/Sales information
|
362 |
- Cost and Expense details
|
363 |
- Profit/Income figures
|
364 |
- Operating metrics
|
365 |
- Period/Year information
|
366 |
|
367 |
+
#### Balance Sheet Requirements:
|
368 |
- Asset information (Current & Non-current)
|
369 |
- Liability details (Current & Long-term)
|
370 |
- Equity components
|
371 |
- Period/Year information
|
372 |
|
373 |
+
### Analysis Output Includes:
|
374 |
1. Overall Financial Health Assessment
|
375 |
2. Key Performance Metrics & Ratios
|
376 |
3. Trend Analysis
|
377 |
4. Risk Assessment
|
378 |
5. Strategic Recommendations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
379 |
|
380 |
+
### Usage Instructions:
|
381 |
+
1. Upload your Income Statement CSV file
|
382 |
+
2. Upload your Balance Sheet CSV file
|
383 |
+
3. Wait for the analysis to complete
|
384 |
+
4. Review the comprehensive financial analysis report
|
385 |
""",
|
386 |
+
theme="default"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
387 |
)
|
388 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
389 |
# Launch configurations
|
390 |
+
if __name__ == "__main__":
|
391 |
try:
|
392 |
+
# Configure and launch
|
393 |
+
iface.queue()
|
|
|
|
|
|
|
|
|
|
|
|
|
394 |
iface.launch(
|
395 |
server_name="0.0.0.0",
|
396 |
server_port=7860,
|
397 |
+
share=False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
398 |
)
|
|
|
399 |
except Exception as e:
|
400 |
logger.error(f"Launch error: {str(e)}")
|
401 |
+
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|