Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import numpy as np | |
| import pickle | |
| import streamlit.components.v1 as components | |
| from sklearn.preprocessing import LabelEncoder | |
| le = LabelEncoder() | |
| # Load the pickled model | |
| def load_model(): | |
| return pickle.load(open('Diamond_Price_Prediction_LinearRegression.pkl', 'rb')) | |
| # Function for model prediction | |
| def model_prediction(model, features): | |
| predicted = str(model.predict(features)[0]) | |
| return predicted | |
| def transform(text): | |
| text = le.fit_transform(text) | |
| return text[0] | |
| def app_design(): | |
| # Add input fields for High, Open, and Low values | |
| image = 'Diamond price image.png' | |
| st.image(image, use_column_width=True) | |
| st.subheader("Enter the following values:") | |
| Carat = st.number_input("Carat(Weight of Daimond)") | |
| Cut = st.text_input("Cut(Quality) ('Ideal','Premium','Good','Very Good','Fair')") | |
| Cut = transform([Cut]) | |
| Color = st.text_input("Color ('E','I','J','H','F','G','D')") | |
| Color=transform([Color]) | |
| Clarity = st.text_input("Clarity ('SI2','SI1','VS1','VS2','VVS2','VVS1','I1','IF')") | |
| Clarity=transform([Clarity]) | |
| Depth = st.number_input("Depth") | |
| Table = st.number_input("Table") | |
| X_length = st.number_input("X length") | |
| Y_width = st.number_input("Y width") | |
| Z_depth = st.number_input("Z depth") | |
| # Create a feature list from the user inputs | |
| features = [[Carat,Cut,Color,Clarity,Depth,Table,X_length,Y_width,Z_depth]] | |
| # Load the model | |
| model = load_model() | |
| # Make a prediction when the user clicks the "Predict" button | |
| if st.button('Predict Price'): | |
| predicted_value = model_prediction(model, features) | |
| st.success(f"The Price is: {predicted_value}") | |
| def main(): | |
| # Set the app title and add your website name and logo | |
| st.set_page_config( | |
| page_title="Diamond Price Prediction.", | |
| page_icon=":chart_with_upwards_trend:", | |
| ) | |
| st.title("Welcome to our Diamond Price Prediction App!") | |
| app_design() | |
| if __name__ == '__main__': | |
| main() |