Update app.py
Browse files12345678910111213141516171819202122232425262728293031import gradio as gr# Replace with the ID of your model on Hugging Facemodel_id = "rmaitest/housepricepridiction"def predict(size, bedrooms, age):"""Predicts house price based on input features."""# Prepare input data as a dictionary (adjust based on your model)input_data = {"Size (sq ft)": size, "Number of Bedrooms": bedrooms, "Age of House (years)": age}# Send prediction request to Hugging Face Inference APIprediction = predictor(input_data)# Extract predicted pricepredicted_price = prediction[0]["predicted_price"]# Format the output with dollar sign and two decimal placesreturn f"Predicted Price: ${predicted_price:,.2f}"# Create the Gradio interfaceiface = gr.Interface(fn=predict,inputs=["number", "number", "number"], # Three numeric input fieldsoutputs="text", # Output is the predicted price (text, not number)title="House Price Prediction",description="Enter house details to predict the price using a publicly deployed model.")iface.launch(share=True)123456789101112131415161718192021222324252627282930!pip install gradiofrom huggingface_hub import from_pretrainedimport gradio as gr# Load the model from Hugging Face Hubrepo_id = "rmaitest/mlmodel2" # Your model repository IDmodel = from_pretrained(repo_id) # Loads the inference function (predict_price)def predict_with_hf_model(size, bedrooms, age):"""Predicts house price using the model from Hugging Face Hub."""# Call the loaded inference functionresult = model.predict_price(size=size, bedrooms=bedrooms, age=age)predicted_price = result["predicted_price"] # Extract the predicted price# Format the outputreturn f"Predicted Price: ${predicted_price:,.2f}"# Create the Gradio interfaceiface = gr.Interface(fn=predict_with_hf_model,inputs=["number", "number", "number"],outputs="text",title="House Price Prediction",description="Enter house details to predict the price.",)# Launch the interfaceiface.launch()
app.py+18-19