Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ from datetime import datetime
|
|
8 |
from sklearn.metrics import mean_absolute_error, mean_squared_error
|
9 |
from statsmodels.tsa.statespace.sarimax import SARIMAX
|
10 |
from statsmodels.tsa.holtwinters import ExponentialSmoothing
|
11 |
-
|
12 |
from openpyxl import Workbook
|
13 |
from openpyxl.drawing.image import Image
|
14 |
from pandas import DataFrame
|
@@ -36,6 +36,29 @@ def forecast(name,duration):
|
|
36 |
})
|
37 |
return forecast_df
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
warnings.filterwarnings('ignore')
|
40 |
def predict(operation,file):
|
41 |
if file == None:
|
@@ -50,7 +73,7 @@ def predict(operation,file):
|
|
50 |
|
51 |
# output_name = "Forecasted.csv"
|
52 |
# predicted.to_csv(output_name,index=False)
|
53 |
-
|
54 |
workbook = Workbook()
|
55 |
# Remove the default sheet
|
56 |
default_sheet = workbook.active
|
@@ -73,6 +96,7 @@ def predict(operation,file):
|
|
73 |
# Insert the plot image into the Excel file
|
74 |
img = Image(plot_filename)
|
75 |
worksheet.add_image(img, 'D1')
|
|
|
76 |
# Save the Excel file
|
77 |
now = datetime.now()
|
78 |
formatted_datetime = now.strftime("%H:%M %d-%m-%Y")
|
@@ -89,5 +113,7 @@ iface = gr.Interface(fn=predict,
|
|
89 |
|
90 |
inputs=[gr.Radio(label='Predict ahead:',choices=['Month','Week'],value='Month'),gr.File(label="CSV file")],
|
91 |
|
92 |
-
outputs=[gr.File(label="CSV file"),gr.Textbox(label='Log',interactive=False)]
|
|
|
|
|
93 |
iface.launch()
|
|
|
8 |
from sklearn.metrics import mean_absolute_error, mean_squared_error
|
9 |
from statsmodels.tsa.statespace.sarimax import SARIMAX
|
10 |
from statsmodels.tsa.holtwinters import ExponentialSmoothing
|
11 |
+
from openpyxl.utils import get_column_letter
|
12 |
from openpyxl import Workbook
|
13 |
from openpyxl.drawing.image import Image
|
14 |
from pandas import DataFrame
|
|
|
36 |
})
|
37 |
return forecast_df
|
38 |
|
39 |
+
def changewidth(worksheet):
|
40 |
+
column_widths = {}
|
41 |
+
|
42 |
+
# Calculate the maximum width for each column
|
43 |
+
for column in worksheet.columns:
|
44 |
+
column_letter = get_column_letter(column[0].column)
|
45 |
+
max_length = 0
|
46 |
+
for cell in column:
|
47 |
+
try:
|
48 |
+
if len(str(cell.value)) > max_length:
|
49 |
+
max_length = len(str(cell.value))
|
50 |
+
except TypeError:
|
51 |
+
pass
|
52 |
+
column_widths[column_letter] = max_length
|
53 |
+
|
54 |
+
# Set the column widths based on the maximum width for each column
|
55 |
+
for column_letter, width in column_widths.items():
|
56 |
+
column_width = (width + 2) * 1.2 # Adjust the width by adding some padding
|
57 |
+
worksheet.column_dimensions[column_letter].width = column_width
|
58 |
+
|
59 |
+
return worksheet
|
60 |
+
|
61 |
+
|
62 |
warnings.filterwarnings('ignore')
|
63 |
def predict(operation,file):
|
64 |
if file == None:
|
|
|
73 |
|
74 |
# output_name = "Forecasted.csv"
|
75 |
# predicted.to_csv(output_name,index=False)
|
76 |
+
|
77 |
workbook = Workbook()
|
78 |
# Remove the default sheet
|
79 |
default_sheet = workbook.active
|
|
|
96 |
# Insert the plot image into the Excel file
|
97 |
img = Image(plot_filename)
|
98 |
worksheet.add_image(img, 'D1')
|
99 |
+
worksheet = changewidth(worksheet)
|
100 |
# Save the Excel file
|
101 |
now = datetime.now()
|
102 |
formatted_datetime = now.strftime("%H:%M %d-%m-%Y")
|
|
|
113 |
|
114 |
inputs=[gr.Radio(label='Predict ahead:',choices=['Month','Week'],value='Month'),gr.File(label="CSV file")],
|
115 |
|
116 |
+
outputs=[gr.File(label="CSV file"),gr.Textbox(label='Log',interactive=False)],
|
117 |
+
|
118 |
+
debug=True)
|
119 |
iface.launch()
|