Update app.py
Browse files
app.py
CHANGED
@@ -1,60 +1,60 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
st.
|
|
|
57 |
|
58 |
if __name__ == "__main__":
|
59 |
-
|
60 |
-
app.main() # Corrected call
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
+
import openai
|
4 |
+
|
5 |
+
# Function to calculate late interest
|
6 |
+
def calculate_late_interest(data, late_interest_rate):
|
7 |
+
# Check if 'due_date' and 'payment_date' columns exist
|
8 |
+
if 'due_date' not in data.columns or 'payment_date' not in data.columns:
|
9 |
+
st.error("Error: 'due_date' or 'payment_date' columns not found in the uploaded file.")
|
10 |
+
return None
|
11 |
+
|
12 |
+
# Convert 'due_date' and 'payment_date' to datetime
|
13 |
+
data['due_date'] = pd.to_datetime(data['due_date'], errors='coerce')
|
14 |
+
data['payment_date'] = pd.to_datetime(data['payment_date'], errors='coerce')
|
15 |
+
|
16 |
+
# Calculate late days and late interest
|
17 |
+
data['late_days'] = (data['payment_date'] - data['due_date']).dt.days.clip(lower=0)
|
18 |
+
data['late_interest'] = data['late_days'] * data['amount'] * (late_interest_rate / 100)
|
19 |
+
return data
|
20 |
+
|
21 |
+
# Streamlit App
|
22 |
+
def main():
|
23 |
+
st.title("Invoice Interest Calculator and Conversation")
|
24 |
+
|
25 |
+
# Allow user to upload Excel sheet
|
26 |
+
uploaded_file = st.file_uploader("Upload Excel file", type=["xlsx", "xls"])
|
27 |
+
|
28 |
+
if uploaded_file is not None:
|
29 |
+
df = pd.read_excel(uploaded_file)
|
30 |
+
|
31 |
+
# Display uploaded data
|
32 |
+
st.write("Uploaded Data:")
|
33 |
+
st.write(df)
|
34 |
+
|
35 |
+
# Allow user to specify late interest rate
|
36 |
+
late_interest_rate = st.number_input("Enter Late Interest Rate (%):", min_value=0.0, max_value=100.0, step=0.1)
|
37 |
+
|
38 |
+
# Analyze data and calculate late interest
|
39 |
+
df_with_interest = calculate_late_interest(df, late_interest_rate)
|
40 |
+
|
41 |
+
if df_with_interest is not None:
|
42 |
+
# Display analyzed data
|
43 |
+
st.write("Data with Late Interest Calculated:")
|
44 |
+
st.write(df_with_interest)
|
45 |
+
|
46 |
+
# Allow user to engage in conversation
|
47 |
+
user_input = st.text_input("Start a conversation:")
|
48 |
+
if st.button("Send"):
|
49 |
+
openai.api_key = api_key # Set OpenAI API key
|
50 |
+
completion = openai.Completion.create(
|
51 |
+
engine="davinci-codex",
|
52 |
+
prompt=user_input,
|
53 |
+
max_tokens=100
|
54 |
+
)
|
55 |
+
response = completion.choices[0].text.strip()
|
56 |
+
st.write("AI's Response:")
|
57 |
+
st.write(response)
|
58 |
|
59 |
if __name__ == "__main__":
|
60 |
+
main()
|
|