Update app_chatgpt.py
Browse files- app_chatgpt.py +21 -5
app_chatgpt.py
CHANGED
|
@@ -14,34 +14,50 @@ session = boto3.Session(
|
|
| 14 |
aws_secret_access_key=os.getenv("secret_access_key")
|
| 15 |
)
|
| 16 |
|
| 17 |
-
# ✅ Upload reconciled results and original files to S3
|
| 18 |
def upload_files_to_s3(erp_file_path, external_file_path, content, bucket_name):
|
| 19 |
s3 = session.client("s3")
|
| 20 |
session_id = str(uuid.uuid4())
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
txt_filename = f"{session_id}.txt"
|
| 25 |
|
| 26 |
# Write reconciliation output to local file
|
| 27 |
with open(txt_filename, "w", encoding="utf-8") as file:
|
| 28 |
file.write(content)
|
| 29 |
|
| 30 |
-
#
|
| 31 |
erp_s3_key = f"ERP Statements/{erp_filename}"
|
| 32 |
bank_s3_key = f"Bank Statements/{bank_filename}"
|
| 33 |
txt_s3_key = f"Reconciliation Results/{txt_filename}"
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
s3.upload_file(erp_file_path, bucket_name, erp_s3_key)
|
| 36 |
s3.upload_file(external_file_path, bucket_name, bank_s3_key)
|
| 37 |
s3.upload_file(txt_filename, bucket_name, txt_s3_key)
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
os.remove(txt_filename)
|
| 40 |
|
| 41 |
return {
|
| 42 |
"erp_s3_key": erp_s3_key,
|
| 43 |
"bank_s3_key": bank_s3_key,
|
| 44 |
"result_s3_key": txt_s3_key,
|
|
|
|
| 45 |
"session_id": session_id
|
| 46 |
}
|
| 47 |
|
|
@@ -178,4 +194,4 @@ with gr.Blocks(css="""
|
|
| 178 |
outputs=[status, result]
|
| 179 |
)
|
| 180 |
|
| 181 |
-
iface.launch()
|
|
|
|
| 14 |
aws_secret_access_key=os.getenv("secret_access_key")
|
| 15 |
)
|
| 16 |
|
|
|
|
| 17 |
def upload_files_to_s3(erp_file_path, external_file_path, content, bucket_name):
|
| 18 |
s3 = session.client("s3")
|
| 19 |
session_id = str(uuid.uuid4())
|
| 20 |
|
| 21 |
+
base_erp = os.path.splitext(os.path.basename(erp_file_path))[0]
|
| 22 |
+
base_bank = os.path.splitext(os.path.basename(external_file_path))[0]
|
| 23 |
+
|
| 24 |
+
# Add session ID to filenames
|
| 25 |
+
erp_filename = f"{base_erp}_{session_id}.csv"
|
| 26 |
+
bank_filename = f"{base_bank}_{session_id}.csv"
|
| 27 |
txt_filename = f"{session_id}.txt"
|
| 28 |
|
| 29 |
# Write reconciliation output to local file
|
| 30 |
with open(txt_filename, "w", encoding="utf-8") as file:
|
| 31 |
file.write(content)
|
| 32 |
|
| 33 |
+
# === Separate folders by type ===
|
| 34 |
erp_s3_key = f"ERP Statements/{erp_filename}"
|
| 35 |
bank_s3_key = f"Bank Statements/{bank_filename}"
|
| 36 |
txt_s3_key = f"Reconciliation Results/{txt_filename}"
|
| 37 |
|
| 38 |
+
# === Combined folder for each run ===
|
| 39 |
+
combined_prefix = f"Combined Files/{session_id}/"
|
| 40 |
+
erp_combined_key = combined_prefix + erp_filename
|
| 41 |
+
bank_combined_key = combined_prefix + bank_filename
|
| 42 |
+
txt_combined_key = combined_prefix + txt_filename
|
| 43 |
+
|
| 44 |
+
# ✅ Upload to type-based folders
|
| 45 |
s3.upload_file(erp_file_path, bucket_name, erp_s3_key)
|
| 46 |
s3.upload_file(external_file_path, bucket_name, bank_s3_key)
|
| 47 |
s3.upload_file(txt_filename, bucket_name, txt_s3_key)
|
| 48 |
|
| 49 |
+
# ✅ Upload to combined folder
|
| 50 |
+
s3.upload_file(erp_file_path, bucket_name, erp_combined_key)
|
| 51 |
+
s3.upload_file(external_file_path, bucket_name, bank_combined_key)
|
| 52 |
+
s3.upload_file(txt_filename, bucket_name, txt_combined_key)
|
| 53 |
+
|
| 54 |
os.remove(txt_filename)
|
| 55 |
|
| 56 |
return {
|
| 57 |
"erp_s3_key": erp_s3_key,
|
| 58 |
"bank_s3_key": bank_s3_key,
|
| 59 |
"result_s3_key": txt_s3_key,
|
| 60 |
+
"combined_keys": [erp_combined_key, bank_combined_key, txt_combined_key],
|
| 61 |
"session_id": session_id
|
| 62 |
}
|
| 63 |
|
|
|
|
| 194 |
outputs=[status, result]
|
| 195 |
)
|
| 196 |
|
| 197 |
+
iface.launch()
|