trial2 / index.html
alaa-ahmed14's picture
Create index.html
d1153c0 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>STEMerald-2b API</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 20px;
background-color: #f5f5f5;
}
#container {
max-width: 600px;
margin: auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
textarea {
width: 100%;
height: 100px;
margin-bottom: 10px;
border-radius: 4px;
border: 1px solid #ccc;
padding: 10px;
font-size: 16px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
#output {
margin-top: 20px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
background-color: #e8f4e5;
}
</style>
</head>
<body>
<div id="container">
<h2>STEMerald-2b API</h2>
<textarea id="question" placeholder="Type your question here..."></textarea>
<button id="submit-btn">Submit</button>
<div id="output"></div>
</div>
<script>
document.getElementById('submit-btn').addEventListener('click', async () => {
const question = document.getElementById('question').value;
const outputDiv = document.getElementById('output');
// Clear previous output
outputDiv.innerHTML = "";
if (question.trim() === "") {
outputDiv.innerHTML = "Please enter a question.";
return;
}
try {
const response = await fetch("http://localhost:7860/generate/", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ prompt: question })
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
const data = await response.json();
outputDiv.innerHTML = "<strong>Response:</strong> " + data.generated_text;
} catch (error) {
outputDiv.innerHTML = "Error: " + error.message;
}
});
// Allow pressing Enter to submit the question
document.getElementById('question').addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
document.getElementById('submit-btn').click();
}
});
</script>
</body>
</html>