Spaces:
Runtime error
Runtime error
Nguyen Quang Truong
commited on
Commit
·
18fc856
1
Parent(s):
a82860f
[Upload]
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
from sklearn.linear_model import LinearRegression
|
5 |
+
import pickle
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
with open('./ML_APP/model.pkl', 'rb') as file:
|
10 |
+
model = pickle.load(file)
|
11 |
+
|
12 |
+
|
13 |
+
def proLocation(location):
|
14 |
+
if location=='Rural':
|
15 |
+
return 0
|
16 |
+
elif location=='Urban':
|
17 |
+
return 1
|
18 |
+
else:
|
19 |
+
return 2
|
20 |
+
|
21 |
+
def predict_loan_amount(gender, age, income, income_stability, property_age, property_price, property_location):
|
22 |
+
input_data = {
|
23 |
+
|
24 |
+
"Gender": [1 if gender == 'M' else 0],
|
25 |
+
"Age": [age],
|
26 |
+
"Income (USD)": [income],
|
27 |
+
"Income Stability": [1 if income_stability == 'Low' else 0],
|
28 |
+
"Property Age": [property_age],
|
29 |
+
"Property Price": [property_price],
|
30 |
+
"Property Location": [proLocation(property_location)],
|
31 |
+
|
32 |
+
}
|
33 |
+
input_df = pd.DataFrame(input_data)
|
34 |
+
|
35 |
+
prediction = model.predict(input_df.to_numpy())
|
36 |
+
return prediction[0]
|
37 |
+
|
38 |
+
# Gradio interface
|
39 |
+
iface = gr.Interface(
|
40 |
+
fn=predict_loan_amount,
|
41 |
+
inputs=[
|
42 |
+
gr.Radio(['F', 'M'], label='Gender'),
|
43 |
+
gr.Slider(18, 70, step=1, label='Age'),
|
44 |
+
gr.Number(label='Income (USD)'),
|
45 |
+
gr.Radio(['Low', 'High'], label='Income Stability'),
|
46 |
+
gr.Number(label='Property Age'),
|
47 |
+
gr.Number(label='Property Price'),
|
48 |
+
gr.Radio(['Rural', 'Urban', 'Semi-Urban'], label='Property Location'),
|
49 |
+
],
|
50 |
+
outputs="number",
|
51 |
+
live=True
|
52 |
+
)
|
53 |
+
|
54 |
+
iface.launch()
|
model.pkl
ADDED
Binary file (703 Bytes). View file
|
|