Update app_chatgpt.py
Browse files- app_chatgpt.py +14 -40
app_chatgpt.py
CHANGED
|
@@ -156,13 +156,13 @@ def reconcile_statements_openai(erp_file, external_file):
|
|
| 156 |
if not erp_file or not external_file:
|
| 157 |
error_msg = "Both ERP and External files are required"
|
| 158 |
logger.error(f"β {error_msg}")
|
| 159 |
-
yield "β Error: Missing files", f"<h3>Error</h3><pre>{error_msg}</pre>"
|
| 160 |
return
|
| 161 |
|
| 162 |
logger.info(f"π ERP file: {erp_file.name if erp_file else 'None'}")
|
| 163 |
logger.info(f"π¦ External file: {external_file.name if external_file else 'None'}")
|
| 164 |
|
| 165 |
-
yield "β³ Processing your request...", ""
|
| 166 |
|
| 167 |
try:
|
| 168 |
# Extract data from files
|
|
@@ -231,8 +231,11 @@ Here is the External (Bank or Vendor) data:
|
|
| 231 |
# Calculate processing time
|
| 232 |
processing_time = (datetime.now() - session_start).total_seconds()
|
| 233 |
logger.info(f"β±οΈ Processing completed in {processing_time:.2f} seconds")
|
|
|
|
|
|
|
|
|
|
| 234 |
|
| 235 |
-
yield "β
Done!", html
|
| 236 |
|
| 237 |
# β
Upload the files + result to S3
|
| 238 |
try:
|
|
@@ -255,56 +258,27 @@ Here is the External (Bank or Vendor) data:
|
|
| 255 |
error_msg = f"Error during reconciliation: {e}"
|
| 256 |
logger.error(f"β {error_msg}")
|
| 257 |
logger.error(f"π Full error details: {str(e)}")
|
| 258 |
-
yield "β Error occurred", f"<h3>Error</h3><pre>{error_msg}</pre>"
|
| 259 |
|
| 260 |
|
| 261 |
-
# β
Gradio UI
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
with gr.Blocks(css="""
|
| 265 |
-
#company-logo {
|
| 266 |
-
width: 25%;
|
| 267 |
-
margin: auto;
|
| 268 |
-
display: block;
|
| 269 |
-
}
|
| 270 |
-
""") as iface:
|
| 271 |
gr.Image("logo_Icon.png", elem_id="company-logo", label="Beiing Human")
|
| 272 |
gr.Markdown("## π ERP vs Bank/Vendor Reconciliation Tool")
|
| 273 |
|
| 274 |
-
gr.Markdown(
|
| 275 |
-
"β οΈ **Important:** Please upload your statements as CSV files only. "
|
| 276 |
-
"Include columns: **Date**, **Amount**, **Description**."
|
| 277 |
-
)
|
| 278 |
-
|
| 279 |
with gr.Row():
|
| 280 |
-
erp_file = gr.File(
|
| 281 |
-
|
| 282 |
-
type="filepath",
|
| 283 |
-
file_types=[".csv"]
|
| 284 |
-
)
|
| 285 |
-
external_file = gr.File(
|
| 286 |
-
label="π¦ Upload Bank or Vendor Statement (CSV only)",
|
| 287 |
-
type="filepath",
|
| 288 |
-
file_types=[".csv"]
|
| 289 |
-
)
|
| 290 |
|
| 291 |
btn = gr.Button("π Reconcile")
|
| 292 |
|
| 293 |
-
with gr.Row():
|
| 294 |
-
support_btn = gr.Button(
|
| 295 |
-
"π§ Contact Support",
|
| 296 |
-
link="mailto:rishi@beiinghuman.com?subject=Support%20Request&body=Hi%20Beiing%20Human%20Team%2C%0A%0AI%20have%20a%20question%20about%20the%20reconciliation%20tool.%20Here%20are%20the%20details..."
|
| 297 |
-
)
|
| 298 |
-
gr.Markdown("π¬ Or email us at: `rishi@beiinghuman.com` (copy & paste)")
|
| 299 |
-
|
| 300 |
status = gr.Markdown()
|
| 301 |
result = gr.HTML()
|
|
|
|
| 302 |
|
| 303 |
btn.click(
|
| 304 |
fn=reconcile_statements_openai,
|
| 305 |
inputs=[erp_file, external_file],
|
| 306 |
-
outputs=[status, result]
|
| 307 |
)
|
| 308 |
-
iface.launch()
|
| 309 |
-
# Log when interface is ready
|
| 310 |
-
logger.info("β
Gradio interface built successfully")
|
|
|
|
| 156 |
if not erp_file or not external_file:
|
| 157 |
error_msg = "Both ERP and External files are required"
|
| 158 |
logger.error(f"β {error_msg}")
|
| 159 |
+
yield "β Error: Missing files", f"<h3>Error</h3><pre>{error_msg}</pre>", None
|
| 160 |
return
|
| 161 |
|
| 162 |
logger.info(f"π ERP file: {erp_file.name if erp_file else 'None'}")
|
| 163 |
logger.info(f"π¦ External file: {external_file.name if external_file else 'None'}")
|
| 164 |
|
| 165 |
+
yield "β³ Processing your request...", "", None
|
| 166 |
|
| 167 |
try:
|
| 168 |
# Extract data from files
|
|
|
|
| 231 |
# Calculate processing time
|
| 232 |
processing_time = (datetime.now() - session_start).total_seconds()
|
| 233 |
logger.info(f"β±οΈ Processing completed in {processing_time:.2f} seconds")
|
| 234 |
+
download_filename = f"reconciliation_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt"
|
| 235 |
+
with open(download_filename, "w", encoding="utf-8") as f:
|
| 236 |
+
f.write(content)
|
| 237 |
|
| 238 |
+
yield "β
Done!", html, download_filename
|
| 239 |
|
| 240 |
# β
Upload the files + result to S3
|
| 241 |
try:
|
|
|
|
| 258 |
error_msg = f"Error during reconciliation: {e}"
|
| 259 |
logger.error(f"β {error_msg}")
|
| 260 |
logger.error(f"π Full error details: {str(e)}")
|
| 261 |
+
yield "β Error occurred", f"<h3>Error</h3><pre>{error_msg}</pre>", None
|
| 262 |
|
| 263 |
|
| 264 |
+
# β
Gradio UI
|
| 265 |
+
with gr.Blocks(css="""#company-logo { width: 25%; margin: auto; display: block; }""") as iface:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
gr.Image("logo_Icon.png", elem_id="company-logo", label="Beiing Human")
|
| 267 |
gr.Markdown("## π ERP vs Bank/Vendor Reconciliation Tool")
|
| 268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
with gr.Row():
|
| 270 |
+
erp_file = gr.File(label="π Upload ERP Statement (CSV only)", type="filepath", file_types=[".csv"])
|
| 271 |
+
external_file = gr.File(label="π¦ Upload Bank or Vendor Statement (CSV only)", type="filepath", file_types=[".csv"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
btn = gr.Button("π Reconcile")
|
| 274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
status = gr.Markdown()
|
| 276 |
result = gr.HTML()
|
| 277 |
+
download = gr.File(label="β¬οΈ Download Reconciliation Report", type="filepath")
|
| 278 |
|
| 279 |
btn.click(
|
| 280 |
fn=reconcile_statements_openai,
|
| 281 |
inputs=[erp_file, external_file],
|
| 282 |
+
outputs=[status, result, download]
|
| 283 |
)
|
| 284 |
+
iface.launch()
|
|
|
|
|
|