create an app with the following side pages: 1. Upload File 2. Generate Results 3. View Person Profile 4. Download Report When click on the link on side page 1, the main page allows a file upload function to upload excel with .xlsx or .csv and create a list of entities found from the file for display. When click on the link on side page 2, the main page, displays a SWOT analysis of the data read from the file uploaded in side page 1 and give a quick summarised view of the rows and entities. When click on the link on side page 3, the main page shows a person profile of the individual row from the file uploaded and show the records under the different entities this record has. When click on the link on side page 4, the main page allows 2 types of download with a drop down button. First button "Download results", downloads the analysed file with its original data and new fields "Entities found" and second button "Download Report", downloads a word document of the SWOT analysis in side page 2 and Person Profile in side page 3.
To upload files, please first save the app
import streamlit as st
import pandas as pd
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from sqlalchemy.orm import DeclarativeBase
import os
from docx import Document
class Base(DeclarativeBase):
pass
# Your SQLAlchemy models can be defined here
engine = create_engine("sqlite:///data.sqlite")
st.sidebar.title("Navigation")
page = st.sidebar.radio("Go to", ["Upload File", "Generate Results", "View Person Profile", "Download Report"])
if page == "Upload File":
st.title("Upload File")
uploaded_file = st.file_uploader("Choose a file (xlsx or csv)", type=["xlsx", "csv"])
if uploaded_file is not None:
# Read the uploaded file
if uploaded_file.name.endswith('.xlsx'):
data = pd.read_excel(uploaded_file)
else:
data = pd.read_csv(uploaded_file)
st.write("Entities found:")
entities = data['Entity'].unique() # Assuming 'Entity' column exists
st.table(entities)
elif page == "Generate Results":
st.title("Generate Results")
# Here you would load and analyze data
# For demonstration, assume 'data' is loaded from a file
try:
data = pd.read_csv("uploaded_data.csv") # Example placeholder
swot_analysis = "Strengths, Weaknesses, Opportunities, Threats analysis for given data."
st.write(swot_analysis)
st.table(data.describe())
except:
st.write("No data available. Please upload a file first.")
elif page == "View Person Profile":
st.title("View Person Profile")
try:
data = pd.read_csv("uploaded_data.csv")
record_id = st.selectbox("Select Record ID:", data['ID'].unique()) # Assuming 'ID' field exists
person_data = data[data['ID'] == record_id]
st.write(person_data)
except:
st.write("No data available. Please upload a file first.")
elif page == "Download Report":
st.title("Download Report")
option = st.selectbox("Select download type:", ["Download results", "Download Report"])
if option == "Download results":
if st.button("Download analysed data with Entities found"):
# Create a sample data file for download
data = pd.read_csv("uploaded_data.csv")
data['Entities found'] = data['Entity'].unique() # Assuming such processing
data.to_csv("analysed_data.csv", index=False)
with open("analysed_data.csv", "rb") as file:
st.download_button("Download", file, "analysed_data.csv")
elif option == "Download Report":
if st.button("Download SWOT analysis and Profile"):
doc = Document()
doc.add_heading('SWOT Analysis', 0)
swot_analysis = "Strengths, Weaknesses, Opportunities, Threats analysis."
doc.add_paragraph(swot_analysis)
doc.add_heading('Person Profile', 0)
doc.add_paragraph("Profile details here.")
doc.save("report.docx")
with open("report.docx", "rb") as file:
st.download_button("Download", file, "report.docx")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?