rmaitest commited on
Commit
55fbbef
·
verified ·
1 Parent(s): 030dbe0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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(
27
+ fn=predict_price,
28
+ inputs=[
29
+ gr.Number(label="Size (sq ft)"),
30
+ gr.Number(label="Number of Bedrooms"),
31
+ gr.Number(label="Age of House (years)")
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()