zaid-kamil commited on
Commit
7f78f4b
·
1 Parent(s): 03e5041

Added files

Browse files
Files changed (3) hide show
  1. app.py +58 -0
  2. diamond_price.joblib +3 -0
  3. training.ipynb +0 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from joblib import load
3
+ import os
4
+ import pandas as pd
5
+
6
+ # load the model
7
+ def load_model(path=""):
8
+ if os.path.exists(path):
9
+ model_dict = load(path)
10
+ return model_dict
11
+ else:
12
+ print("Model not found")
13
+
14
+ model_dict = load_model('diamond_price.joblib')
15
+ # prediction function
16
+ def diamond_price_regressor(caret, depth, table, x, y, z, cut, color, clarity):
17
+ model = model_dict['model']
18
+ target_converter = model_dict['quantile']
19
+ input_frame = pd.DataFrame({
20
+ 'carat': [caret],
21
+ 'cut': [cut],
22
+ 'color': [color],
23
+ 'clarity': [clarity],
24
+ 'depth': [depth],
25
+ 'table': [table],
26
+ 'x': [x],
27
+ 'y': [y],
28
+ 'z': [z]
29
+ })
30
+ print(input_frame)
31
+ pred = model.predict(input_frame)
32
+ pred = target_converter.inverse_transform(pred.reshape(-1, 1))
33
+ print(pred)
34
+ return f'Approx price is ${pred[0][0]:.2f}'
35
+
36
+ cut_choices = ['Ideal', 'Premium', 'Good', 'Very Good', 'Fair']
37
+ color_choices = ['E', 'I', 'J', 'H', 'F', 'G', 'D']
38
+ clarity_choices = ['SI2', 'SI1', 'VS1', 'VS2', 'VVS2', 'VVS1', 'I1', 'IF']
39
+
40
+ # gradio interface
41
+ ui = gr.Interface(
42
+ fn = diamond_price_regressor,
43
+ inputs = [
44
+ gr.Slider(minimum=0, maximum=10, step=.01, value=.7, label="Carat", info="1 carat = 0.2 grams"),
45
+ gr.Slider(minimum=0, maximum=100, step=.01, value=61, label="Depth", info="Total depth percentage"),
46
+ gr.Slider(minimum=0, maximum=100, step=.01, value=57, label="Table", info="Width of top of diamond relative to widest point"),
47
+ gr.Slider(minimum=0, maximum=100, step=.01, value=5, label="x", info="Length in mm"),
48
+ gr.Slider(minimum=0, maximum=100, step=.01, value=5, label="y", info="Width in mm"),
49
+ gr.Slider(minimum=0, maximum=100, step=.01, value=3.5, label="z", info="Height in mm"),
50
+ gr.Dropdown(cut_choices, label="Cut", value="Ideal", info="Cut quality"),
51
+ gr.Dropdown(color_choices, label="Color", value="E", info="Color grade"),
52
+ gr.Dropdown(clarity_choices, label="Clarity", value="SI2", info="Clarity grade")
53
+ ],
54
+ outputs = "text",
55
+ )
56
+
57
+ if __name__ == "__main__":
58
+ ui.launch()
diamond_price.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a317966b5e8d936934fd45dadca0f61c9959273ab1f1cf3d5db020ce2fd7428d
3
+ size 12623306
training.ipynb ADDED
The diff for this file is too large to render. See raw diff