Spaces:
Runtime error
Runtime error
Download app.py from AzharAbbas/construction_estimator: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/spaces/AzharAbbas/construction_estimator/resolve/main/app.py
- Command line
-
hf download hf://spaces/AzharAbbas/construction_estimator/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AzharAbbas/construction_estimator/resolve/main/app.py
2.19 kB
| import gradio as gr | |
| import pandas as pd | |
| import numpy as np | |
| import tensorflow as tf | |
| from joblib import load # or from sklearn.preprocessing import ... | |
| # other imports like your encoder/scaler imports | |
| # 1. Load model and preprocessing objects | |
| model = tf.keras.models.load_model('ann_model_manual.h5') | |
| scaler = load('scaler_manual.pkl') | |
| y_scaler = load('y_scaler_manual.pkl') | |
| encoder = load('encoder_manual.pkl') | |
| # app.py (Corrected) | |
| # ... (Previous imports and model/scaler loading) | |
| # 2. Define the main prediction function | |
| # You must list ALL required input variables here, separated by commas. | |
| def predict_construction_cost(Area, Floors, Type): | |
| # 1. Prepare data for prediction | |
| # Create a DataFrame or array from the inputs | |
| data = {'Area': [Area], 'Floors': [Floors], 'Type': [Type]} | |
| X_raw = pd.DataFrame(data) | |
| # *Insert your notebook's prediction logic here* | |
| # (e.g., Encoding 'Type', then scaling the data, running the prediction, and inverse scaling) | |
| # Example Step 2: Apply the encoder to the 'Type' feature | |
| # Note: You may need to handle one-hot encoding or label encoding here exactly as you did during training. | |
| # ... | |
| # Example Step 3 & 4: Scale and Predict | |
| # X_scaled = scaler.transform(X_processed_and_encoded) | |
| # prediction_scaled = model.predict(X_scaled) | |
| # Example Step 5: Inverse Scale to get the final cost | |
| # final_cost = y_scaler.inverse_transform(prediction_scaled)[0][0] | |
| # return f"The Estimated Cost is: ${final_cost:,.2f}" # Return the formatted cost | |
| return "Your final predicted cost" | |
| # 3. Define the Gradio Interface | |
| # The 'inputs' list MUST match the number and type of arguments in your function. | |
| demo = gr.Interface( | |
| fn=predict_construction_cost, | |
| inputs=[ | |
| gr.Number(label="Project Area (sq ft)"), | |
| gr.Slider(minimum=1, maximum=20, step=1, label="Number of Floors"), | |
| gr.Dropdown(choices=["Residential", "Commercial", "Industrial"], label="Construction Type"), | |
| # ... Add ALL your input components here | |
| ], | |
| outputs="text", | |
| # ... (Rest of your interface code) | |
| ) |