Spaces:
Sleeping
Sleeping
File size: 2,664 Bytes
f58abe5 2e2e73d a536b12 2e2e73d a536b12 2e2e73d a536b12 2e2e73d a536b12 2e2e73d a536b12 267c72e a536b12 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
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("""
<style>
.stButton>button {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 10px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.stButton>button:hover {
background-color: #45a049;
}
</style>
""", 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)}") |