Spaces:
Runtime error

File size: 2,189 Bytes
34539c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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)
)