Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +57 -0
- label_encoder.pkl +3 -0
- tabular_model1.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from fastai.tabular.all import load_learner
|
| 4 |
+
import random
|
| 5 |
+
import torch
|
| 6 |
+
import joblib
|
| 7 |
+
from sklearn.preprocessing import LabelEncoder
|
| 8 |
+
import numpy as np
|
| 9 |
+
|
| 10 |
+
# Set random seed for reproducibility
|
| 11 |
+
random.seed(42)
|
| 12 |
+
torch.manual_seed(42)
|
| 13 |
+
|
| 14 |
+
# Load the saved model and LabelEncoder
|
| 15 |
+
learn = load_learner('/home/venerable/Downloads/rohit/tabular_model1.pkl') # Replace with your model path
|
| 16 |
+
label_encoder = joblib.load('/home/venerable/Downloads/rohit/label_encoder.pkl') # Replace with your encoder path
|
| 17 |
+
|
| 18 |
+
# Function to make predictions
|
| 19 |
+
def predict_location(input_data):
|
| 20 |
+
input_df = pd.DataFrame([input_data])
|
| 21 |
+
pred_class, pred_idx, outputs = learn.predict(input_df.iloc[0])
|
| 22 |
+
|
| 23 |
+
# Apply softmax to get probabilities
|
| 24 |
+
probabilities = torch.nn.functional.softmax(torch.tensor(outputs), dim=0)
|
| 25 |
+
|
| 26 |
+
# Get the index of the maximum probability
|
| 27 |
+
pred_idx = np.argmax(probabilities.numpy())
|
| 28 |
+
|
| 29 |
+
# Convert the index to the corresponding location
|
| 30 |
+
location = label_encoder.inverse_transform([pred_idx])[0]
|
| 31 |
+
return location
|
| 32 |
+
|
| 33 |
+
# Streamlit app
|
| 34 |
+
def main():
|
| 35 |
+
st.title('Location Prediction App')
|
| 36 |
+
|
| 37 |
+
# Example input fields (replace with your actual input fields)
|
| 38 |
+
product_name = st.text_input('Product Name')
|
| 39 |
+
day_of_purchase = st.selectbox('Day of Purchase', ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'])
|
| 40 |
+
product_price = st.number_input('Product Price (INR)')
|
| 41 |
+
avg_purchase_value = st.number_input('Average Purchase Value (INR)')
|
| 42 |
+
|
| 43 |
+
# Prepare input data for prediction
|
| 44 |
+
input_data = {
|
| 45 |
+
'Product Name': product_name,
|
| 46 |
+
'Day of Purchase': day_of_purchase,
|
| 47 |
+
'Product Price (INR)': product_price,
|
| 48 |
+
'Average Purchase Value (INR)': avg_purchase_value
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
# Predict button
|
| 52 |
+
if st.button('Predict Location'):
|
| 53 |
+
prediction = predict_location(input_data)
|
| 54 |
+
st.success(f'Predicted Location: {prediction}')
|
| 55 |
+
|
| 56 |
+
if __name__ == '__main__':
|
| 57 |
+
main()
|
label_encoder.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3dd272a0c24c5806dedf8518cad756fe45edb00475086f874f47e1fc4c32969d
|
| 3 |
+
size 2589
|
tabular_model1.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:90a3211bd59b025c182e4bd894027cbd3cbdf3672a856fc6889be7d9bfdbc9a2
|
| 3 |
+
size 635546
|