Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- best_arima_models.pkl +3 -0
- gradiomojo.ipynb +115 -0
best_arima_models.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c62c5b809e6ea8ab754b5179f68e77a697800c577df11a61d852d6d7ee974025
|
| 3 |
+
size 5552038
|
gradiomojo.ipynb
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"nbformat": 4,
|
| 3 |
+
"nbformat_minor": 0,
|
| 4 |
+
"metadata": {
|
| 5 |
+
"colab": {
|
| 6 |
+
"provenance": []
|
| 7 |
+
},
|
| 8 |
+
"kernelspec": {
|
| 9 |
+
"name": "python3",
|
| 10 |
+
"display_name": "Python 3"
|
| 11 |
+
},
|
| 12 |
+
"language_info": {
|
| 13 |
+
"name": "python"
|
| 14 |
+
}
|
| 15 |
+
},
|
| 16 |
+
"cells": [
|
| 17 |
+
{
|
| 18 |
+
"cell_type": "code",
|
| 19 |
+
"execution_count": 5,
|
| 20 |
+
"metadata": {
|
| 21 |
+
"colab": {
|
| 22 |
+
"base_uri": "https://localhost:8080/",
|
| 23 |
+
"height": 646
|
| 24 |
+
},
|
| 25 |
+
"id": "Y2i3qMAayerW",
|
| 26 |
+
"outputId": "09a4d84b-3aab-4886-b5d4-948f48ca5017"
|
| 27 |
+
},
|
| 28 |
+
"outputs": [
|
| 29 |
+
{
|
| 30 |
+
"output_type": "stream",
|
| 31 |
+
"name": "stdout",
|
| 32 |
+
"text": [
|
| 33 |
+
"Setting queue=True in a Colab notebook requires sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n",
|
| 34 |
+
"\n",
|
| 35 |
+
"Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n",
|
| 36 |
+
"Running on public URL: https://abaebd2aaded04d1bb.gradio.live\n",
|
| 37 |
+
"\n",
|
| 38 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
|
| 39 |
+
]
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"output_type": "display_data",
|
| 43 |
+
"data": {
|
| 44 |
+
"text/plain": [
|
| 45 |
+
"<IPython.core.display.HTML object>"
|
| 46 |
+
],
|
| 47 |
+
"text/html": [
|
| 48 |
+
"<div><iframe src=\"https://abaebd2aaded04d1bb.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 49 |
+
]
|
| 50 |
+
},
|
| 51 |
+
"metadata": {}
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
"output_type": "execute_result",
|
| 55 |
+
"data": {
|
| 56 |
+
"text/plain": []
|
| 57 |
+
},
|
| 58 |
+
"metadata": {},
|
| 59 |
+
"execution_count": 5
|
| 60 |
+
}
|
| 61 |
+
],
|
| 62 |
+
"source": [
|
| 63 |
+
"import gradio as gr\n",
|
| 64 |
+
"import pandas as pd\n",
|
| 65 |
+
"import numpy as np\n",
|
| 66 |
+
"import pickle\n",
|
| 67 |
+
"\n",
|
| 68 |
+
"# Load the trained model from the pickle file\n",
|
| 69 |
+
"with open('best_arima_models.pkl', 'rb') as f:\n",
|
| 70 |
+
" model = pickle.load(f)\n",
|
| 71 |
+
"\n",
|
| 72 |
+
"def predict_demand(mapped_code, num_months):\n",
|
| 73 |
+
" try:\n",
|
| 74 |
+
" # Retrieve the specific model for the mapped code\n",
|
| 75 |
+
" if mapped_code not in model:\n",
|
| 76 |
+
" return f\"No model found for Mapped Code: {mapped_code}\"\n",
|
| 77 |
+
"\n",
|
| 78 |
+
" model_for_code = model[mapped_code]\n",
|
| 79 |
+
"\n",
|
| 80 |
+
" # Generate a date range for the prediction period\n",
|
| 81 |
+
" dates = pd.date_range(start=pd.Timestamp.today(), periods=num_months, freq='M')\n",
|
| 82 |
+
"\n",
|
| 83 |
+
" # Make predictions\n",
|
| 84 |
+
" future_steps = len(dates)\n",
|
| 85 |
+
" forecast = model_for_code.forecast(steps=future_steps)\n",
|
| 86 |
+
"\n",
|
| 87 |
+
" # Prepare a DataFrame for display\n",
|
| 88 |
+
" df = pd.DataFrame({\n",
|
| 89 |
+
" 'Date': dates.strftime('%Y-%m'),\n",
|
| 90 |
+
" 'Predicted Demand': forecast\n",
|
| 91 |
+
" })\n",
|
| 92 |
+
"\n",
|
| 93 |
+
" return df\n",
|
| 94 |
+
"\n",
|
| 95 |
+
" except Exception as e:\n",
|
| 96 |
+
" print(f\"Error occurred: {e}\")\n",
|
| 97 |
+
" return f\"An error occurred: {str(e)}\"\n",
|
| 98 |
+
"\n",
|
| 99 |
+
"# Gradio Interface Definition\n",
|
| 100 |
+
"gr.Interface(\n",
|
| 101 |
+
" fn=predict_demand,\n",
|
| 102 |
+
" inputs=[\n",
|
| 103 |
+
" gr.Textbox(label=\"Mapped Code\", placeholder=\"Enter mapped code here\"),\n",
|
| 104 |
+
" gr.Slider(minimum=1, maximum=12, step=1, label=\"Number of Months\")\n",
|
| 105 |
+
" ],\n",
|
| 106 |
+
" outputs=[\n",
|
| 107 |
+
" gr.Dataframe(label=\"Predicted Demand\")\n",
|
| 108 |
+
" ],\n",
|
| 109 |
+
" title=\"Demand Forecasting\",\n",
|
| 110 |
+
" description=\"Enter the mapped code and the number of months to predict future demand.\"\n",
|
| 111 |
+
").launch()\n"
|
| 112 |
+
]
|
| 113 |
+
}
|
| 114 |
+
]
|
| 115 |
+
}
|