Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
# Replace with the ID of your model on Hugging Face
|
| 5 |
-
model_id = "rmaitest/housepricepridiction"
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# Prepare input data as a dictionary (adjust based on your model)
|
| 11 |
-
input_data = {"Size (sq ft)": size, "Number of Bedrooms": bedrooms, "Age of House (years)": age}
|
| 12 |
|
| 13 |
-
# Send prediction request to Hugging Face Inference API
|
| 14 |
-
prediction = predictor(input_data)
|
| 15 |
-
|
| 16 |
-
# Extract predicted price
|
| 17 |
-
predicted_price = prediction[0]["predicted_price"]
|
| 18 |
-
|
| 19 |
-
# Format the output with dollar sign and two decimal places
|
| 20 |
-
return f"Predicted Price: ${predicted_price:,.2f}"
|
| 21 |
|
| 22 |
# Create the Gradio interface
|
| 23 |
iface = gr.Interface(
|
| 24 |
-
fn=
|
| 25 |
-
inputs=["number", "number", "number"],
|
| 26 |
-
outputs="text",
|
| 27 |
title="House Price Prediction",
|
| 28 |
-
description="Enter house details to predict the price
|
| 29 |
)
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
| 1 |
+
!pip install gradio
|
| 2 |
+
from huggingface_hub import from_pretrained
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
# Load the model from Hugging Face Hub
|
| 6 |
+
repo_id = "rmaitest/mlmodel2" # Your model repository ID
|
| 7 |
+
model = from_pretrained(repo_id) # Loads the inference function (predict_price)
|
| 8 |
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
def predict_with_hf_model(size, bedrooms, age):
|
| 11 |
+
"""Predicts house price using the model from Hugging Face Hub."""
|
| 12 |
+
# Call the loaded inference function
|
| 13 |
+
result = model.predict_price(size=size, bedrooms=bedrooms, age=age)
|
| 14 |
+
predicted_price = result["predicted_price"] # Extract the predicted price
|
| 15 |
|
| 16 |
+
# Format the output
|
| 17 |
+
return f"Predicted Price: ${predicted_price:,.2f}"
|
|
|
|
|
|
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Create the Gradio interface
|
| 21 |
iface = gr.Interface(
|
| 22 |
+
fn=predict_with_hf_model,
|
| 23 |
+
inputs=["number", "number", "number"],
|
| 24 |
+
outputs="text",
|
| 25 |
title="House Price Prediction",
|
| 26 |
+
description="Enter house details to predict the price.",
|
| 27 |
)
|
| 28 |
|
| 29 |
+
# Launch the interface
|
| 30 |
+
iface.launch()
|