febbrri commited on
Commit
45d6f8f
·
verified ·
1 Parent(s): abb6905

Delete app

Browse files
Files changed (1) hide show
  1. app +0 -50
app DELETED
@@ -1,50 +0,0 @@
1
-
2
- import gradio as gr
3
- import pandas as pd
4
- import joblib
5
-
6
- # Load model
7
- model = joblib.load("demand_forecasting_model.pkl")
8
-
9
- # Ordinal encoder (harus sama urutannya dengan saat training)
10
- from sklearn.preprocessing import OrdinalEncoder
11
- encoder = OrdinalEncoder()
12
- encoder.fit([
13
- ['A', 'New York'], ['B', 'Los Angeles'], ['C', 'Chicago'], ['D', 'Houston'], ['E', 'Phoenix']
14
- ]) # dummy untuk encode ulang di input manual
15
-
16
- # Fungsi prediksi untuk input manual
17
- def predict_demand(product_type, price, stock, location, lead_time):
18
- data = pd.DataFrame([[product_type, price, stock, location, lead_time]],
19
- columns=["Product type", "Price", "Stock levels", "Location", "Lead time"])
20
- data[["Product type", "Location"]] = encoder.transform(data[["Product type", "Location"]])
21
- prediction = model.predict(data)
22
- return round(prediction[0], 2)
23
-
24
- # Fungsi prediksi dari file CSV
25
- def predict_from_csv(file):
26
- df = pd.read_csv(file.name)
27
- df[["Product type", "Location"]] = encoder.transform(df[["Product type", "Location"]])
28
- preds = model.predict(df[["Product type", "Price", "Stock levels", "Location", "Lead time"]])
29
- df["Predicted Demand"] = preds
30
- return df
31
-
32
- # Gradio antarmuka
33
- with gr.Blocks() as demo:
34
- gr.Markdown("# 📦 Demand Forecasting App")
35
- with gr.Tab("Input Manual"):
36
- product_type = gr.Dropdown(["A", "B", "C", "D", "E"], label="Product Type")
37
- price = gr.Number(label="Price")
38
- stock = gr.Number(label="Stock Levels")
39
- location = gr.Dropdown(["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"], label="Location")
40
- lead_time = gr.Number(label="Lead Time (days)")
41
- predict_btn = gr.Button("Predict Demand")
42
- output = gr.Textbox(label="Predicted Demand")
43
- predict_btn.click(fn=predict_demand, inputs=[product_type, price, stock, location, lead_time], outputs=output)
44
-
45
- with gr.Tab("Upload CSV"):
46
- csv_input = gr.File(label="Upload CSV", file_types=[".csv"])
47
- csv_output = gr.Dataframe(label="CSV with Predictions")
48
- csv_input.change(fn=predict_from_csv, inputs=csv_input, outputs=csv_output)
49
-
50
- demo.launch()