walaa2022 commited on
Commit
5739b4d
·
verified ·
1 Parent(s): 4f051d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -28
app.py CHANGED
@@ -333,32 +333,32 @@ Provide:
333
 
334
  return "Key Recommendations:\n" + "\n".join(recommendations)
335
 
336
- def analyze_financials(self, balance_sheet_file, income_stmt_file):
337
  """Main analysis function"""
338
- try:
339
  # Validate input files
340
- if not (self.is_valid_markdown(balance_sheet_file) and self.is_valid_markdown(income_stmt_file)):
341
- return "Error: One or both files are invalid or not in Markdown format."
342
 
343
  # Read files
344
- with open(balance_sheet_file, 'r') as f:
345
- balance_sheet = f.read()
346
- with open(income_stmt_file, 'r') as f:
347
- income_stmt = f.read()
348
 
349
  # Process financial data
350
- income_data = self.parse_financial_data(income_stmt)
351
- balance_data = self.parse_financial_data(balance_sheet)
352
 
353
  # Calculate metrics
354
- metrics = self.calculate_metrics(income_data, balance_data)
355
- self.last_metrics = metrics
356
 
357
  # Generate analysis
358
- analysis = self.generate_analysis(metrics)
359
 
360
  # Prepare final results
361
- results = {
362
  "Financial Analysis": {
363
  "Key Metrics": {
364
  "Profitability": {
@@ -385,19 +385,19 @@ Provide:
385
  }
386
  }
387
 
388
- return json.dumps(results, indent=2)
389
 
390
- except Exception as e:
391
- return f"Error in analysis: {str(e)}\n\nDetails: {type(e).__name__}"
392
 
393
- def fine_tune_models(self, train_texts, train_labels, epochs=3):
394
  """Fine-tune the model with custom data"""
395
- try:
396
  # Prepare dataset
397
- train_dataset = FinancialDataset(train_texts, train_labels, self.llama_tokenizer)
398
 
399
  # Training arguments
400
- training_args = TrainingArguments(
401
  output_dir="./financial_model_tuned",
402
  num_train_epochs=epochs,
403
  per_device_train_batch_size=4,
@@ -411,22 +411,22 @@ Provide:
411
  )
412
 
413
  # Initialize trainer
414
- trainer = Trainer(
415
  model=self.llama_model,
416
  args=training_args,
417
  train_dataset=train_dataset
418
  )
419
 
420
  # Fine-tune the model
421
- trainer.train()
422
 
423
  # Save the fine-tuned model
424
- self.llama_model.save_pretrained("./financial_model_tuned")
425
- self.llama_tokenizer.save_pretrained("./financial_model_tuned")
426
 
427
- print("Fine-tuning completed successfully!")
428
- except Exception as e:
429
- print(f"Error in fine-tuning: {str(e)}")
430
 
431
 
432
 
 
333
 
334
  return "Key Recommendations:\n" + "\n".join(recommendations)
335
 
336
+ def analyze_financials(self, balance_sheet_file, income_stmt_file):
337
  """Main analysis function"""
338
+ try:
339
  # Validate input files
340
+ if not (self.is_valid_markdown(balance_sheet_file) and self.is_valid_markdown(income_stmt_file)):
341
+ return "Error: One or both files are invalid or not in Markdown format."
342
 
343
  # Read files
344
+ with open(balance_sheet_file, 'r') as f:
345
+ balance_sheet = f.read()
346
+ with open(income_stmt_file, 'r') as f:
347
+ income_stmt = f.read()
348
 
349
  # Process financial data
350
+ income_data = self.parse_financial_data(income_stmt)
351
+ balance_data = self.parse_financial_data(balance_sheet)
352
 
353
  # Calculate metrics
354
+ metrics = self.calculate_metrics(income_data, balance_data)
355
+ self.last_metrics = metrics
356
 
357
  # Generate analysis
358
+ analysis = self.generate_analysis(metrics)
359
 
360
  # Prepare final results
361
+ results = {
362
  "Financial Analysis": {
363
  "Key Metrics": {
364
  "Profitability": {
 
385
  }
386
  }
387
 
388
+ return json.dumps(results, indent=2)
389
 
390
+ except Exception as e:
391
+ return f"Error in analysis: {str(e)}\n\nDetails: {type(e).__name__}"
392
 
393
+ def fine_tune_models(self, train_texts, train_labels, epochs=3):
394
  """Fine-tune the model with custom data"""
395
+ try:
396
  # Prepare dataset
397
+ train_dataset = FinancialDataset(train_texts, train_labels, self.llama_tokenizer)
398
 
399
  # Training arguments
400
+ training_args = TrainingArguments(
401
  output_dir="./financial_model_tuned",
402
  num_train_epochs=epochs,
403
  per_device_train_batch_size=4,
 
411
  )
412
 
413
  # Initialize trainer
414
+ trainer = Trainer(
415
  model=self.llama_model,
416
  args=training_args,
417
  train_dataset=train_dataset
418
  )
419
 
420
  # Fine-tune the model
421
+ trainer.train()
422
 
423
  # Save the fine-tuned model
424
+ self.llama_model.save_pretrained("./financial_model_tuned")
425
+ self.llama_tokenizer.save_pretrained("./financial_model_tuned")
426
 
427
+ print("Fine-tuning completed successfully!")
428
+ except Exception as e:
429
+ print(f"Error in fine-tuning: {str(e)}")
430
 
431
 
432