SMCP-AI / SMCP-AI.html
GDT-Studio's picture
Rename SMCP.html to SMCP-AI.html
8c4de45
Raw History Blame Contribute Delete
3.52 kB
<!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>