File size: 1,673 Bytes
f58abe5
2e2e73d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)}")