Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -82,8 +82,8 @@ def classify_email_single_model(text, model_name):
|
|
| 82 |
return response
|
| 83 |
|
| 84 |
|
| 85 |
-
# Classification function (all models together)
|
| 86 |
-
def
|
| 87 |
votes = {"Safe": 0, "Spam": 0, "Phishing": 0}
|
| 88 |
probabilities = {}
|
| 89 |
|
|
@@ -111,11 +111,43 @@ def classify_email(text):
|
|
| 111 |
response += "\n"
|
| 112 |
|
| 113 |
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
# Gradio UI
|
| 116 |
demo = gr.Interface(
|
| 117 |
fn=classify_email,
|
| 118 |
-
inputs=gr.Textbox(lines=10, placeholder="Ievietojiet savu e-pastu šeit..."),
|
|
|
|
|
|
|
| 119 |
outputs="text",
|
| 120 |
title="E-pastu klasifikators (vairāku modeļu balsošana)",
|
| 121 |
description="Autori: Kristaps Tretjuks un Aleksejs Gorlovičs"
|
|
|
|
| 82 |
return response
|
| 83 |
|
| 84 |
|
| 85 |
+
# Classification function (all models together, probabilities for each model)
|
| 86 |
+
def classify_email_detailed(text):
|
| 87 |
votes = {"Safe": 0, "Spam": 0, "Phishing": 0}
|
| 88 |
probabilities = {}
|
| 89 |
|
|
|
|
| 111 |
response += "\n"
|
| 112 |
|
| 113 |
return response
|
| 114 |
+
|
| 115 |
+
# Classification function (all models together, just the votes)
|
| 116 |
+
def classify_email_simple(text):
|
| 117 |
+
votes = {"Safe": 0, "Spam": 0, "Phishing": 0}
|
| 118 |
+
|
| 119 |
+
for model_name in model_names:
|
| 120 |
+
response = classify_email_single_model(text, model_name)
|
| 121 |
+
vote = response['prediction']
|
| 122 |
+
votes[vote] += 1
|
| 123 |
+
|
| 124 |
+
response = ""
|
| 125 |
+
i = 1
|
| 126 |
+
for label, vote_count in votes.items():
|
| 127 |
+
vote_or_votes = "vote" if vote_count == 1 else "votes"
|
| 128 |
+
if i != 3:
|
| 129 |
+
response += f"{label}: {vote_count} {vote_or_votes}, "
|
| 130 |
+
else:
|
| 131 |
+
response += f"{label}: {vote_count} {vote_or_votes}\n"
|
| 132 |
+
i += 1
|
| 133 |
+
response += "\n"
|
| 134 |
+
|
| 135 |
+
return response
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def classify_email(text, mode):
|
| 139 |
+
if mode == "Tikai balsis":
|
| 140 |
+
return classify_email_simple(text)
|
| 141 |
+
else:
|
| 142 |
+
return classify_email_detailed(text)
|
| 143 |
+
|
| 144 |
|
| 145 |
# Gradio UI
|
| 146 |
demo = gr.Interface(
|
| 147 |
fn=classify_email,
|
| 148 |
+
inputs=[gr.Textbox(lines=10, placeholder="Ievietojiet savu e-pastu šeit..."),
|
| 149 |
+
gr.Radio(choices=["Tikai balsis", "Balsis un varbūtības"], label='Klasifikācijas veids')
|
| 150 |
+
],
|
| 151 |
outputs="text",
|
| 152 |
title="E-pastu klasifikators (vairāku modeļu balsošana)",
|
| 153 |
description="Autori: Kristaps Tretjuks un Aleksejs Gorlovičs"
|