Update app.py
Browse files
app.py
CHANGED
|
@@ -93,18 +93,20 @@ def evaluate_model_with_report(val_loader):
|
|
| 93 |
|
| 94 |
# Performance metrics
|
| 95 |
def generate_performance_metrics():
|
|
|
|
|
|
|
|
|
|
| 96 |
return {
|
| 97 |
-
"accuracy": "
|
| 98 |
-
"precision": "
|
| 99 |
-
"recall": "
|
| 100 |
-
"f1_score": "
|
| 101 |
-
"confusion_matrix_plot": "",
|
| 102 |
}
|
| 103 |
|
| 104 |
-
performance_metrics = generate_performance_metrics()
|
| 105 |
-
|
| 106 |
# Gradio Interface
|
|
|
|
| 107 |
def create_interface():
|
|
|
|
| 108 |
with gr.Blocks() as interface:
|
| 109 |
gr.Markdown("Spam Email Classification")
|
| 110 |
|
|
@@ -120,6 +122,16 @@ def create_interface():
|
|
| 120 |
|
| 121 |
analyze_button = gr.Button("Analyze Email 🕵️♂️")
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
analyze_button.click(
|
| 124 |
fn=classify_email,
|
| 125 |
inputs=email_input,
|
|
|
|
| 93 |
|
| 94 |
# Performance metrics
|
| 95 |
def generate_performance_metrics():
|
| 96 |
+
y_pred = model.predict(X_test)
|
| 97 |
+
accuracy = accuracy_score(y_test,y_pred)
|
| 98 |
+
report = classification_report(y_test, y_pred, output_dict=True))
|
| 99 |
return {
|
| 100 |
+
"accuracy": f"{accuracy:.2%}",
|
| 101 |
+
"precision": f"{report['1']['precision']:.2%}",
|
| 102 |
+
"recall": f"{report['1']['recall']:.2%}",
|
| 103 |
+
"f1_score": f"{report['1']['f1-score']:.2%}",
|
|
|
|
| 104 |
}
|
| 105 |
|
|
|
|
|
|
|
| 106 |
# Gradio Interface
|
| 107 |
+
|
| 108 |
def create_interface():
|
| 109 |
+
performance_metrics = generate_performance_metrics()
|
| 110 |
with gr.Blocks() as interface:
|
| 111 |
gr.Markdown("Spam Email Classification")
|
| 112 |
|
|
|
|
| 122 |
|
| 123 |
analyze_button = gr.Button("Analyze Email 🕵️♂️")
|
| 124 |
|
| 125 |
+
def email_analysis_pipeline(email_text):
|
| 126 |
+
results = classify_email(email_text)
|
| 127 |
+
return (
|
| 128 |
+
results["result"],
|
| 129 |
+
results["confidence"],
|
| 130 |
+
results["highlighted"],
|
| 131 |
+
results["spammy_keywords"],
|
| 132 |
+
results["advice"]
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
analyze_button.click(
|
| 136 |
fn=classify_email,
|
| 137 |
inputs=email_input,
|