File size: 6,804 Bytes
256cf3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!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; /* Hide the image initially */
        }

        .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 = 'https://arafath10-newapi.hf.space';

        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(); // Prevent caching

            imgElement.onload = () => {
                hideLoader('graphLoader');
                imgElement.style.display = 'block'; // Show the image when it is loaded
            };

            imgElement.onerror = () => {
                hideLoader('graphLoader');
                showWarning('graphWarning', 'Error loading graph image.');
            };

            imgElement.src = newSrc;
        }
    </script>
</body>
</html>