Spaces:
Sleeping
Sleeping
Jovian Sanjaya Putra commited on
Commit ·
a2fb840
1
Parent(s): 4997def
bahasa indo
Browse files
app.py
CHANGED
|
@@ -6,13 +6,19 @@ import tempfile
|
|
| 6 |
from openpyxl import load_workbook
|
| 7 |
from openpyxl.utils import column_index_from_string
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# Core report-generation function
|
| 10 |
def generate_report(month, year, prev_file_path, template_file_path):
|
| 11 |
if not prev_file_path or not template_file_path:
|
| 12 |
raise gr.Error("Please upload both the previous report and the template.")
|
| 13 |
|
| 14 |
# Determine month numbers
|
| 15 |
-
month_num =
|
| 16 |
prev_month_num = 12 if month_num == 1 else month_num - 1
|
| 17 |
prev_year = year - 1 if month_num == 1 else year
|
| 18 |
|
|
@@ -148,35 +154,35 @@ def generate_report(month, year, prev_file_path, template_file_path):
|
|
| 148 |
|
| 149 |
# Gradio UI components
|
| 150 |
dropdown_month = gr.Dropdown(
|
| 151 |
-
choices=
|
| 152 |
-
label="
|
| 153 |
-
value=
|
| 154 |
)
|
| 155 |
number_year = gr.Number(
|
| 156 |
-
label="
|
| 157 |
value=datetime.now().year,
|
| 158 |
precision=0
|
| 159 |
)
|
| 160 |
file_prev = gr.File(
|
| 161 |
-
label="
|
| 162 |
file_count="single",
|
| 163 |
type="filepath"
|
| 164 |
)
|
| 165 |
file_template = gr.File(
|
| 166 |
-
label="Template
|
| 167 |
file_count="single",
|
| 168 |
type="filepath"
|
| 169 |
)
|
| 170 |
|
| 171 |
-
# Launch interface without flag button
|
| 172 |
iface = gr.Interface(
|
| 173 |
fn=generate_report,
|
| 174 |
inputs=[dropdown_month, number_year, file_prev, file_template],
|
| 175 |
-
outputs=[gr.File(label="
|
| 176 |
title="Pembuatan Laporan J&T Otomatis",
|
| 177 |
allow_flagging='never'
|
| 178 |
)
|
| 179 |
|
|
|
|
| 180 |
if __name__ == '__main__':
|
| 181 |
iface.launch(share=True, server_name="0.0.0.0", server_port=7860)
|
| 182 |
|
|
|
|
| 6 |
from openpyxl import load_workbook
|
| 7 |
from openpyxl.utils import column_index_from_string
|
| 8 |
|
| 9 |
+
# 1) Define Indonesian month names
|
| 10 |
+
MONTHS_ID = [
|
| 11 |
+
"Januari", "Februari", "Maret", "April", "Mei", "Juni",
|
| 12 |
+
"Juli", "Agustus", "September", "Oktober", "November", "Desember"
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
# Core report-generation function
|
| 16 |
def generate_report(month, year, prev_file_path, template_file_path):
|
| 17 |
if not prev_file_path or not template_file_path:
|
| 18 |
raise gr.Error("Please upload both the previous report and the template.")
|
| 19 |
|
| 20 |
# Determine month numbers
|
| 21 |
+
month_num = MONTHS_ID.index(month) + 1
|
| 22 |
prev_month_num = 12 if month_num == 1 else month_num - 1
|
| 23 |
prev_year = year - 1 if month_num == 1 else year
|
| 24 |
|
|
|
|
| 154 |
|
| 155 |
# Gradio UI components
|
| 156 |
dropdown_month = gr.Dropdown(
|
| 157 |
+
choices=MONTHS_ID,
|
| 158 |
+
label="Pilih Bulan",
|
| 159 |
+
value=MONTHS_ID[datetime.now().month - 1]
|
| 160 |
)
|
| 161 |
number_year = gr.Number(
|
| 162 |
+
label="Tahun",
|
| 163 |
value=datetime.now().year,
|
| 164 |
precision=0
|
| 165 |
)
|
| 166 |
file_prev = gr.File(
|
| 167 |
+
label="Laporan Bulan Sebelumnya (.xlsx)",
|
| 168 |
file_count="single",
|
| 169 |
type="filepath"
|
| 170 |
)
|
| 171 |
file_template = gr.File(
|
| 172 |
+
label="Template Laporan (.xlsx)",
|
| 173 |
file_count="single",
|
| 174 |
type="filepath"
|
| 175 |
)
|
| 176 |
|
|
|
|
| 177 |
iface = gr.Interface(
|
| 178 |
fn=generate_report,
|
| 179 |
inputs=[dropdown_month, number_year, file_prev, file_template],
|
| 180 |
+
outputs=[gr.File(label="Unduh Laporan", type="filepath")],
|
| 181 |
title="Pembuatan Laporan J&T Otomatis",
|
| 182 |
allow_flagging='never'
|
| 183 |
)
|
| 184 |
|
| 185 |
+
|
| 186 |
if __name__ == '__main__':
|
| 187 |
iface.launch(share=True, server_name="0.0.0.0", server_port=7860)
|
| 188 |
|