@@ -23,7 +23,7 @@ <h3>Forecasted Values</h3>
2323 < pre id ="forecast "> </ pre >
2424
2525 < form id ="predictForm ">
26- < label > Enter future X values (comma-separated):</ label > < br >
26+ < label > Enter future X values (comma-separated, e.g., 2025-06-01, 2025-06-15 ):</ label > < br >
2727 < input type ="text " id ="futureInput " placeholder ="e.g., 2025-06-01, 2025-06-15 ">
2828 < input type ="submit " value ="Forecast ">
2929 </ form >
@@ -36,17 +36,31 @@ <h3>Forecasted Values</h3>
3636 const formData = new FormData ( ) ;
3737 formData . append ( 'file' , document . getElementById ( 'fileInput' ) . files [ 0 ] ) ;
3838
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' ;
39+ try {
40+ const response = await fetch ( `${ backendUrl } /upload` , {
41+ method : 'POST' ,
42+ body : formData
43+ } ) ;
44+
45+ if ( ! response . ok ) {
46+ const errorText = await response . text ( ) ;
47+ console . error ( "Upload error:" , errorText ) ;
48+ alert ( "Upload failed: " + response . status ) ;
49+ return ;
50+ }
51+
52+ const data = await response . json ( ) ;
53+
54+ document . getElementById ( 'summary' ) . textContent = data . summary ;
55+ document . getElementById ( 'log' ) . textContent = data . log ;
56+ document . getElementById ( 'forecast' ) . textContent = data . forecast ;
57+ document . getElementById ( 'plot' ) . src = `${ backendUrl } ${ data . plot_url } ` ;
58+ document . getElementById ( 'plot' ) . style . display = 'block' ;
59+
60+ } catch ( err ) {
61+ console . error ( "Unexpected upload error:" , err ) ;
62+ alert ( "Upload failed: " + err . message ) ;
63+ }
5064 } ) ;
5165
5266 document . getElementById ( 'predictForm' ) . addEventListener ( 'submit' , async function ( e ) {
@@ -56,15 +70,34 @@ <h3>Forecasted Values</h3>
5670 const formData = new FormData ( ) ;
5771 formData . append ( 'future_x' , futureX ) ;
5872
59- const response = await fetch ( `${ backendUrl } /predict` , {
60- method : 'POST' ,
61- body : formData
62- } ) ;
73+ try {
74+ const response = await fetch ( `${ backendUrl } /predict` , {
75+ method : 'POST' ,
76+ body : formData
77+ } ) ;
6378
64- const data = await response . text ( ) ;
65- document . getElementById ( 'forecast' ) . textContent = data ;
79+ if ( ! response . ok ) {
80+ const errorText = await response . text ( ) ;
81+ console . error ( "Predict error:" , errorText ) ;
82+ alert ( "Prediction failed: " + response . status ) ;
83+ return ;
84+ }
85+
86+ const data = await response . json ( ) ;
87+
88+ document . getElementById ( 'forecast' ) . textContent =
89+ typeof data . forecast === "string"
90+ ? data . forecast
91+ : JSON . stringify ( data . forecast , null , 2 ) ;
92+ document . getElementById ( 'log' ) . textContent = data . log ;
93+ document . getElementById ( 'plot' ) . src = `${ backendUrl } ${ data . plot_url } ` ;
94+ document . getElementById ( 'plot' ) . style . display = 'block' ;
95+
96+ } catch ( err ) {
97+ console . error ( "Unexpected prediction error:" , err ) ;
98+ alert ( "Prediction failed: " + err . message ) ;
99+ }
66100 } ) ;
67101 </ script >
68102</ body >
69103</ html >
70-
0 commit comments