File size: 1,780 Bytes
1403624 0a54e2f 1403624 5ac22a1 1403624 0405cf9 0a54e2f f0d402f 0658c67 f0d402f 0a474a7 930580c 96b9617 1403624 0a54e2f 930580c cd78f62 |
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 60 61 62 63 64 65 66 67 |
import os
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")
hf_token = os.environ["HF_TOKEN"]
hf_writer = gr.HuggingFaceDatasetSaver(hf_token, "diamond-price-predictor-logs")
model_output = gr.Label(label="Predicted Price (USD)")
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()
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,
theme=gr.themes.Soft(),
title="Diamond Price Predictor",
description="This API allows you to predict the price of a diamond given its attributes",
allow_flagging="auto",
flagging_callback=hf_writer,
concurrency_limit=8
)
demo.queue()
demo.launch(share=False) |