Spaces:
Sleeping
Sleeping
File size: 1,583 Bytes
6a69f5f 55fbbef 8c733e2 8a57db9 6a69f5f 55fbbef 8c733e2 55fbbef 8a57db9 55fbbef 8c733e2 55fbbef 8c733e2 55fbbef 8a57db9 55fbbef 722ddd6 55fbbef 8a57db9 6a69f5f 8a57db9 6a69f5f 55fbbef 8a57db9 8c733e2 722ddd6 6a69f5f |
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 58 59 |
pip install gradio fastapi uvicorn
import gradio as gr
import pandas as pd
from huggingface_hub import hf_hub_download
import joblib
from fastapi import FastAPI
from gradio.routes import Route
# 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)
# Define the prediction function
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."
)
# Create FastAPI app
app = FastAPI()
# Create a route for the /predict API endpoint
@app.post("/predict")
async def predict(size: float, bedrooms: int, age: int):
# Call the Gradio function manually for the API route
return iface.fn(size, bedrooms, age)
# Launch Gradio interface (only for UI purposes, if needed)
if __name__ == "__main__":
iface.launch(share=True)
|