first upload for app.py, req, model-v1
Browse files- app.py +67 -0
- model-v1.joblib +3 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import joblib
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
price_predictor = joblib.load('model-v1.joblib')
|
8 |
+
|
9 |
+
carat_input = gr.Number(label="Carat")
|
10 |
+
|
11 |
+
shape_input = gr.Dropdown(
|
12 |
+
['Round', 'Princess', 'Emerald', 'Asscher', 'Cushion', 'Radiant', 'Oval',
|
13 |
+
'Pear', 'Marquise'],
|
14 |
+
label="Shape"
|
15 |
+
)
|
16 |
+
|
17 |
+
cut_input = gr.Dropdown(
|
18 |
+
['Ideal', 'Premium', 'Very Good', 'Good', 'Fair'],
|
19 |
+
label="Cut"
|
20 |
+
)
|
21 |
+
|
22 |
+
color_input = gr.Dropdown(
|
23 |
+
['D', 'E', 'F', 'G', 'H', 'I', 'J'],
|
24 |
+
label="Color"
|
25 |
+
)
|
26 |
+
|
27 |
+
clarity_input = gr.Dropdown(
|
28 |
+
['IF', 'VVS1', 'VVS2', 'VS1', 'VS2', 'SI1', 'SI2', 'I1'],
|
29 |
+
label="Clarity"
|
30 |
+
)
|
31 |
+
report_input = gr.Dropdown(['GIA', 'IGI', 'HRD', 'AGS'], label="Report")
|
32 |
+
type_input = gr.Dropdown(['Natural', 'Lab Grown'], label="Type")
|
33 |
+
|
34 |
+
# hf_token = os.environ["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"]
|
35 |
+
# hf_writer = gr.HuggingFaceDatasetSaver(hf_token, "diamond-price-predictor-logs")
|
36 |
+
|
37 |
+
model_output = gr.Label(label="Predicted Price (USD)")
|
38 |
+
|
39 |
+
def predict_price(carat, shape, cut, color, clarity, report, type):
|
40 |
+
sample = {
|
41 |
+
'carat': carat,
|
42 |
+
'shape': shape,
|
43 |
+
'cut': cut,
|
44 |
+
'color': color,
|
45 |
+
'clarity': clarity,
|
46 |
+
'report': report,
|
47 |
+
'type': type,
|
48 |
+
}
|
49 |
+
data_point = pd.DataFrame([sample])
|
50 |
+
prediction = price_predictor.predict(data_point).tolist()
|
51 |
+
return prediction[0]
|
52 |
+
|
53 |
+
demo = gr.Interface(
|
54 |
+
fn=predict_price,
|
55 |
+
inputs=[carat_input, shape_input, cut_input, color_input,
|
56 |
+
clarity_input, report_input, type_input],
|
57 |
+
outputs=model_output,
|
58 |
+
theme=gr.themes.Soft(),
|
59 |
+
title="Diamond Price Predictor",
|
60 |
+
description="This API allows you to predict the price of a diamond given its attributes",
|
61 |
+
# allow_flagging="auto",
|
62 |
+
# flagging_callback=hf_writer,
|
63 |
+
concurrency_limit=8
|
64 |
+
)
|
65 |
+
|
66 |
+
demo.queue()
|
67 |
+
demo.launch(share=False)
|
model-v1.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b1cc1943364228998ca7b8eb1b73a8adfc892217283555cfc8c961e1c75794b0
|
3 |
+
size 67248
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.22.0
|
2 |
+
pandas==1.4.0
|
3 |
+
scikit-learn==1.2.0
|