Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
from huggingface_hub import hf_hub_download
|
4 |
import joblib
|
|
|
|
|
5 |
|
6 |
# Load the model
|
7 |
repo_id = "rmaitest/mlmodel2"
|
@@ -11,6 +13,7 @@ model_file = "house_price_model.pkl" # Adjust as necessary
|
|
11 |
model_path = hf_hub_download(repo_id, model_file)
|
12 |
model = joblib.load(model_path)
|
13 |
|
|
|
14 |
def predict_price(size, bedrooms, age):
|
15 |
# Create a DataFrame from the input
|
16 |
input_data = pd.DataFrame({
|
@@ -23,7 +26,7 @@ def predict_price(size, bedrooms, age):
|
|
23 |
prediction = model.predict(input_data)
|
24 |
return prediction[0]
|
25 |
|
26 |
-
# Define the Gradio interface
|
27 |
iface = gr.Interface(
|
28 |
fn=predict_price,
|
29 |
inputs=[
|
@@ -36,8 +39,14 @@ iface = gr.Interface(
|
|
36 |
description="Enter the size, number of bedrooms, and age of the house to get the predicted price."
|
37 |
)
|
38 |
|
39 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
if __name__ == "__main__":
|
41 |
-
iface.launch()
|
42 |
|
43 |
|
|
|
2 |
import pandas as pd
|
3 |
from huggingface_hub import hf_hub_download
|
4 |
import joblib
|
5 |
+
from fastapi import FastAPI
|
6 |
+
from gradio import fastapi as gr_fastapi
|
7 |
|
8 |
# Load the model
|
9 |
repo_id = "rmaitest/mlmodel2"
|
|
|
13 |
model_path = hf_hub_download(repo_id, model_file)
|
14 |
model = joblib.load(model_path)
|
15 |
|
16 |
+
# Define the prediction function
|
17 |
def predict_price(size, bedrooms, age):
|
18 |
# Create a DataFrame from the input
|
19 |
input_data = pd.DataFrame({
|
|
|
26 |
prediction = model.predict(input_data)
|
27 |
return prediction[0]
|
28 |
|
29 |
+
# Define the Gradio interface
|
30 |
iface = gr.Interface(
|
31 |
fn=predict_price,
|
32 |
inputs=[
|
|
|
39 |
description="Enter the size, number of bedrooms, and age of the house to get the predicted price."
|
40 |
)
|
41 |
|
42 |
+
# Create FastAPI app
|
43 |
+
app = FastAPI()
|
44 |
+
|
45 |
+
# Mount Gradio as an API on the /predict endpoint
|
46 |
+
app = gr_fastapi.mount_gradio_app(app, iface, path="/predict")
|
47 |
+
|
48 |
+
# Launch Gradio app (optionally with API)
|
49 |
if __name__ == "__main__":
|
50 |
+
iface.launch(share=True)
|
51 |
|
52 |
|