Update app.py
Browse files1234567845910111213141589101116171813141516171819201920212425262223242528262728293130!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)
# Replace with the ID of your model on Hugging Facemodel_id = "rmaitest/housepricepridiction"
def predict_with_hf_model(size, bedrooms, age): """Predicts house price using the model from Hugging Face Hub.""" # Call the loaded inference function result = model.predict_price(size=size, bedrooms=bedrooms, age=age) predicted_price = result["predicted_price"] # Extract the predicted price
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} # Format the output return f"Predicted Price: ${predicted_price:,.2f}"
# Send prediction request to Hugging Face Inference API prediction = predictor(input_data)
# Extract predicted price predicted_price = prediction[0]["predicted_price"]
# Format the output with dollar sign and two decimal places return f"Predicted Price: ${predicted_price:,.2f}"
# Create the Gradio interfaceiface = gr.Interface( fn=predict, inputs=["number", "number", "number"], # Three numeric input fields outputs="text", # Output is the predicted price (text, not number) fn=predict_with_hf_model, inputs=["number", "number", "number"], outputs="text", title="House Price Prediction", description="Enter house details to predict the price using a publicly deployed model." description="Enter house details to predict the price.",)
# Launch the interfaceiface.launch(share=True)iface.launch()app.py+18-19