|
5 | 5 | </head> |
6 | 6 | <body> |
7 | 7 | <h2>Upload Your Data</h2> |
8 | | - <form action="/upload" method="post" enctype="multipart/form-data"> |
9 | | - <input type="file" name="file" accept=".csv, .xlsx" required> |
| 8 | + <form id="uploadForm"> |
| 9 | + <input type="file" id="fileInput" name="file" accept=".csv" required> |
10 | 10 | <input type="submit" value="Upload and Analyze"> |
11 | 11 | </form> |
12 | 12 |
|
13 | 13 | <h3>OpenAI Summary</h3> |
14 | | - <div>{{ summary }}</div> |
| 14 | + <div id="summary"></div> |
15 | 15 |
|
16 | 16 | <h3>Scatter Plot</h3> |
17 | | - {% if plot_url %} |
18 | | - <img src="{{ plot_url }}" alt="Scatter Plot"> |
19 | | - {% endif %} |
| 17 | + <img id="plot" style="display:none;" alt="Scatter Plot" /> |
20 | 18 |
|
21 | 19 | <h3>Backend Log</h3> |
22 | | - <pre>{{ log }}</pre> |
| 20 | + <pre id="log"></pre> |
23 | 21 |
|
24 | 22 | <h3>Forecasted Values</h3> |
25 | | - <pre>{{ forecast }}</pre> |
| 23 | + <pre id="forecast"></pre> |
26 | 24 |
|
27 | | - <form action="/predict" method="post"> |
| 25 | + <form id="predictForm"> |
28 | 26 | <label>Enter future X values (comma-separated):</label><br> |
29 | | - <input type="text" name="future_x" placeholder="e.g., 2025-06-01, 2025-06-15"> |
| 27 | + <input type="text" id="futureInput" placeholder="e.g., 2025-06-01, 2025-06-15"> |
30 | 28 | <input type="submit" value="Forecast"> |
31 | 29 | </form> |
| 30 | + |
| 31 | + <script> |
| 32 | + const backendUrl = 'http://18.118.126.228'; |
| 33 | + |
| 34 | + document.getElementById('uploadForm').addEventListener('submit', async function (e) { |
| 35 | + e.preventDefault(); |
| 36 | + const formData = new FormData(); |
| 37 | + formData.append('file', document.getElementById('fileInput').files[0]); |
| 38 | + |
| 39 | + const response = await fetch(`${backendUrl}/upload`, { |
| 40 | + method: 'POST', |
| 41 | + body: formData |
| 42 | + }); |
| 43 | + |
| 44 | + const data = await response.json(); |
| 45 | + document.getElementById('summary').textContent = data.summary; |
| 46 | + document.getElementById('log').textContent = data.log; |
| 47 | + document.getElementById('forecast').textContent = data.forecast; |
| 48 | + document.getElementById('plot').src = `${backendUrl}/static/plot.png`; |
| 49 | + document.getElementById('plot').style.display = 'block'; |
| 50 | + }); |
| 51 | + |
| 52 | + document.getElementById('predictForm').addEventListener('submit', async function (e) { |
| 53 | + e.preventDefault(); |
| 54 | + const futureX = document.getElementById('futureInput').value; |
| 55 | + |
| 56 | + const formData = new FormData(); |
| 57 | + formData.append('future_x', futureX); |
| 58 | + |
| 59 | + const response = await fetch(`${backendUrl}/predict`, { |
| 60 | + method: 'POST', |
| 61 | + body: formData |
| 62 | + }); |
| 63 | + |
| 64 | + const data = await response.text(); |
| 65 | + document.getElementById('forecast').textContent = data; |
| 66 | + }); |
| 67 | + </script> |
32 | 68 | </body> |
33 | 69 | </html> |
34 | 70 |
|
0 commit comments