File size: 1,713 Bytes
2912755
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e6800e
2912755
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import joblib

import gradio as gr
import pandas as pd

price_predictor = joblib.load('model-v1.joblib')

carat_input = gr.Number(label="Carat")

shape_input = gr.Dropdown(
    ['Round', 'Princess', 'Emerald', 'Asscher', 'Cushion', 'Radiant', 'Oval', 
     'Pear', 'Marquise'], 
     label="Shape"
)

cut_input = gr.Dropdown(
    ['Ideal', 'Premium', 'Very Good', 'Good', 'Fair'], 
    label="Cut"
)

color_input = gr.Dropdown(
    ['D', 'E', 'F', 'G', 'H', 'I', 'J'], 
    label="Color"
)

clarity_input = gr.Dropdown(
    ['IF', 'VVS1', 'VVS2', 'VS1', 'VS2', 'SI1', 'SI2', 'I1'], 
    label="Clarity"
)
report_input = gr.Dropdown(['GIA', 'IGI', 'HRD', 'AGS'], label="Report")
type_input = gr.Dropdown(['Natural', 'Lab Grown'], label="Type")

model_output = gr.Label(label="Predicted Price")

def predict_price(carat, shape, cut, color, clarity, report, type):
    sample = {
        'carat': carat,
        'shape': shape,
        'cut': cut,
        'color': color,
        'clarity': clarity,
        'report': report,
        'type': type,
    }
    data_point = pd.DataFrame([sample])
    prediction = price_predictor.predict(data_point).tolist()
    print(prediction)
    return prediction[0]

demo = gr.Interface(fn=predict_price,
                    inputs=[carat_input, shape_input, cut_input, color_input, 
                            clarity_input, report_input, type_input],
                    outputs=model_output,
                    title="Diamond Price Predictor",
                    description="This API allows you to predict the price of a diamond given its attributes",
                    flagging_options=["Incorrect", "Correct"])

demo.queue(concurrency_count=8)
demo.launch(share=False)