MojoHz commited on
Commit
ae46cdb
·
verified ·
1 Parent(s): b68bfab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -9,9 +9,12 @@ with open('best_arima_models.pkl', 'rb') as f:
9
 
10
  def predict_demand(mapped_code, num_months):
11
  try:
 
 
 
12
  # Retrieve the specific model for the mapped code
13
  if mapped_code not in model:
14
- return f"No model found for Mapped Code: {mapped_code}"
15
 
16
  model_for_code = model[mapped_code]
17
 
@@ -21,6 +24,7 @@ def predict_demand(mapped_code, num_months):
21
  # Make predictions
22
  future_steps = len(dates)
23
  forecast = model_for_code.forecast(steps=future_steps)
 
24
 
25
  # Prepare a DataFrame for display
26
  df = pd.DataFrame({
@@ -28,11 +32,11 @@ def predict_demand(mapped_code, num_months):
28
  'Predicted Demand': forecast
29
  })
30
 
31
- return df
32
 
33
  except Exception as e:
34
  print(f"Error occurred: {e}")
35
- return f"An error occurred: {str(e)}"
36
 
37
  # Gradio Interface Definition
38
  gr.Interface(
@@ -42,8 +46,9 @@ gr.Interface(
42
  gr.Slider(minimum=1, maximum=12, step=1, label="Number of Months")
43
  ],
44
  outputs=[
45
- gr.Dataframe(label="Predicted Demand")
 
46
  ],
47
  title="Demand Forecasting",
48
  description="Enter the mapped code and the number of months to predict future demand."
49
- ).launch(share=True)
 
9
 
10
  def predict_demand(mapped_code, num_months):
11
  try:
12
+ print(f"Received mapped code: {mapped_code}")
13
+ print(f"Number of months for prediction: {num_months}")
14
+
15
  # Retrieve the specific model for the mapped code
16
  if mapped_code not in model:
17
+ return None, f"No model found for Mapped Code: {mapped_code}"
18
 
19
  model_for_code = model[mapped_code]
20
 
 
24
  # Make predictions
25
  future_steps = len(dates)
26
  forecast = model_for_code.forecast(steps=future_steps)
27
+ print(f"Forecast: {forecast}")
28
 
29
  # Prepare a DataFrame for display
30
  df = pd.DataFrame({
 
32
  'Predicted Demand': forecast
33
  })
34
 
35
+ return df, None
36
 
37
  except Exception as e:
38
  print(f"Error occurred: {e}")
39
+ return None, f"An error occurred: {str(e)}"
40
 
41
  # Gradio Interface Definition
42
  gr.Interface(
 
46
  gr.Slider(minimum=1, maximum=12, step=1, label="Number of Months")
47
  ],
48
  outputs=[
49
+ gr.Dataframe(label="Predicted Demand"),
50
+ gr.Textbox(label="Error Message")
51
  ],
52
  title="Demand Forecasting",
53
  description="Enter the mapped code and the number of months to predict future demand."
54
+ ).launch()