File size: 4,791 Bytes
4f6ed1c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Hate Speech Detection</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background: #f9f9f9;
      color: #000;
      margin: 0;
      padding: 20px;
      display: flex;
      flex-direction: column;
      align-items: center;
    }

    body.dark-mode {
      background: #272626;
      color: #fff;
    }

    h1 {
      font-size: 40px;
      margin-bottom: 10px;
    }

    .subtext {
      font-size: 16px;
      margin-bottom: 40px;
      text-align: center;
      max-width: 800px;
    }

    .container {
      display: flex;
      justify-content: center;
      gap: 40px;
      width: 100%;
      max-width: 1000px;
    }

    .left-panel, .right-panel {
      flex: 1;
      display: flex;
      flex-direction: column;
    }

    textarea {
      width: 100%;
      height: 140px;
      padding: 10px;
      font-size: 16px;
    }

    .buttons {
      display: flex;
      justify-content: space-between;
      width: 100%;
      margin-top: 10px;
    }

    .buttons button {
      width: 49.5%;
      padding: 12px;
      font-size: 16px;
      border: none;
      border-radius: 4px;
      cursor: pointer;
    }

    .submit-btn {
      background: #4CAF50;
      color: white;
    }

    .clear-btn {
      background: #45a049;
      color: white;
    }

    .share-btn {
      width: 100%;
      padding: 14px;
      font-size: 16px;
      background: #007BFF;
      color: white;
      border: none;
      border-radius: 4px;
      margin-top: auto;
    }

    .output {
      background: white;
      padding: 15px;
      border-radius: 8px;
      box-shadow: 0 0 10px rgba(0,0,0,0.1);
      font-size: 16px;
      min-height: 120px;
      margin-bottom: 20px;
    }

    .dark-mode .output {
      background: #1e1e1e;
      color: #fff;
    }

    .mode-toggle {
      margin-top: 60px;
      font-size: 14px;
    }
  </style>
</head>
<body>
  <h1 id="page-title">Hate Speech Detection</h1>
  <p class="subtext">
    This tool uses 3 models (GloVe-based GRU, facebook/RoBERTa-dynabench-r4 (Transformer), ToxiGen-roberta (Transformer)) 
    to classify hate speech using an ensemble method.
  </p>

  <div class="container">
    <div class="left-panel">
      <form id="hs-form">
        <textarea id="text-input" placeholder="Enter text here..."></textarea>
        <div class="buttons">
          <button type="button" class="clear-btn" onclick="clearText()">Clear Text</button>
          <button type="submit" class="submit-btn">Submit</button>
        </div>
      </form>
    </div>

    <div class="right-panel">
      <div class="output" id="output" style="display: none;"></div>
      <button class="share-btn" onclick="shareText()">Share via Link</button>
    </div>
  </div>

  <div class="mode-toggle">
    <label><input type="checkbox" id="mode-toggle"> Dark Mode</label>
  </div>

  <script>
    const outputDiv = document.getElementById("output");
    const pageTitle = document.getElementById("page-title");

    document.getElementById("hs-form").addEventListener("submit", async function (e) {
      e.preventDefault();
      const text = document.getElementById("text-input").value;

      const response = await fetch("/predict", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ text: text }),
      });

      const result = await response.json();
      outputDiv.style.display = "block";
      outputDiv.innerHTML = `
        <strong>Model 1:</strong> ${result.gru_prob}<br>
        <strong>Model 2:</strong> ${result.roberta_prob}<br>
        <strong>Model 3:</strong> ${result.toxigen_prob}<br>
        <strong>Prediction:</strong> ${result.prediction}
      `;
    });

    function clearText() {
      document.getElementById("text-input").value = "";
      outputDiv.style.display = "none";
      outputDiv.innerHTML = "";
    }

    function shareText() {
      const text = document.getElementById("text-input").value;
      const shareUrl = `${window.location.href}?text=${encodeURIComponent(text)}`;
      navigator.clipboard.writeText(shareUrl);
      alert("Sharable link copied to clipboard!");
    }

    document.getElementById("mode-toggle").addEventListener("change", function () {
      document.body.classList.toggle("dark-mode", this.checked);
      pageTitle.style.color = this.checked ? "white" : "black";
    });

    // On load: apply shared text if present
    window.onload = function () {
      const urlParams = new URLSearchParams(window.location.search);
      const sharedText = urlParams.get("text");
      if (sharedText) {
        document.getElementById("text-input").value = decodeURIComponent(sharedText);
      }
    };
  </script>
</body>
</html>