rmaitest commited on
Commit
8c733e2
·
verified ·
1 Parent(s): 2f177f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -19
app.py CHANGED
@@ -1,26 +1,27 @@
1
  import gradio as gr
2
- import requests
 
 
3
 
4
- # Define the Gradio app URL for API access
5
- API_URL = "https://huggingface.co/spaces/rmaitest/demoforml22oct/run/predict"
 
 
 
 
 
6
 
7
  def predict_price(size, bedrooms, age):
8
- # Prepare the data in the required format for the API request
9
- payload = {
10
- "data": [size, bedrooms, age]
11
- }
12
-
13
- # Send request to the Gradio app API
14
- response = requests.post(API_URL, json=payload)
15
 
16
- # Handle the response
17
- if response.status_code == 200:
18
- result = response.json()
19
- # Extract the prediction from the response
20
- prediction = result["data"][0]
21
- return prediction
22
- else:
23
- return "Error: Unable to get prediction."
24
 
25
  # Define the Gradio interface
26
  iface = gr.Interface(
@@ -32,9 +33,12 @@ iface = gr.Interface(
32
  ],
33
  outputs=gr.Number(label="Predicted Price ($)"),
34
  title="House Price Prediction",
35
- description="Enter the size, number of bedrooms, and age of the house to get the predicted price."
 
 
36
  )
37
 
38
  # Launch the interface
39
  if __name__ == "__main__":
40
  iface.launch()
 
 
1
  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"
8
+ model_file = "house_price_model.pkl" # Adjust as necessary
9
+
10
+ # Download and load the model
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({
17
+ 'Size (sq ft)': [size],
18
+ 'Number of Bedrooms': [bedrooms],
19
+ 'Age of House (years)': [age]
20
+ })
 
21
 
22
+ # Make prediction
23
+ prediction = model.predict(input_data)
24
+ return prediction[0]
 
 
 
 
 
25
 
26
  # Define the Gradio interface
27
  iface = gr.Interface(
 
33
  ],
34
  outputs=gr.Number(label="Predicted Price ($)"),
35
  title="House Price Prediction",
36
+ description="Enter the size, number of bedrooms, and age of the house to get the predicted price.",
37
+ # Enable API mode for the Space
38
+ api_open=True
39
  )
40
 
41
  # Launch the interface
42
  if __name__ == "__main__":
43
  iface.launch()
44
+