ombhojane's picture
Update app.py
4e4ea7e verified
import streamlit as st
import pandas as pd
import json
# Title of the app
st.title('Gen AI Jam JSON Visualizer')
# File uploader widget
uploaded_file = st.file_uploader("Choose a JSON file", type=['json'])
if uploaded_file is not None:
# Reading the file
file_data = json.load(uploaded_file)
# If the JSON is deeply nested, you may need to normalize it to create a flat table
if isinstance(file_data, list): # Assuming the JSON is an array of records
df = pd.json_normalize(file_data)
else:
df = pd.json_normalize(file_data, max_level=1)
# Display the dataframe as a table
st.write(df)
st.download_button(
label="Download CSV",
data=df.to_csv(index=False).encode('utf-8'),
file_name='table.csv',
mime='text/csv',
)