Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,25 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.graph_objects as go
|
| 4 |
-
import base64
|
| 5 |
from io import StringIO
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
# Custom CSS for
|
| 8 |
st.markdown("""
|
| 9 |
<style>
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
}
|
|
|
|
|
|
|
| 15 |
.stButton>button {
|
| 16 |
background-color: #4CAF50;
|
| 17 |
color: white;
|
|
@@ -19,24 +27,37 @@ st.markdown("""
|
|
| 19 |
padding: 10px 24px;
|
| 20 |
border: none;
|
| 21 |
font-size: 16px;
|
|
|
|
| 22 |
}
|
| 23 |
-
.
|
| 24 |
-
background-color: #
|
| 25 |
-
color: white;
|
| 26 |
-
border-radius: 8px;
|
| 27 |
-
padding: 10px 24px;
|
| 28 |
-
border: none;
|
| 29 |
-
font-size: 16px;
|
| 30 |
}
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
background-color: #f0f2f6;
|
| 33 |
border-radius: 8px;
|
| 34 |
-
padding:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
}
|
| 36 |
</style>
|
| 37 |
""", unsafe_allow_html=True)
|
| 38 |
|
| 39 |
-
|
|
|
|
| 40 |
positions = {}
|
| 41 |
edge_x = []
|
| 42 |
edge_y = []
|
|
@@ -94,91 +115,110 @@ def create_org_chart(df, title, direction='TB'):
|
|
| 94 |
x=node_x, y=node_y,
|
| 95 |
mode='markers+text',
|
| 96 |
text=node_text,
|
| 97 |
-
textposition="
|
| 98 |
marker=dict(
|
| 99 |
symbol='square',
|
| 100 |
-
size=[
|
| 101 |
color='#4CAF50',
|
| 102 |
line=dict(width=2, color='DarkSlateGrey')
|
| 103 |
),
|
| 104 |
hoverinfo='text',
|
| 105 |
-
textfont=dict(size=
|
| 106 |
)
|
| 107 |
|
| 108 |
fig = go.Figure(data=[edge_trace, node_trace],
|
| 109 |
layout=go.Layout(
|
| 110 |
title=f'<b>{title}</b><br>',
|
| 111 |
-
titlefont_size=
|
| 112 |
showlegend=False,
|
| 113 |
hovermode='closest',
|
| 114 |
-
margin=dict(b=20,l=5,r=5,t=40),
|
| 115 |
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
| 116 |
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False))
|
| 117 |
)
|
| 118 |
|
| 119 |
return fig
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
def main():
|
| 122 |
st.title("Professional Organization Chart Generator")
|
| 123 |
|
| 124 |
-
#
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
st.markdown(""
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
else:
|
| 145 |
-
default_data = """Parent,Child
|
| 146 |
CEO,CTO
|
| 147 |
CEO,CFO
|
| 148 |
CTO,Engineering Manager
|
| 149 |
CFO,Accounting Manager"""
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
if
|
| 158 |
-
|
| 159 |
-
st.
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
if
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
if __name__ == "__main__":
|
| 184 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.graph_objects as go
|
|
|
|
| 4 |
from io import StringIO
|
| 5 |
+
import base64
|
| 6 |
+
from streamlit_tabs import st_tabs
|
| 7 |
|
| 8 |
+
# Custom CSS for professional UI
|
| 9 |
st.markdown("""
|
| 10 |
<style>
|
| 11 |
+
/* Main container */
|
| 12 |
+
.stApp {
|
| 13 |
+
background-color: #f5f5f5;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
/* Sidebar */
|
| 17 |
+
.stSidebar {
|
| 18 |
+
background-color: #2c3e50;
|
| 19 |
+
color: white;
|
| 20 |
}
|
| 21 |
+
|
| 22 |
+
/* Buttons */
|
| 23 |
.stButton>button {
|
| 24 |
background-color: #4CAF50;
|
| 25 |
color: white;
|
|
|
|
| 27 |
padding: 10px 24px;
|
| 28 |
border: none;
|
| 29 |
font-size: 16px;
|
| 30 |
+
transition: background-color 0.3s;
|
| 31 |
}
|
| 32 |
+
.stButton>button:hover {
|
| 33 |
+
background-color: #45a049;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
}
|
| 35 |
+
|
| 36 |
+
/* File uploader */
|
| 37 |
+
.stFileUploader>div>div>div>div {
|
| 38 |
background-color: #f0f2f6;
|
| 39 |
border-radius: 8px;
|
| 40 |
+
padding: 12px;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/* Tabs */
|
| 44 |
+
.stTabs [data-baseweb="tab-list"] {
|
| 45 |
+
background-color: #2c3e50;
|
| 46 |
+
border-radius: 8px;
|
| 47 |
+
}
|
| 48 |
+
.stTabs [data-baseweb="tab"] {
|
| 49 |
+
color: white;
|
| 50 |
+
padding: 10px 20px;
|
| 51 |
+
}
|
| 52 |
+
.stTabs [aria-selected="true"] {
|
| 53 |
+
background-color: #4CAF50;
|
| 54 |
+
border-radius: 8px;
|
| 55 |
}
|
| 56 |
</style>
|
| 57 |
""", unsafe_allow_html=True)
|
| 58 |
|
| 59 |
+
# Function to create organization chart
|
| 60 |
+
def create_org_chart(df, title):
|
| 61 |
positions = {}
|
| 62 |
edge_x = []
|
| 63 |
edge_y = []
|
|
|
|
| 115 |
x=node_x, y=node_y,
|
| 116 |
mode='markers+text',
|
| 117 |
text=node_text,
|
| 118 |
+
textposition="middle center",
|
| 119 |
marker=dict(
|
| 120 |
symbol='square',
|
| 121 |
+
size=[50] * len(node_x), # Reduced size for better fit
|
| 122 |
color='#4CAF50',
|
| 123 |
line=dict(width=2, color='DarkSlateGrey')
|
| 124 |
),
|
| 125 |
hoverinfo='text',
|
| 126 |
+
textfont=dict(size=12, color='white')
|
| 127 |
)
|
| 128 |
|
| 129 |
fig = go.Figure(data=[edge_trace, node_trace],
|
| 130 |
layout=go.Layout(
|
| 131 |
title=f'<b>{title}</b><br>',
|
| 132 |
+
titlefont_size=20,
|
| 133 |
showlegend=False,
|
| 134 |
hovermode='closest',
|
| 135 |
+
margin=dict(b=20, l=5, r=5, t=40),
|
| 136 |
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
| 137 |
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False))
|
| 138 |
)
|
| 139 |
|
| 140 |
return fig
|
| 141 |
|
| 142 |
+
# Function to download CSV template
|
| 143 |
+
def download_csv_template():
|
| 144 |
+
csv_template = "Parent,Child\nCEO,CTO\nCEO,CFO\nCTO,Engineering Manager\nCFO,Accounting Manager"
|
| 145 |
+
b64 = base64.b64encode(csv_template.encode()).decode()
|
| 146 |
+
href = f'<a href="data:file/csv;base64,{b64}" download="org_chart_template.csv">Download CSV Template</a>'
|
| 147 |
+
st.markdown(href, unsafe_allow_html=True)
|
| 148 |
+
|
| 149 |
+
# Main function
|
| 150 |
def main():
|
| 151 |
st.title("Professional Organization Chart Generator")
|
| 152 |
|
| 153 |
+
# Tabs for better organization
|
| 154 |
+
tab1, tab2 = st_tabs(["Data Input", "Organization Chart"])
|
| 155 |
+
|
| 156 |
+
with tab1:
|
| 157 |
+
st.header("Data Input")
|
| 158 |
+
st.markdown("### Upload or Edit Your Organizational Data")
|
| 159 |
+
|
| 160 |
+
# Download CSV template
|
| 161 |
+
st.markdown("**Step 1:** Download the CSV template to input your data.")
|
| 162 |
+
download_csv_template()
|
| 163 |
+
|
| 164 |
+
# File upload
|
| 165 |
+
st.markdown("**Step 2:** Upload your CSV file or edit the default data below.")
|
| 166 |
+
uploaded_file = st.file_uploader("Upload CSV File", type=["csv"])
|
| 167 |
+
|
| 168 |
+
# Input data
|
| 169 |
+
if uploaded_file:
|
| 170 |
+
df = pd.read_csv(uploaded_file)
|
| 171 |
+
else:
|
| 172 |
+
default_data = """Parent,Child
|
|
|
|
|
|
|
| 173 |
CEO,CTO
|
| 174 |
CEO,CFO
|
| 175 |
CTO,Engineering Manager
|
| 176 |
CFO,Accounting Manager"""
|
| 177 |
+
df = pd.read_csv(StringIO(default_data))
|
| 178 |
+
|
| 179 |
+
# Editable data table
|
| 180 |
+
st.markdown("**Step 3:** Edit your data below if needed.")
|
| 181 |
+
edited_df = st.data_editor(df, num_rows="dynamic")
|
| 182 |
+
|
| 183 |
+
# Save edited data
|
| 184 |
+
if st.button("Save Data"):
|
| 185 |
+
edited_df.to_csv("edited_data.csv", index=False)
|
| 186 |
+
st.success("Data saved successfully!")
|
| 187 |
+
|
| 188 |
+
with tab2:
|
| 189 |
+
st.header("Organization Chart")
|
| 190 |
+
st.markdown("### Visualize Your Organizational Structure")
|
| 191 |
+
|
| 192 |
+
# Chart title
|
| 193 |
+
chart_title = st.text_input("Enter Chart Title", "Organization Chart")
|
| 194 |
+
|
| 195 |
+
# Generate chart
|
| 196 |
+
if st.button("Generate Organization Chart"):
|
| 197 |
+
if not edited_df.empty:
|
| 198 |
+
fig = create_org_chart(edited_df, chart_title)
|
| 199 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 200 |
+
|
| 201 |
+
# PDF download options
|
| 202 |
+
st.markdown("### Download Options")
|
| 203 |
+
col1, col2 = st.columns(2)
|
| 204 |
+
with col1:
|
| 205 |
+
orientation = st.selectbox("PDF Orientation", ["Portrait", "Landscape"])
|
| 206 |
+
with col2:
|
| 207 |
+
paper_size = st.selectbox("Paper Size", ["A4", "Letter", "Legal"])
|
| 208 |
+
|
| 209 |
+
# Convert to PDF
|
| 210 |
+
if st.button("Download as PDF"):
|
| 211 |
+
img_bytes = fig.to_image(format="pdf",
|
| 212 |
+
width=800 if orientation == "Portrait" else 1200,
|
| 213 |
+
height=1200 if orientation == "Portrait" else 800)
|
| 214 |
+
st.download_button(
|
| 215 |
+
label="Download PDF",
|
| 216 |
+
data=img_bytes,
|
| 217 |
+
file_name="org_chart.pdf",
|
| 218 |
+
mime="application/pdf"
|
| 219 |
+
)
|
| 220 |
+
else:
|
| 221 |
+
st.warning("Please enter some organizational data first.")
|
| 222 |
|
| 223 |
if __name__ == "__main__":
|
| 224 |
main()
|