HumanMachine74's picture
Upload folder using huggingface_hub
e241815 verified
import streamlit as st
import requests
import pandas as pd
from datetime import datetime
st.title('SuperKart Data Viewer')
st.markdown('A simple Streamlit app to fetch data from the Flask API deployed on Hugging Face.')
# Define the API endpoint URL.
# *** REPLACE with your actual deployed Flask API URL ***
api_url = "https://<YOUR-FLASK-SPACE-ID>.hf.space/data"
def fetch_data():
try:
response = requests.get(api_url)
if response.status_code == 200:
return response.json()
else:
st.error(f"Error fetching data from API: {response.status_code} - {response.text}")
return None
except requests.exceptions.RequestException as e:
st.error(f"Failed to connect to the API: {e}")
return None
if st.button('Fetch and Process Data'):
with st.spinner('Fetching and processing data...'):
data = fetch_data()
if data:
df = pd.DataFrame(data)
df['Years_Since_Establishment'] = datetime.now().year - df['Store_Establishment_Year']
df['Product_MRP_per_Weight'] = df['Product_MRP'] / df['Product_Weight']
st.success('Data fetched and processed successfully!')
st.dataframe(df)