Update app.py
Browse files
app.py
CHANGED
|
@@ -1,162 +1,163 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
from __future__ import annotations
|
| 3 |
-
|
| 4 |
-
from datetime import datetime, date, time
|
| 5 |
-
import base64
|
| 6 |
-
|
| 7 |
-
import pandas as pd
|
| 8 |
-
import streamlit as st
|
| 9 |
-
|
| 10 |
-
from analysis import read_excel_safe, build, get_pivots_for_ppt
|
| 11 |
-
from ppt_fill import fill_ppt
|
| 12 |
-
|
| 13 |
-
st.set_page_config(page_title="Reports 940", layout="centered")
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def get_base64_image(path: str) -> str:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
background
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
font-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
<div
|
| 110 |
-
|
| 111 |
-
<img src="data:image/png;base64,{
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
from datetime import datetime, date, time
|
| 5 |
+
import base64
|
| 6 |
+
|
| 7 |
+
import pandas as pd
|
| 8 |
+
import streamlit as st
|
| 9 |
+
import os
|
| 10 |
+
from analysis import read_excel_safe, build, get_pivots_for_ppt
|
| 11 |
+
from ppt_fill import fill_ppt
|
| 12 |
+
|
| 13 |
+
st.set_page_config(page_title="Reports 940", layout="centered")
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def get_base64_image(path: str) -> str:
|
| 17 |
+
abs_path = os.path.join(os.path.dirname(__file__), path)
|
| 18 |
+
with open(abs_path, "rb") as f:
|
| 19 |
+
return base64.b64encode(f.read()).decode()
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
amanah_b64 = get_base64_image("assets/amanah_logo.png")
|
| 23 |
+
center_b64 = get_base64_image("assets/center_logo.png")
|
| 24 |
+
vision_b64 = get_base64_image("assets/vision2030_logo.png")
|
| 25 |
+
|
| 26 |
+
page_css = f"""
|
| 27 |
+
<style>
|
| 28 |
+
.stAppViewContainer {{
|
| 29 |
+
position: relative;
|
| 30 |
+
background: linear-gradient(to bottom, #043548 0%, #02141e 55%, #01080c 100%);
|
| 31 |
+
background-attachment: fixed;
|
| 32 |
+
}}
|
| 33 |
+
|
| 34 |
+
main .block-container {{
|
| 35 |
+
max-width: 900px;
|
| 36 |
+
padding-top: 6rem;
|
| 37 |
+
}}
|
| 38 |
+
|
| 39 |
+
[data-testid="stHeader"] {{
|
| 40 |
+
background-color: rgba(0, 0, 0, 0);
|
| 41 |
+
}}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
.top-logos-main {{
|
| 45 |
+
display: flex;
|
| 46 |
+
justify-content: center;
|
| 47 |
+
margin-bottom: 0.75rem;
|
| 48 |
+
}}
|
| 49 |
+
|
| 50 |
+
.vision-logo {{
|
| 51 |
+
width: 260px;
|
| 52 |
+
height: auto;
|
| 53 |
+
}}
|
| 54 |
+
|
| 55 |
+
.sub-logos {{
|
| 56 |
+
display: flex;
|
| 57 |
+
justify-content: center;
|
| 58 |
+
align-items: center;
|
| 59 |
+
gap: 0.0rem;
|
| 60 |
+
margin-bottom: 0rem;
|
| 61 |
+
}}
|
| 62 |
+
|
| 63 |
+
.center-logo {{
|
| 64 |
+
width: 270px;
|
| 65 |
+
height: auto;
|
| 66 |
+
}}
|
| 67 |
+
|
| 68 |
+
.amanah-logo {{
|
| 69 |
+
width: 270px;
|
| 70 |
+
height: auto;
|
| 71 |
+
}}
|
| 72 |
+
|
| 73 |
+
.title-row {{
|
| 74 |
+
margin-bottom: 0.75rem;
|
| 75 |
+
}}
|
| 76 |
+
|
| 77 |
+
.title-text {{
|
| 78 |
+
font-size: 1.9rem;
|
| 79 |
+
font-weight: 600;
|
| 80 |
+
color: #ffffff;
|
| 81 |
+
}}
|
| 82 |
+
|
| 83 |
+
h1, h2, h3, h4, h5, h6, p, label {{
|
| 84 |
+
color: #ffffff !important;
|
| 85 |
+
}}
|
| 86 |
+
|
| 87 |
+
section[data-testid="stFileUploader"] > div {{
|
| 88 |
+
background-color: #181b24;
|
| 89 |
+
border-radius: 6px;
|
| 90 |
+
}}
|
| 91 |
+
|
| 92 |
+
div[data-baseweb="input"] > div {{
|
| 93 |
+
background-color: #181b24;
|
| 94 |
+
}}
|
| 95 |
+
|
| 96 |
+
button[kind="primary"] {{
|
| 97 |
+
background-color: #22252f;
|
| 98 |
+
border-radius: 6px;
|
| 99 |
+
}}
|
| 100 |
+
</style>
|
| 101 |
+
"""
|
| 102 |
+
|
| 103 |
+
st.markdown(page_css, unsafe_allow_html=True)
|
| 104 |
+
|
| 105 |
+
st.markdown(
|
| 106 |
+
f"""
|
| 107 |
+
<div class="top-logos-main">
|
| 108 |
+
<img src="data:image/png;base64,{vision_b64}" class="vision-logo" />
|
| 109 |
+
</div>
|
| 110 |
+
<div class="sub-logos">
|
| 111 |
+
<img src="data:image/png;base64,{center_b64}" class="center-logo" />
|
| 112 |
+
<img src="data:image/png;base64,{amanah_b64}" class="amanah-logo" />
|
| 113 |
+
</div>
|
| 114 |
+
""",
|
| 115 |
+
unsafe_allow_html=True,
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
st.markdown(
|
| 119 |
+
"""
|
| 120 |
+
<div class="title-row">
|
| 121 |
+
<span class="title-text">Reports 940</span>
|
| 122 |
+
</div>
|
| 123 |
+
""",
|
| 124 |
+
unsafe_allow_html=True,
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
uploaded_file = st.file_uploader("Upload file (Excel)", type=["xlsx"])
|
| 129 |
+
|
| 130 |
+
c1, c2 = st.columns(2)
|
| 131 |
+
with c1:
|
| 132 |
+
d_closed = st.date_input("Date", value=date.today())
|
| 133 |
+
with c2:
|
| 134 |
+
t_closed = st.time_input("Time", value=time(8, 0))
|
| 135 |
+
|
| 136 |
+
CLOSED_DT = pd.Timestamp(datetime.combine(d_closed, t_closed))
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
if uploaded_file is not None:
|
| 140 |
+
df0 = read_excel_safe(uploaded_file)
|
| 141 |
+
|
| 142 |
+
out_excel = build(df0, CLOSED_DT)
|
| 143 |
+
|
| 144 |
+
p_open_ar, p_sla_ar, p_urbi = get_pivots_for_ppt(df0, CLOSED_DT)
|
| 145 |
+
|
| 146 |
+
ppt_template = "templates/balady_template.pptx"
|
| 147 |
+
out_ppt = fill_ppt(ppt_template, p_open_ar, p_sla_ar, p_urbi, CLOSED_DT)
|
| 148 |
+
|
| 149 |
+
c1, c2 = st.columns(2)
|
| 150 |
+
with c1:
|
| 151 |
+
st.download_button(
|
| 152 |
+
"Download Excel report",
|
| 153 |
+
data=out_excel.getvalue(),
|
| 154 |
+
file_name="report_balady.xlsx",
|
| 155 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
| 156 |
+
)
|
| 157 |
+
with c2:
|
| 158 |
+
st.download_button(
|
| 159 |
+
"Download PowerPoint report",
|
| 160 |
+
data=out_ppt.getvalue(),
|
| 161 |
+
file_name="report_balady.pptx",
|
| 162 |
+
mime="application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
| 163 |
+
)
|