Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import requests | |
import io | |
st.set_page_config(page_title="SuperKart Sales Prediction", page_icon="π") | |
st.title("SuperKart Sales Prediction") | |
st.write("Upload a 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: | |
# Display the uploaded data | |
df = pd.read_csv(uploaded_file) | |
st.write("Preview of uploaded data:") | |
st.dataframe(df.head()) | |
if st.button("Get Predictions"): | |
# Prepare the file for API request | |
files = {"file": ("SuperKart.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.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("Error getting predictions from the API") | |
except Exception as e: | |
st.error(f"Error: {str(e)}") |