Spaces:
Sleeping
Sleeping
alperugurcan
commited on
Commit
•
4ef2b90
1
Parent(s):
a373624
Update app.py
Browse files
app.py
CHANGED
@@ -2,74 +2,34 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
import joblib
|
4 |
from huggingface_hub import hf_hub_download
|
5 |
-
import numpy as np
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
feature_names_path = hf_hub_download(repo_id="alperugurcan/mercedes", filename="feature_names.joblib")
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
# Most common X0 values with their frequencies
|
16 |
-
FEATURE_OPTIONS = {
|
17 |
-
"z (Most Common - 360 cases)": "z",
|
18 |
-
"ak (349 cases)": "ak",
|
19 |
"y (324 cases)": "y",
|
20 |
"ay (313 cases)": "ay",
|
21 |
"t (306 cases)": "t",
|
22 |
"x (300 cases)": "x",
|
23 |
"o (269 cases)": "o",
|
24 |
-
"f (227 cases)": "f",
|
25 |
"n (195 cases)": "n",
|
26 |
"w (182 cases)": "w"
|
27 |
}
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
# Create a dictionary with all features set to default values
|
35 |
-
input_dict = DEFAULT_VALUES.copy()
|
36 |
-
|
37 |
-
# Get the actual value from the selected option
|
38 |
-
selected_value = FEATURE_OPTIONS[selected_option]
|
39 |
-
|
40 |
-
# Create dummy variable columns for X0
|
41 |
-
for val in set(FEATURE_OPTIONS.values()):
|
42 |
-
col_name = f'X0_{val}'
|
43 |
-
input_dict[col_name] = 1 if val == selected_value else 0
|
44 |
-
|
45 |
-
# Create DataFrame with all features
|
46 |
-
df = pd.DataFrame([input_dict])
|
47 |
-
|
48 |
-
# Make prediction
|
49 |
-
if hasattr(model, '_Booster'):
|
50 |
-
booster = model._Booster
|
51 |
-
prediction = booster.predict(df)[0]
|
52 |
-
else:
|
53 |
-
prediction = model.predict(df)[0]
|
54 |
-
|
55 |
-
return f"Predicted manufacturing time: {prediction:.2f} seconds"
|
56 |
-
except Exception as e:
|
57 |
-
return f"Error in prediction: {str(e)}"
|
58 |
|
59 |
-
|
60 |
-
interface = gr.Interface(
|
61 |
fn=predict,
|
62 |
-
inputs=gr.Dropdown(
|
63 |
-
|
64 |
-
label="Select Manufacturing Configuration (X0)",
|
65 |
-
value=list(FEATURE_OPTIONS.keys())[0]
|
66 |
-
),
|
67 |
-
outputs=gr.Textbox(label="Prediction Result"),
|
68 |
title="Mercedes-Benz Manufacturing Time Predictor",
|
69 |
-
description="Select
|
70 |
-
examples=[[list(FEATURE_OPTIONS.keys())[0]]],
|
71 |
-
cache_examples=True,
|
72 |
theme=gr.themes.Soft()
|
73 |
-
)
|
74 |
-
|
75 |
-
interface.launch(debug=True)
|
|
|
2 |
import pandas as pd
|
3 |
import joblib
|
4 |
from huggingface_hub import hf_hub_download
|
|
|
5 |
|
6 |
+
model = joblib.load(hf_hub_download(repo_id="alperugurcan/mercedes", filename="mercedes_model.joblib"))
|
7 |
+
feature_names = joblib.load(hf_hub_download(repo_id="alperugurcan/mercedes", filename="feature_names.joblib"))
|
|
|
8 |
|
9 |
+
CONFIGS = {
|
10 |
+
"z (360 cases)": "z",
|
11 |
+
"ak (349 cases)": "ak",
|
|
|
|
|
|
|
|
|
|
|
12 |
"y (324 cases)": "y",
|
13 |
"ay (313 cases)": "ay",
|
14 |
"t (306 cases)": "t",
|
15 |
"x (300 cases)": "x",
|
16 |
"o (269 cases)": "o",
|
17 |
+
"f (227 cases)": "f",
|
18 |
"n (195 cases)": "n",
|
19 |
"w (182 cases)": "w"
|
20 |
}
|
21 |
|
22 |
+
def predict(option):
|
23 |
+
input_data = {name: 0.0 for name in feature_names}
|
24 |
+
input_data[f'X0_{CONFIGS[option]}'] = 1.0
|
25 |
+
prediction = model.predict(pd.DataFrame([input_data]))[0]
|
26 |
+
return f"Predicted manufacturing time: {prediction:.2f} seconds"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
gr.Interface(
|
|
|
29 |
fn=predict,
|
30 |
+
inputs=gr.Dropdown(choices=list(CONFIGS.keys()), label="Manufacturing Configuration"),
|
31 |
+
outputs=gr.Textbox(label="Prediction"),
|
|
|
|
|
|
|
|
|
32 |
title="Mercedes-Benz Manufacturing Time Predictor",
|
33 |
+
description="Select a manufacturing configuration to predict production time.",
|
|
|
|
|
34 |
theme=gr.themes.Soft()
|
35 |
+
).launch(debug=True)
|
|
|
|