import streamlit as st import pandas as pd import requests import io # Configure Streamlit page st.set_page_config( page_title="SuperKart Sales Prediction", page_icon="🛒", layout="wide" ) # Add custom CSS st.markdown(""" """, unsafe_allow_html=True) st.title("SuperKart Sales Prediction") st.write("Upload your CSV file to get sales predictions") # File uploader uploaded_file = st.file_uploader("Choose a CSV file", type="csv") if uploaded_file is not None: try: # Display the uploaded data df = pd.read_csv(uploaded_file) st.write("Preview of uploaded data:") st.dataframe(df.head()) # Add a button for predictions if st.button("Get Predictions", key="predict_button"): with st.spinner("Getting predictions..."): # Prepare the file for API request files = {"file": ("data.csv", uploaded_file.getvalue(), "text/csv")} try: # Make request to the backend API response = requests.post("https://huggingface.co/spaces/abhishek-kumar/superkart_sales_backend/predict", files=files) if response.status_code == 200: predictions = response.json()["predictions"] # Add predictions to the dataframe df["Predicted_Sales"] = predictions st.success("Predictions generated successfully!") st.write("Predictions:") st.dataframe(df) # Download button for results csv = df.to_csv(index=False) st.download_button( label="Download predictions", data=csv, file_name="predictions.csv", mime="text/csv" ) else: st.error(f"Error getting predictions from the API. Status code: {response.status_code}") except Exception as e: st.error(f"Error: {str(e)}") except Exception as e: st.error(f"Error reading the CSV file: {str(e)}")