jackfroooot's picture
Upload folder using huggingface_hub
21dae8e verified
raw
history blame
3.45 kB
import streamlit as st
import pandas as pd
import requests
# Set the title of the Streamlit app
st.title("ExtraaLearn Customer Predictor")
st.subheader("Online Prediction")
# Collect user input for property features
age = st.number_input("age", min_value=5, max_value=90, step=1, value=30)
website_visits = st.number_input("website_visits", min_value=0, step=1, value=1)
time_spent_on_website = st.number_input("time_spent_on_website", min_value=0, step=1, value=1)
page_views_per_visit = st.number_input("page_views_per_visit", min_value=0, step=1, value=1)
current_occupation = st.selectbox("current_occupation", ["Professional", "Student", "Unemployed"])
first_interaction = st.selectbox("first_interaction", ["Mobile App", "Website"])
profile_completed = st.selectbox("profile_completed", ["Medium", "High", "Low"])
last_activity = st.selectbox("last_activity", ["Website Activity", "Email Activity", "Phone Activity"])
print_media_type1 = st.selectbox("print_media_type1", ["Yes", "No"])
print_media_type2 = st.selectbox("print_media_type2", ["Yes", "No"])
digital_media = st.selectbox("digital_media", ["Yes", "No"])
educational_channels = st.selectbox("educational_channels", ["Yes", "No"])
referral = st.selectbox("referral", ["Yes", "No"])
# Convert user input into a DataFrame
input_data = pd.DataFrame([{
'age' : 'age',
'website_visits' : 'website_visits',
'time_spent_on_website' : 'time_spent_on_website',
'page_views_per_visit' : 'page_views_per_visit',
'current_occupation' : 'current_occupation',
'first_interaction' : 'first_interaction',
'profile_completed' : 'profile_completed',
'last_activity' : 'last_activity',
'print_media_type1' : 'print_media_type1',
'print_media_type2' : 'print_media_type2',
'digital_media' : 'digital_media',
'educational_channels' : 'educational_channels',
'referral' : 'referral'
}])
# Make prediction when the "Predict" button is clicked
if st.button("Predict"):
response = requests.post("https://<username>-<repo_id>.hf.space/v1/rental", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
if response.status_code == 200:
prediction = response.json()['Predicted Price (in dollars)']
st.success(f"Predicted Rental Price (in dollars): {prediction}")
else:
st.error("Error making prediction.")
# Section for batch prediction
st.subheader("Batch Prediction")
# Allow users to upload a CSV file for batch prediction
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
# Make batch prediction when the "Predict Batch" button is clicked
if uploaded_file is not None:
if st.button("Predict Batch"):
response = requests.post("https://jackfroooot-AssignmentExtraaLearnBackend.hf.space/v1/rentalbatch", files={"file": uploaded_file}) # Send file to Flask API
if response.status_code == 200:
predictions = response.json()
st.success("Batch predictions completed!")
st.write(predictions) # Display the predictions
else:
st.error("Error making batch prediction.")