Commit
·
0a54e2f
1
Parent(s):
c23693f
application file
Browse files
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import joblib
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
price_predictor = joblib.load('model-v1.joblib')
|
7 |
+
|
8 |
+
carat_input = gr.Number(label="Carat")
|
9 |
+
|
10 |
+
shape_input = gr.Dropdown(
|
11 |
+
['Round', 'Princess', 'Emerald', 'Asscher', 'Cushion', 'Radiant', 'Oval',
|
12 |
+
'Pear', 'Marquise'],
|
13 |
+
label="Shape"
|
14 |
+
)
|
15 |
+
|
16 |
+
cut_input = gr.Dropdown(
|
17 |
+
['Ideal', 'Premium', 'Very Good', 'Good', 'Fair'],
|
18 |
+
label="Cut"
|
19 |
+
)
|
20 |
+
|
21 |
+
color_input = gr.Dropdown(
|
22 |
+
['D', 'E', 'F', 'G', 'H', 'I', 'J'],
|
23 |
+
label="Color"
|
24 |
+
)
|
25 |
+
|
26 |
+
clarity_input = gr.Dropdown(
|
27 |
+
['IF', 'VVS1', 'VVS2', 'VS1', 'VS2', 'SI1', 'SI2', 'I1'],
|
28 |
+
label="Clarity"
|
29 |
+
)
|
30 |
+
report_input = gr.Dropdown(['GIA', 'IGI', 'HRD', 'AGS'], label="Report")
|
31 |
+
type_input = gr.Dropdown(['Natural', 'Lab Grown'], label="Type")
|
32 |
+
|
33 |
+
model_output = gr.Label(label="Predicted Price")
|
34 |
+
|
35 |
+
def predict_price(carat, shape, cut, color, clarity, report, type):
|
36 |
+
sample = {
|
37 |
+
'carat': carat,
|
38 |
+
'shape': shape,
|
39 |
+
'cut': cut,
|
40 |
+
'color': color,
|
41 |
+
'clarity': clarity,
|
42 |
+
'report': report,
|
43 |
+
'type': type,
|
44 |
+
}
|
45 |
+
data_point = pd.DataFrame([sample])
|
46 |
+
prediction = price_predictor.predict(data_point).tolist()
|
47 |
+
return prediction[0]
|
48 |
+
|
49 |
+
demo = gr.Interface(fn=predict_price,
|
50 |
+
inputs=[carat_input, shape_input, cut_input, color_input,
|
51 |
+
clarity_input, report_input, type_input],
|
52 |
+
outputs=model_output,
|
53 |
+
title="Diamond Price Predictor",
|
54 |
+
description="This API allows you to predict the price of a diamond given its attributes",
|
55 |
+
flagging_options=["Incorrect", "Correct"])
|
56 |
+
|
57 |
+
demo.queue(concurrency_count=3)
|
58 |
+
demo.launch(share=True)
|