Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import pandas as pd | |
| import requests | |
| # Set the title of the Streamlit app | |
| st.title("Extra Learn Status Prediction") | |
| # Section for online prediction | |
| st.subheader("Online Prediction") | |
| # Collect user input for property features | |
| age = st.number_input("age", min_value=1, value=75) | |
| profile_completed = st.selectbox("profile_completed", ["Yes", "No"]) | |
| current_occupation = st.selectbox("current_occupation", ["Unemployed", "Professional", "Student"]) | |
| last_activity =st.selectbox("last_activity", ["Yes", "No"]) | |
| first_interaction = st.selectbox("first_interaction", ["Yes", "No"]) | |
| referral = st.selectbox("referral", ["Yes", "No"]) | |
| digital_media = st.selectbox("digital_media", ["Yes", "No"]) | |
| # Convert user input into a DataFrame | |
| input_data = pd.DataFrame([{ | |
| 'age': age, | |
| 'profile_completed': profile_completed, | |
| 'current_occupation': current_occupation, | |
| 'first_interaction': first_interaction, | |
| 'last_activity':last_activity, | |
| 'referral': referral, | |
| 'digital_media': digital_media | |
| }]) | |
| # 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 Status'] | |
| st.success(f"Predicted Status: {prediction}") | |
| else: | |
| st.error("Error making prediction.") | |
| # Section for batch prediction | |
| st.subheader("Status Prediction") | |
| # Allow users to upload a CSV file for batch prediction | |
| uploaded_file = st.file_uploader("Upload CSV file for Status prediction", type=["csv"]) | |
| # Make batch prediction when the "Predict Batch" button is clicked | |
| if uploaded_file is not None: | |
| if st.button("Predict Status"): | |
| response = requests.post("https://<username>-<repo_id>.hf.space/v1/rentalbatch", files={"file": uploaded_file}) # Send file to Flask API | |
| if response.status_code == 200: | |
| predictions = response.json() | |
| st.success("Status predictions completed!") | |
| st.write(predictions) # Display the predictions | |
| else: | |
| st.error("Error making status prediction.") | |