|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Stock Prediction and Graph</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
background: #f4f4f4;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
}
|
|
|
|
.container {
|
|
background: white;
|
|
padding: 20px;
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
border-radius: 8px;
|
|
text-align: center;
|
|
width: 80%;
|
|
max-width: 600px;
|
|
}
|
|
|
|
h1 {
|
|
color: #333;
|
|
}
|
|
|
|
img {
|
|
max-width: 100%;
|
|
height: auto;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
padding: 5px;
|
|
margin-top: 20px;
|
|
display: none;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 5px;
|
|
text-align: left;
|
|
}
|
|
|
|
.form-group input, .form-group select {
|
|
width: 100%;
|
|
padding: 8px;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.form-group button {
|
|
background-color: #007BFF;
|
|
color: white;
|
|
border: none;
|
|
padding: 10px 20px;
|
|
margin-top: 10px;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
transition: background-color 0.3s;
|
|
}
|
|
|
|
.form-group button:hover {
|
|
background-color: #0056b3;
|
|
}
|
|
|
|
.result {
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.result pre {
|
|
text-align: left;
|
|
background: #f9f9f9;
|
|
padding: 10px;
|
|
border-radius: 5px;
|
|
border: 1px solid #ddd;
|
|
max-height: 300px;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.loader {
|
|
border: 16px solid #f3f3f3;
|
|
border-radius: 50%;
|
|
border-top: 16px solid #3498db;
|
|
width: 60px;
|
|
height: 60px;
|
|
animation: spin 2s linear infinite;
|
|
display: none;
|
|
margin: 20px auto;
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
|
|
.warning {
|
|
color: red;
|
|
margin-top: 10px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>Stock Prediction and Graph</h1>
|
|
<div class="form-group">
|
|
<label for="symbol">Stock Symbol:</label>
|
|
<input type="text" id="symbol" placeholder="Enter stock symbol (e.g., AAPL)">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="interval">Interval (in days):</label>
|
|
<input type="number" id="interval" placeholder="Enter prediction interval in days">
|
|
</div>
|
|
<div class="form-group">
|
|
<button onclick="getPrediction()">Get Prediction</button>
|
|
</div>
|
|
<div class="loader" id="loader"></div>
|
|
<div class="warning" id="warning"></div>
|
|
<div class="result" id="result">
|
|
<h2>Prediction Result</h2>
|
|
<pre id="predictionOutput"></pre>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="graphType">Graph Type:</label>
|
|
<select id="graphType">
|
|
<option value="line">Line</option>
|
|
<option value="bar">Bar</option>
|
|
<option value="scatter">Scatter</option>
|
|
<option value="buy_sell">Buy/Sell</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<button onclick="getGraph()">Get Graph</button>
|
|
</div>
|
|
<div class="loader" id="graphLoader"></div>
|
|
<div class="warning" id="graphWarning"></div>
|
|
<div class="result" id="graphResult">
|
|
<h2>Stock Graph</h2>
|
|
<img id="stockGraph" src="" alt="Stock graph">
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const baseUrl = 'http://127.0.0.1:8000';
|
|
|
|
function showLoader(loaderId) {
|
|
document.getElementById(loaderId).style.display = 'block';
|
|
}
|
|
|
|
function hideLoader(loaderId) {
|
|
document.getElementById(loaderId).style.display = 'none';
|
|
}
|
|
|
|
function showWarning(warningId, message) {
|
|
document.getElementById(warningId).textContent = message;
|
|
}
|
|
|
|
function clearWarning(warningId) {
|
|
document.getElementById(warningId).textContent = '';
|
|
}
|
|
|
|
async function getPrediction() {
|
|
const symbol = document.getElementById('symbol').value;
|
|
const interval = document.getElementById('interval').value;
|
|
|
|
if (!symbol || !interval) {
|
|
showWarning('warning', 'Please enter both stock symbol and interval.');
|
|
return;
|
|
}
|
|
|
|
clearWarning('warning');
|
|
showLoader('loader');
|
|
|
|
try {
|
|
const response = await fetch(`${baseUrl}/predict?symbol=${symbol}&interval=${interval}`);
|
|
const data = await response.json();
|
|
document.getElementById('predictionOutput').textContent = JSON.stringify(data, null, 2);
|
|
} catch (error) {
|
|
showWarning('warning', 'Error fetching prediction data.');
|
|
} finally {
|
|
hideLoader('loader');
|
|
}
|
|
}
|
|
|
|
async function getGraph() {
|
|
const symbol = document.getElementById('symbol').value;
|
|
const graphType = document.getElementById('graphType').value;
|
|
|
|
if (!symbol || !graphType) {
|
|
showWarning('graphWarning', 'Please enter the stock symbol and select a graph type.');
|
|
return;
|
|
}
|
|
|
|
clearWarning('graphWarning');
|
|
showLoader('graphLoader');
|
|
|
|
const graphUrl = `${baseUrl}/graph?symbol=${symbol}&graph_type=${graphType}`;
|
|
const imgElement = document.getElementById('stockGraph');
|
|
const newSrc = graphUrl + '&time=' + new Date().getTime();
|
|
|
|
imgElement.onload = () => {
|
|
hideLoader('graphLoader');
|
|
imgElement.style.display = 'block';
|
|
};
|
|
|
|
imgElement.onerror = () => {
|
|
hideLoader('graphLoader');
|
|
showWarning('graphWarning', 'Error loading graph image.');
|
|
};
|
|
|
|
imgElement.src = newSrc;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|