Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import joblib
|
3 |
+
import gradio as gr
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
# Load the pre-trained model
|
7 |
+
price_predictor = joblib.load("model-v3.joblib")
|
8 |
+
|
9 |
+
# Define the input components for the Gradio interface
|
10 |
+
carat_input = gr.Number(label="Carat")
|
11 |
+
shape_input = gr.Dropdown(['Round', 'Emerald', 'Marquise', 'Princess', 'Pear', 'Heart',
|
12 |
+
'Oval', 'Cushion', 'Asscher', 'Radiant'], label='Shape')
|
13 |
+
cut_input = gr.Dropdown(['Very Good', 'Ideal', 'Super Ideal', 'Good', 'Fair'], label='Cut')
|
14 |
+
color_input = gr.Dropdown(['J', 'I', 'E', 'F', 'G', 'H', 'D'], label='Color')
|
15 |
+
clarity_input = gr.Dropdown(['SI2', 'SI1', 'VS2', 'VVS1', 'VS1', 'VVS2', 'IF', 'FL'], label='Clarity')
|
16 |
+
report_input = gr.Dropdown(['GIA', 'HRD', 'IGI', 'GCAL'], label='Report')
|
17 |
+
type_input = gr.Dropdown(['natural', 'lab'], label='Type')
|
18 |
+
|
19 |
+
# Define the output component for the Gradio interface
|
20 |
+
model_output = gr.Label(label="Predicted Price (USD)")
|
21 |
+
|
22 |
+
# Define the prediction function
|
23 |
+
def predict_price(carat, shape, cut, color, clarity, report, type):
|
24 |
+
sample = {'carat': carat, # Corrected key here
|
25 |
+
'shape': shape,
|
26 |
+
'cut': cut,
|
27 |
+
'color': color,
|
28 |
+
'clarity': clarity,
|
29 |
+
'report': report,
|
30 |
+
'type': type}
|
31 |
+
data_point = pd.DataFrame([sample])
|
32 |
+
prediction = price_predictor.predict(data_point).tolist()
|
33 |
+
return prediction[0]
|
34 |
+
|
35 |
+
# Create the Gradio interface
|
36 |
+
demo = gr.Interface(
|
37 |
+
fn=predict_price,
|
38 |
+
inputs=[carat_input, shape_input, cut_input, color_input, clarity_input, report_input, type_input],
|
39 |
+
outputs=model_output,
|
40 |
+
theme=gr.themes.Soft(),
|
41 |
+
title="Predictor of Diamond Valuations",
|
42 |
+
description="This application enables you to estimate the value of diamonds based on their characteristics",
|
43 |
+
# Uncomment the following lines if you have set up flagging
|
44 |
+
# allow_flagging="auto",
|
45 |
+
# flagging_callback=hf_writer,
|
46 |
+
concurrency_limit=8
|
47 |
+
)
|
48 |
+
|
49 |
+
# Launch the application
|
50 |
+
demo.launch()
|