albhu commited on
Commit
646e5e3
·
verified ·
1 Parent(s): 345243b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -24
app.py CHANGED
@@ -12,7 +12,7 @@ def main():
12
 
13
  if api_key:
14
  # Download BOE rates
15
- boe_rates_df = download_boe_rates()
16
 
17
  # Allow user to upload Excel sheet
18
  uploaded_file = st.file_uploader("Upload Excel file", type=["xlsx", "xls"])
@@ -39,15 +39,8 @@ def main():
39
  'amount': amounts
40
  })
41
 
42
- # If Bank of England rates are available, adjust the late interest calculation
43
- if boe_rates_df is not None:
44
- # Get the latest Bank of England base rate
45
- latest_base_rate = boe_rates_df['Bank Rate'].iloc[-1]
46
- # Calculate late interest with adjusted rate
47
- df_with_interest = calculate_late_interest(df_calculate, late_interest_rate, latest_base_rate)
48
- else:
49
- # Calculate late interest using the specified late interest rate
50
- df_with_interest = calculate_late_interest(df_calculate, late_interest_rate)
51
 
52
  # Display calculated late interest
53
  total_late_interest = df_with_interest['late_interest'].sum()
@@ -84,17 +77,10 @@ def main():
84
  st.warning("Please enter your OpenAI API key.")
85
 
86
  # Function to calculate late interest
87
- def calculate_late_interest(data, late_interest_rate, base_rate=None):
88
- # If base_rate is provided, calculate late interest based on it
89
- if base_rate is not None:
90
- # Calculate late days and late interest using the adjusted late interest rate
91
- data['late_days'] = (data['payment_date'] - data['due_date']).dt.days.clip(lower=0)
92
- data['late_interest'] = data['late_days'] * data['amount'] * ((late_interest_rate + base_rate) / 100)
93
- else:
94
- # Calculate late days and late interest using the provided late interest rate
95
- data['late_days'] = (data['payment_date'] - data['due_date']).dt.days.clip(lower=0)
96
- data['late_interest'] = data['late_days'] * data['amount'] * (late_interest_rate / 100)
97
-
98
  return data
99
 
100
  # Function to analyze Excel sheet and extract relevant information
@@ -125,13 +111,10 @@ def download_boe_rates():
125
  df = pd.read_html(response.text)[0]
126
  df.to_csv('boe_rates.csv', index=False)
127
  st.success("Bank of England rates downloaded successfully.")
128
- return df
129
  else:
130
  st.error("Failed to retrieve data from the Bank of England website.")
131
- return None
132
  except requests.RequestException as e:
133
  st.error(f"Failed to download rates: {e}")
134
- return None
135
 
136
  if __name__ == "__main__":
137
  main()
 
12
 
13
  if api_key:
14
  # Download BOE rates
15
+ download_boe_rates()
16
 
17
  # Allow user to upload Excel sheet
18
  uploaded_file = st.file_uploader("Upload Excel file", type=["xlsx", "xls"])
 
39
  'amount': amounts
40
  })
41
 
42
+ # Calculate late interest
43
+ df_with_interest = calculate_late_interest(df_calculate, late_interest_rate)
 
 
 
 
 
 
 
44
 
45
  # Display calculated late interest
46
  total_late_interest = df_with_interest['late_interest'].sum()
 
77
  st.warning("Please enter your OpenAI API key.")
78
 
79
  # Function to calculate late interest
80
+ def calculate_late_interest(data, late_interest_rate):
81
+ # Calculate late days and late interest
82
+ data['late_days'] = (data['payment_date'] - data['due_date']).dt.days.clip(lower=0)
83
+ data['late_interest'] = data['late_days'] * data['amount'] * (late_interest_rate / 100)
 
 
 
 
 
 
 
84
  return data
85
 
86
  # Function to analyze Excel sheet and extract relevant information
 
111
  df = pd.read_html(response.text)[0]
112
  df.to_csv('boe_rates.csv', index=False)
113
  st.success("Bank of England rates downloaded successfully.")
 
114
  else:
115
  st.error("Failed to retrieve data from the Bank of England website.")
 
116
  except requests.RequestException as e:
117
  st.error(f"Failed to download rates: {e}")
 
118
 
119
  if __name__ == "__main__":
120
  main()