Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,30 +12,40 @@ feature_names_path = hf_hub_download(repo_id="alperugurcan/mercedes", filename="
|
|
12 |
model = joblib.load(model_path)
|
13 |
feature_names = joblib.load(feature_names_path)
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
|
29 |
-
|
|
|
|
|
|
|
30 |
try:
|
31 |
-
#
|
32 |
-
|
33 |
-
|
|
|
|
|
34 |
|
35 |
-
#
|
36 |
-
|
|
|
|
|
37 |
|
38 |
-
#
|
|
|
|
|
|
|
39 |
if hasattr(model, '_Booster'):
|
40 |
booster = model._Booster
|
41 |
prediction = booster.predict(df)[0]
|
@@ -46,20 +56,20 @@ def predict(*features):
|
|
46 |
except Exception as e:
|
47 |
return f"Error in prediction: {str(e)}"
|
48 |
|
49 |
-
# Create interface with
|
50 |
-
inputs = create_input_components()
|
51 |
-
output = gr.Textbox(label="Prediction Result")
|
52 |
-
|
53 |
-
# Create the interface
|
54 |
interface = gr.Interface(
|
55 |
fn=predict,
|
56 |
-
inputs=
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
62 |
)
|
63 |
|
64 |
-
# Launch with debugging enabled
|
65 |
interface.launch(debug=True)
|
|
|
12 |
model = joblib.load(model_path)
|
13 |
feature_names = joblib.load(feature_names_path)
|
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 |
+
# Default values for other features
|
30 |
+
DEFAULT_VALUES = {name: 0.0 for name in feature_names}
|
31 |
+
|
32 |
+
def predict(selected_option):
|
33 |
try:
|
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]
|
|
|
56 |
except Exception as e:
|
57 |
return f"Error in prediction: {str(e)}"
|
58 |
|
59 |
+
# Create interface with dropdown
|
|
|
|
|
|
|
|
|
60 |
interface = gr.Interface(
|
61 |
fn=predict,
|
62 |
+
inputs=gr.Dropdown(
|
63 |
+
choices=list(FEATURE_OPTIONS.keys()),
|
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 one of the most common manufacturing configurations to predict the production time. The options are sorted by frequency of occurrence in the training data.",
|
70 |
+
examples=[[list(FEATURE_OPTIONS.keys())[0]]],
|
71 |
+
cache_examples=True,
|
72 |
+
theme=gr.themes.Soft()
|
73 |
)
|
74 |
|
|
|
75 |
interface.launch(debug=True)
|