Skip to content

Commit 46aeaee

Browse files
Hariprashad RavikumarHariprashad Ravikumar
authored andcommitted
Convert frontend to static HTML with fetch() for GitHub Pages
1 parent 89650de commit 46aeaee

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

frontend/index.html

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,66 @@
55
</head>
66
<body>
77
<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>
1010
<input type="submit" value="Upload and Analyze">
1111
</form>
1212

1313
<h3>OpenAI Summary</h3>
14-
<div>{{ summary }}</div>
14+
<div id="summary"></div>
1515

1616
<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" />
2018

2119
<h3>Backend Log</h3>
22-
<pre>{{ log }}</pre>
20+
<pre id="log"></pre>
2321

2422
<h3>Forecasted Values</h3>
25-
<pre>{{ forecast }}</pre>
23+
<pre id="forecast"></pre>
2624

27-
<form action="/predict" method="post">
25+
<form id="predictForm">
2826
<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">
3028
<input type="submit" value="Forecast">
3129
</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>
3268
</body>
3369
</html>
3470

0 commit comments

Comments
 (0)