BabuRayapati's picture
Upload folder using huggingface_hub
989b9a7 verified
import streamlit as st
import pandas as pd
import requests
# Set the title of the Streamlit app
st.title("ExtraaLearn Status Prediction")
# Section for online prediction
st.subheader("Online Prediction")
# Collect user input for ExtraaLearn features
id_val = st.text_input("ID")
age = st.number_input("Age", min_value=0, max_value=100, step=1, value=25)
current_occupation = st.selectbox("Current Occupation", ["Student", "Professional", "Unemployed", "Other"])
first_interaction = st.selectbox("First Interaction", ["Website", "Mobile App"])
profile_completed = st.selectbox("Profile Completed", ["Low", "Medium", "High"])
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 (seconds)", min_value=0, step=1, value=10)
page_views_per_visit = st.number_input("Page Views per Visit", min_value=0.0, step=0.1, value=1.0)
last_activity = st.selectbox("Last Activity", ["Website Activity", "Email Activity", "Phone Activity", "Other"])
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"])
status = st.selectbox("Status", [0, 1]) # 0 = Not converted, 1 = Converted
# Convert user input into a DataFrame
input_data = pd.DataFrame([{
'ID': id_val,
'age': age,
'current_occupation': current_occupation,
'first_interaction': first_interaction,
'profile_completed': profile_completed,
'website_visits': website_visits,
'time_spent_on_website': time_spent_on_website,
'page_views_per_visit': page_views_per_visit,
'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,
'status': status
}])
# Make prediction when the "Predict" button is clicked
if st.button("Predict"):
response = requests.post("https://BabuRayapati-ExtraalearnFrontendDocker.hf.space/v1/extraalearn", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
if response.status_code == 200:
prediction = response.json()['Predicted status (in dollars)']
st.success(f"Predicted Product Status (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://BabuRayapati-ExtraalearnFrontendDocker.hf.space/v1/extraalearnbatch", 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.")