Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import pandas as pd
|
|
| 2 |
import pickle
|
| 3 |
import gradio as gr
|
| 4 |
from sklearn.preprocessing import LabelEncoder
|
|
|
|
| 5 |
|
| 6 |
# --- Load dataset ---
|
| 7 |
df_original = pd.read_csv('AB_ELEVATORS_DATASET_final.csv')
|
|
@@ -66,6 +67,18 @@ def predict_price(
|
|
| 66 |
except Exception as e:
|
| 67 |
return f"β Error: {str(e)}", "β οΈ Please check inputs"
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
# --- Custom UI using Blocks ---
|
| 70 |
with gr.Blocks(theme=gr.themes.Soft(), title="AB Elevators") as demo:
|
| 71 |
|
|
@@ -83,12 +96,15 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AB Elevators") as demo:
|
|
| 83 |
with gr.Column():
|
| 84 |
brand = gr.Dropdown(categorical_options['BRAND NAME'], label="π’ Brand")
|
| 85 |
lift = gr.Dropdown(categorical_options['LIFT_TYPE'], label="π Lift Type")
|
|
|
|
| 86 |
door_frame = gr.Dropdown(categorical_options['DOOR_FRAME'], label="πͺ Door Frame")
|
| 87 |
|
| 88 |
with gr.Column():
|
| 89 |
door_type = gr.Dropdown(categorical_options['DOOR_TYPE'], label="πͺ Door Type")
|
|
|
|
| 90 |
cabin = gr.Dropdown(categorical_options['CABIN_MATERIAL'], label="π§± Cabin Material")
|
| 91 |
motor = gr.Dropdown(categorical_options['MOTOR_TYPE'], label="βοΈ Motor Type")
|
|
|
|
| 92 |
|
| 93 |
gr.Markdown("### π’ Configuration")
|
| 94 |
|
|
@@ -122,6 +138,25 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AB Elevators") as demo:
|
|
| 122 |
output_price = gr.Markdown()
|
| 123 |
output_status = gr.Markdown()
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
predict_btn.click(
|
| 126 |
fn=predict_price,
|
| 127 |
inputs=[brand, lift, door_frame, door_type, cabin, motor,
|
|
|
|
| 2 |
import pickle
|
| 3 |
import gradio as gr
|
| 4 |
from sklearn.preprocessing import LabelEncoder
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
# --- Load dataset ---
|
| 8 |
df_original = pd.read_csv('AB_ELEVATORS_DATASET_final.csv')
|
|
|
|
| 67 |
except Exception as e:
|
| 68 |
return f"β Error: {str(e)}", "β οΈ Please check inputs"
|
| 69 |
|
| 70 |
+
#Function to get image path from dropdown
|
| 71 |
+
def get_image_path(category, selection):
|
| 72 |
+
if selection is None:
|
| 73 |
+
return None
|
| 74 |
+
|
| 75 |
+
# Convert dropdown value β UPPERCASE filename
|
| 76 |
+
filename = selection.upper().replace(" ", "_") + ".jpg"
|
| 77 |
+
|
| 78 |
+
path = os.path.join("images", category, filename)
|
| 79 |
+
|
| 80 |
+
return path if os.path.exists(path) else None
|
| 81 |
+
|
| 82 |
# --- Custom UI using Blocks ---
|
| 83 |
with gr.Blocks(theme=gr.themes.Soft(), title="AB Elevators") as demo:
|
| 84 |
|
|
|
|
| 96 |
with gr.Column():
|
| 97 |
brand = gr.Dropdown(categorical_options['BRAND NAME'], label="π’ Brand")
|
| 98 |
lift = gr.Dropdown(categorical_options['LIFT_TYPE'], label="π Lift Type")
|
| 99 |
+
lift_img = gr.Image(label="Lift Type Preview", height=150) #Lift_Type Image Display
|
| 100 |
door_frame = gr.Dropdown(categorical_options['DOOR_FRAME'], label="πͺ Door Frame")
|
| 101 |
|
| 102 |
with gr.Column():
|
| 103 |
door_type = gr.Dropdown(categorical_options['DOOR_TYPE'], label="πͺ Door Type")
|
| 104 |
+
door_img = gr.Image(label="Door Type Preview", height=150)
|
| 105 |
cabin = gr.Dropdown(categorical_options['CABIN_MATERIAL'], label="π§± Cabin Material")
|
| 106 |
motor = gr.Dropdown(categorical_options['MOTOR_TYPE'], label="βοΈ Motor Type")
|
| 107 |
+
motor_img = gr.Image(label="Motor Type Preview", height=150)
|
| 108 |
|
| 109 |
gr.Markdown("### π’ Configuration")
|
| 110 |
|
|
|
|
| 138 |
output_price = gr.Markdown()
|
| 139 |
output_status = gr.Markdown()
|
| 140 |
|
| 141 |
+
# --- Image Updates ---
|
| 142 |
+
lift.change(
|
| 143 |
+
fn=lambda x: get_image_path("Lift_Type", x),
|
| 144 |
+
inputs=lift,
|
| 145 |
+
outputs=lift_img
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
door_type.change(
|
| 149 |
+
fn=lambda x: get_image_path("Door_Type", x),
|
| 150 |
+
inputs=door_type,
|
| 151 |
+
outputs=door_img
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
motor.change(
|
| 155 |
+
fn=lambda x: get_image_path("Motor_Type", x),
|
| 156 |
+
inputs=motor,
|
| 157 |
+
outputs=motor_img
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
predict_btn.click(
|
| 161 |
fn=predict_price,
|
| 162 |
inputs=[brand, lift, door_frame, door_type, cabin, motor,
|