Yash goyal commited on
Commit
b8e5331
·
verified ·
1 Parent(s): 9b03af2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -131,7 +131,7 @@ recommendations = {
131
  }
132
 
133
  # Logger
134
- logging.basicConfig(level=logging.INFO)
135
  logger = logging.getLogger(__name__)
136
 
137
  # Database Models
@@ -344,13 +344,16 @@ def home():
344
  @app.route("/form")
345
  def form():
346
  try:
 
 
 
347
  return render_template("form.html", history_plot="/training_plot.png")
348
  except Exception as e:
349
  logger.error("Error rendering form: %s", str(e))
350
  return render_template("form.html", history_plot=None, result={
351
  "prediction": "Error",
352
  "confidence": "N/A",
353
- "message": "Failed to load form. Please try again.",
354
  "email_status": "N/A"
355
  })
356
 
@@ -488,6 +491,8 @@ def predict():
488
 
489
  # Send email automatically
490
  try:
 
 
491
  pdf_path = f"/tmp/report_{scan.id}.pdf"
492
  generate_pdf(report, pdf_path)
493
  msg = Message(
@@ -511,7 +516,7 @@ def predict():
511
  return render_template("form.html", history_plot="/training_plot.png", result={
512
  "prediction": "Error",
513
  "confidence": "N/A",
514
- "message": str(e),
515
  "email_status": "Error occurred, no email sent."
516
  })
517
 
@@ -525,7 +530,7 @@ def result():
525
  return render_template("form.html", history_plot="/training_plot.png", result={
526
  "prediction": "Error",
527
  "confidence": "N/A",
528
- "message": "Failed to load result. Please try again.",
529
  "email_status": "N/A"
530
  })
531
 
 
131
  }
132
 
133
  # Logger
134
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
135
  logger = logging.getLogger(__name__)
136
 
137
  # Database Models
 
344
  @app.route("/form")
345
  def form():
346
  try:
347
+ # Check for required environment variables
348
+ if not app.config['MAIL_USERNAME'] or not app.config['MAIL_PASSWORD']:
349
+ logger.warning("Mail configuration missing, email functionality may fail")
350
  return render_template("form.html", history_plot="/training_plot.png")
351
  except Exception as e:
352
  logger.error("Error rendering form: %s", str(e))
353
  return render_template("form.html", history_plot=None, result={
354
  "prediction": "Error",
355
  "confidence": "N/A",
356
+ "message": f"Failed to load form: {str(e)}",
357
  "email_status": "N/A"
358
  })
359
 
 
491
 
492
  # Send email automatically
493
  try:
494
+ if not app.config['MAIL_USERNAME'] or not app.config['MAIL_PASSWORD']:
495
+ raise ValueError("Mail configuration missing")
496
  pdf_path = f"/tmp/report_{scan.id}.pdf"
497
  generate_pdf(report, pdf_path)
498
  msg = Message(
 
516
  return render_template("form.html", history_plot="/training_plot.png", result={
517
  "prediction": "Error",
518
  "confidence": "N/A",
519
+ "message": f"Prediction failed: {str(e)}",
520
  "email_status": "Error occurred, no email sent."
521
  })
522
 
 
530
  return render_template("form.html", history_plot="/training_plot.png", result={
531
  "prediction": "Error",
532
  "confidence": "N/A",
533
+ "message": f"Failed to load result: {str(e)}",
534
  "email_status": "N/A"
535
  })
536