File size: 3,515 Bytes
8c4de45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html>
  <head>
    <title>Social Media Prediction</title>
    <style>
      /* CSS styles for the container */
      .container {
        width: 80%;
        margin: 0 auto;
        padding: 20px;
        background-color: #f2f2f2;
        border: 1px solid #ccc;
        border-radius: 5px;
        font-family: Arial, sans-serif;
      }
      h1 {
        text-align: center;
        font-size: 36px;
        margin-bottom: 30px;
      }
      p {
        font-size: 18px;
        margin-bottom: 10px;
      }
      input[type="text"], input[type="file"], button {
        display: block;
        width: 100%;
        margin-bottom: 20px;
        padding: 10px;
        border: 1px solid #ccc;
        border-radius: 5px;
        font-size: 16px;
      }
      button {
        background-color: #4CAF50;
        color: white;
        font-weight: bold;
        cursor: pointer;
      }
      h2 {
        text-align: center;
        font-size: 24px;
        margin-top: 30px;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <h1>Social Media Prediction</h1>
      <p>Enter your social media caption:</p>
      <input type="text" id="textInput" placeholder="Enter caption here...">
      <p>Upload your image:</p>
      <input type="file" id="imageInput">
      <button id="predictButton">Predict</button>
      <h2 id="result"></h2>
    </div>

    <script>
      /* JavaScript code for checking the caption, identifying the image, and calculating the points */
      function checkCaption(textInput) {
        var points = 0;
        if (textInput.match(/#[a-zA-Z0-9]+/g)) {
          points += 5;
        }
        if (textInput.match(/@[a-zA-Z0-9]+/g)) {
          points += 2;
        }
        if (textInput.match(/[a-zA-Z]+/g)) {
          points += 10;
        }
        return points;
      }

      function identifyImage(imageInput) {
        return new Promise(function(resolve, reject) {
          var reader = new FileReader();
          reader.onload = function(e) {
            var img = new Image();
            img.onload = function() {
              var colorThief = new ColorThief();
              var colors = colorThief.getPalette(img, 100);
              var numColors = colors.length;
              resolve(numColors);
            }
            img.src = e.target.result;
          }
          reader.readAsDataURL(imageInput);
        });
      }

      function calculatePoints(captionPoints, imagePoints) {
        var totalPoints = captionPoints + imagePoints;
        if (totalPoints >= 1 && totalPoints <= 10) {
          return "Bad";
        } else if (totalPoints >= 11 && totalPoints <= 30) {
          return "Good";
        } else if (totalPoints >= 31 && totalPoints <= 100) {
          return "Very Good";
        } else if (totalPoints >= 101) {
          return "Viral";
        }
      }

      document.getElementById("predictButton").addEventListener("click", function() {
        var textInput = document.getElementById("textInput").value;
        var imageInput = document.getElementById("imageInput").files[0];
        var captionPoints = checkCaption(textInput);
        identifyImage(imageInput).then(function(imagePoints) {
          var result = calculatePoints(captionPoints, imagePoints);
          document.getElementById("result").innerHTML = result;
        });
      });
    </script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/color-thief/2.3.2/color-thief.min.js"></script>
  </body>
        </html>