Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,54 +5,73 @@ import os
|
|
5 |
import base64
|
6 |
from io import StringIO
|
7 |
|
8 |
-
#
|
9 |
os.environ["PATH"] += os.pathsep + '/usr/bin/graphviz'
|
10 |
|
11 |
-
#
|
12 |
st.markdown("""
|
13 |
<style>
|
14 |
-
.
|
15 |
-
background:
|
16 |
-
|
17 |
-
border-radius: 25px !important;
|
18 |
-
padding: 12px 28px !important;
|
19 |
-
transition: all 0.3s !important;
|
20 |
}
|
21 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
transform: scale(1.05);
|
23 |
-
box-shadow: 0 4px
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
}
|
25 |
</style>
|
26 |
""", unsafe_allow_html=True)
|
27 |
|
28 |
def create_org_chart(df, title):
|
29 |
-
"""Create professional
|
30 |
dot = Digraph(comment=title)
|
31 |
dot.attr(rankdir='TB', labelloc='t', label=title,
|
32 |
-
fontsize='24', fontname='Arial', margin='0.5'
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# Process relationships
|
40 |
-
|
41 |
for _, row in df.iterrows():
|
42 |
parent = row['Parent'].strip()
|
43 |
child = row['Child'].strip()
|
44 |
if parent and child:
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
dot.edge(parent, child)
|
53 |
-
|
54 |
-
for node in nodes:
|
55 |
-
dot.node(node, node)
|
56 |
|
57 |
return dot
|
58 |
|
@@ -60,42 +79,57 @@ def main():
|
|
60 |
st.title("π’ Professional Organization Chart Generator")
|
61 |
|
62 |
with st.sidebar:
|
63 |
-
st.header("Configuration")
|
64 |
chart_title = st.text_input("Chart Title", "Company Structure")
|
65 |
-
st.markdown("
|
66 |
-
st.
|
|
|
67 |
|
68 |
# CSV template download
|
69 |
template = "Parent,Child\nCEO,CTO\nCEO,CFO\nCTO,Engineering Manager"
|
70 |
b64 = base64.b64encode(template.encode()).decode()
|
71 |
-
href = f'<a href="data:file/csv;base64,{b64}" download="template.csv">π₯ Download Template</a>'
|
72 |
st.markdown(href, unsafe_allow_html=True)
|
73 |
|
74 |
-
uploaded_file = st.file_uploader("Upload CSV File", type=["csv"]
|
|
|
75 |
|
76 |
if uploaded_file:
|
77 |
try:
|
78 |
df = pd.read_csv(uploaded_file)
|
79 |
if {'Parent', 'Child'}.issubset(df.columns):
|
80 |
-
with st.spinner("
|
81 |
chart = create_org_chart(df, chart_title)
|
82 |
|
83 |
# Display chart
|
84 |
-
st.
|
|
|
|
|
85 |
|
86 |
# PDF Generation
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
else:
|
96 |
-
st.error("CSV must contain 'Parent' and 'Child' columns")
|
97 |
except Exception as e:
|
98 |
-
st.error(f"Error processing file: {str(e)}")
|
99 |
|
100 |
if __name__ == "__main__":
|
101 |
main()
|
|
|
5 |
import base64
|
6 |
from io import StringIO
|
7 |
|
8 |
+
# Fix Graphviz PATH error for Hugging Face
|
9 |
os.environ["PATH"] += os.pathsep + '/usr/bin/graphviz'
|
10 |
|
11 |
+
# Enhanced UI CSS
|
12 |
st.markdown("""
|
13 |
<style>
|
14 |
+
.stApp {
|
15 |
+
background: #f8f9fa;
|
16 |
+
font-family: 'Segoe UI', system-ui;
|
|
|
|
|
|
|
17 |
}
|
18 |
+
.st-emotion-cache-1kyxreq {
|
19 |
+
justify-content: center;
|
20 |
+
}
|
21 |
+
.stButton>button {
|
22 |
+
background: linear-gradient(135deg, #4CAF50, #45a049);
|
23 |
+
color: white;
|
24 |
+
border-radius: 8px;
|
25 |
+
padding: 12px 24px;
|
26 |
+
border: none;
|
27 |
+
font-weight: 600;
|
28 |
+
transition: transform 0.3s;
|
29 |
+
}
|
30 |
+
.stButton>button:hover {
|
31 |
transform: scale(1.05);
|
32 |
+
box-shadow: 0 4px 12px rgba(76,175,80,0.3);
|
33 |
+
}
|
34 |
+
.stDownloadButton>button {
|
35 |
+
background: linear-gradient(135deg, #2196F3, #1976D2);
|
36 |
+
}
|
37 |
+
.st-eb {
|
38 |
+
border-radius: 10px;
|
39 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
40 |
}
|
41 |
</style>
|
42 |
""", unsafe_allow_html=True)
|
43 |
|
44 |
def create_org_chart(df, title):
|
45 |
+
"""Create professional org chart with straight lines"""
|
46 |
dot = Digraph(comment=title)
|
47 |
dot.attr(rankdir='TB', labelloc='t', label=title,
|
48 |
+
fontsize='24', fontname='Arial', margin='0.5',
|
49 |
+
splines='ortho') # Force straight lines
|
50 |
+
|
51 |
+
# Node styling
|
52 |
+
dot.attr('node', shape='box', style='filled',
|
53 |
+
fillcolor='linear-gradient(#4CAF50, #45a049)',
|
54 |
+
fontname='Arial', fontcolor='white',
|
55 |
+
margin='0.4', width='2', height='0.9',
|
56 |
+
fixedsize='false', fontsize='14')
|
57 |
+
|
58 |
+
# Edge styling for straight lines
|
59 |
+
dot.attr('edge', color='#666666', arrowsize='0.8',
|
60 |
+
penwidth='1.2', dir='forward')
|
61 |
|
62 |
# Process relationships
|
63 |
+
added_nodes = set()
|
64 |
for _, row in df.iterrows():
|
65 |
parent = row['Parent'].strip()
|
66 |
child = row['Child'].strip()
|
67 |
if parent and child:
|
68 |
+
if parent not in added_nodes:
|
69 |
+
dot.node(parent)
|
70 |
+
added_nodes.add(parent)
|
71 |
+
if child not in added_nodes:
|
72 |
+
dot.node(child)
|
73 |
+
added_nodes.add(child)
|
74 |
+
dot.edge(parent, child)
|
|
|
|
|
|
|
|
|
75 |
|
76 |
return dot
|
77 |
|
|
|
79 |
st.title("π’ Professional Organization Chart Generator")
|
80 |
|
81 |
with st.sidebar:
|
82 |
+
st.header("βοΈ Configuration")
|
83 |
chart_title = st.text_input("Chart Title", "Company Structure")
|
84 |
+
st.markdown("---")
|
85 |
+
st.markdown("### π CSV Instructions")
|
86 |
+
st.write("1. Download template\n2. Edit in Excel/Sheets\n3. Upload your file")
|
87 |
|
88 |
# CSV template download
|
89 |
template = "Parent,Child\nCEO,CTO\nCEO,CFO\nCTO,Engineering Manager"
|
90 |
b64 = base64.b64encode(template.encode()).decode()
|
91 |
+
href = f'<a href="data:file/csv;base64,{b64}" download="template.csv" style="text-decoration: none; color: white; background: #4CAF50; padding: 10px 20px; border-radius: 8px; display: inline-block; margin-top: 10px;">π₯ Download Template</a>'
|
92 |
st.markdown(href, unsafe_allow_html=True)
|
93 |
|
94 |
+
uploaded_file = st.file_uploader("π€ Upload CSV File", type=["csv"],
|
95 |
+
help="Upload your organizational hierarchy CSV file")
|
96 |
|
97 |
if uploaded_file:
|
98 |
try:
|
99 |
df = pd.read_csv(uploaded_file)
|
100 |
if {'Parent', 'Child'}.issubset(df.columns):
|
101 |
+
with st.spinner("π Analyzing structure..."):
|
102 |
chart = create_org_chart(df, chart_title)
|
103 |
|
104 |
# Display chart
|
105 |
+
col1, col2 = st.columns([3, 1])
|
106 |
+
with col1:
|
107 |
+
st.graphviz_chart(chart, use_container_width=True)
|
108 |
|
109 |
# PDF Generation
|
110 |
+
with col2:
|
111 |
+
st.markdown("### π€ Export Options")
|
112 |
+
pdf_bytes = chart.pipe(format='pdf')
|
113 |
+
st.download_button(
|
114 |
+
label="π Download PDF",
|
115 |
+
data=pdf_bytes,
|
116 |
+
file_name=f"{chart_title.replace(' ', '_')}.pdf",
|
117 |
+
mime="application/pdf",
|
118 |
+
help="Download high-quality PDF version"
|
119 |
+
)
|
120 |
+
|
121 |
+
png_bytes = chart.pipe(format='png')
|
122 |
+
st.download_button(
|
123 |
+
label="πΌοΈ Download PNG",
|
124 |
+
data=png_bytes,
|
125 |
+
file_name=f"{chart_title.replace(' ', '_')}.png",
|
126 |
+
mime="image/png",
|
127 |
+
help="Download image version"
|
128 |
+
)
|
129 |
else:
|
130 |
+
st.error("β CSV must contain 'Parent' and 'Child' columns")
|
131 |
except Exception as e:
|
132 |
+
st.error(f"π¨ Error processing file: {str(e)}")
|
133 |
|
134 |
if __name__ == "__main__":
|
135 |
main()
|