File size: 1,196 Bytes
55fbbef
8c733e2
 
 
55fbbef
8c733e2
 
 
 
 
 
 
55fbbef
 
8c733e2
 
 
 
 
 
55fbbef
8c733e2
 
 
55fbbef
 
 
 
 
 
 
 
 
 
 
8c733e2
 
 
55fbbef
 
 
 
 
8c733e2
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
import gradio as gr
import pandas as pd
from huggingface_hub import hf_hub_download
import joblib

# Load the model
repo_id = "rmaitest/mlmodel2"
model_file = "house_price_model.pkl"  # Adjust as necessary

# Download and load the model
model_path = hf_hub_download(repo_id, model_file)
model = joblib.load(model_path)

def predict_price(size, bedrooms, age):
    # Create a DataFrame from the input
    input_data = pd.DataFrame({
        'Size (sq ft)': [size],
        'Number of Bedrooms': [bedrooms],
        'Age of House (years)': [age]
    })
    
    # Make prediction
    prediction = model.predict(input_data)
    return prediction[0]

# Define the Gradio interface
iface = gr.Interface(
    fn=predict_price,
    inputs=[
        gr.Number(label="Size (sq ft)"),
        gr.Number(label="Number of Bedrooms"),
        gr.Number(label="Age of House (years)")
    ],
    outputs=gr.Number(label="Predicted Price ($)"),
    title="House Price Prediction",
    description="Enter the size, number of bedrooms, and age of the house to get the predicted price.",
    # Enable API mode for the Space
    api_open=True
)

# Launch the interface
if __name__ == "__main__":
    iface.launch()