HarbourSOFT-LAB commited on
Commit
6796431
·
verified ·
1 Parent(s): 4b9315f

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +96 -23
index.html CHANGED
@@ -1,29 +1,102 @@
1
  <!DOCTYPE html>
2
  <html lang="en">
3
-
4
  <head>
5
- <meta charset="UTF-8" />
6
- <link rel="stylesheet" href="style.css" />
7
-
8
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
9
- <title>Transformers.js - Object Detection</title>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  </head>
11
-
12
  <body>
13
- <h1>Object Detection w/ 🤗 Transformers.js</h1>
14
- <label id="container" for="upload">
15
- <svg width="25" height="25" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
16
- <path fill="#000"
17
- d="M3.5 24.3a3 3 0 0 1-1.9-.8c-.5-.5-.8-1.2-.8-1.9V2.9c0-.7.3-1.3.8-1.9.6-.5 1.2-.7 2-.7h18.6c.7 0 1.3.2 1.9.7.5.6.7 1.2.7 2v18.6c0 .7-.2 1.4-.7 1.9a3 3 0 0 1-2 .8H3.6Zm0-2.7h18.7V2.9H3.5v18.7Zm2.7-2.7h13.3c.3 0 .5 0 .6-.3v-.7l-3.7-5a.6.6 0 0 0-.6-.2c-.2 0-.4 0-.5.3l-3.5 4.6-2.4-3.3a.6.6 0 0 0-.6-.3c-.2 0-.4.1-.5.3l-2.7 3.6c-.1.2-.2.4 0 .7.1.2.3.3.6.3Z">
18
- </path>
19
- </svg>
20
- Click to upload image
21
- <label id="example">(or try example)</label>
22
- </label>
23
- <label id="status">Loading model...</label>
24
- <input id="upload" type="file" accept="image/*" />
25
-
26
- <script src="index.js" type="module"></script>
27
- </body>
 
 
 
 
28
 
29
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <!DOCTYPE html>
2
  <html lang="en">
 
3
  <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Phishing Email Detection</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ padding: 20px;
11
+ }
12
+ textarea {
13
+ width: 100%;
14
+ height: 200px;
15
+ margin-bottom: 20px;
16
+ }
17
+ button {
18
+ padding: 10px 20px;
19
+ background-color: #4CAF50;
20
+ color: white;
21
+ border: none;
22
+ cursor: pointer;
23
+ }
24
+ #result {
25
+ margin-top: 20px;
26
+ padding: 10px;
27
+ background-color: #f4f4f4;
28
+ }
29
+ #loading-message {
30
+ margin-top: 20px;
31
+ color: blue;
32
+ }
33
+ </style>
34
  </head>
 
35
  <body>
36
+ <h1>Phishing Email Detection</h1>
37
+ <p>Would you like to load the phishing detection model?</p>
38
+ <button id="load-model-btn">Yes, Load Model</button>
39
+ <button id="cancel-load-btn" style="display: none;">Cancel</button>
40
+
41
+ <div id="loading-message" style="display: none;">Loading model, please wait...</div>
42
+
43
+ <div id="email-input-section" style="display: none;">
44
+ <textarea id="email-input" placeholder="Paste email content here..."></textarea><br>
45
+ <button id="detect-btn">Detect Phishing</button>
46
+ <div id="result"></div>
47
+ </div>
48
+
49
+ <script type="module">
50
+ // Import transformers.js directly from the CDN
51
+ import { pipeline } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@latest/dist/transformers.min.js";
52
+
53
+ const modelPath = "https://huggingface.co/aaazKI/phishing-email-detection-distilbert_v2.4.1-ONNX/resolve/main/model.onnx";
54
+ let model;
55
 
56
+ const loadModelBtn = document.getElementById("load-model-btn");
57
+ const cancelLoadBtn = document.getElementById("cancel-load-btn");
58
+ const emailInputSection = document.getElementById("email-input-section");
59
+ const loadingMessage = document.getElementById("loading-message");
60
+ const resultDiv = document.getElementById("result");
61
+ const detectBtn = document.getElementById("detect-btn");
62
+
63
+ loadModelBtn.addEventListener("click", async () => {
64
+ // Hide buttons and show loading message
65
+ loadModelBtn.style.display = "none";
66
+ cancelLoadBtn.style.display = "inline-block";
67
+ loadingMessage.style.display = "block";
68
+
69
+ // Load the model asynchronously
70
+ try {
71
+ model = await pipeline("text-classification", modelPath);
72
+ loadingMessage.style.display = "none";
73
+ emailInputSection.style.display = "block"; // Show input section once model is loaded
74
+ } catch (error) {
75
+ loadingMessage.innerText = "Error loading the model. Please try again.";
76
+ }
77
+ });
78
+
79
+ cancelLoadBtn.addEventListener("click", () => {
80
+ // Reset the UI if the user cancels loading
81
+ loadModelBtn.style.display = "inline-block";
82
+ cancelLoadBtn.style.display = "none";
83
+ loadingMessage.style.display = "none";
84
+ });
85
+
86
+ detectBtn.addEventListener("click", async () => {
87
+ const emailText = document.getElementById("email-input").value;
88
+ if (!emailText.trim()) {
89
+ resultDiv.innerText = "Please enter some text to classify.";
90
+ return;
91
+ }
92
+
93
+ // Run inference using the model
94
+ const result = await model(emailText);
95
+
96
+ // Display the result
97
+ const prediction = result[0].label;
98
+ resultDiv.innerText = `Prediction: ${prediction}`;
99
+ });
100
+ </script>
101
+ </body>
102
+ </html>