Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -55,7 +55,6 @@ def add_styled_heading(doc, text, bg_color="1B3A6B"):
|
|
| 55 |
run.font.size = Pt(11)
|
| 56 |
run.font.color.rgb = RGBColor(255, 255, 255) # ν°μ ν
μ€νΈ
|
| 57 |
|
| 58 |
-
# λΉ λ¨λ½ μΆκ°νμ¬ κ°κ²© μ‘°μ
|
| 59 |
sp = doc.add_paragraph()
|
| 60 |
sp.paragraph_format.space_before = Pt(0)
|
| 61 |
sp.paragraph_format.space_after = Pt(4)
|
|
@@ -82,7 +81,7 @@ def create_advanced_document(
|
|
| 82 |
title_run = title_p.add_run(f"[{project_name}] {category} μ¬μ§λμ₯")
|
| 83 |
title_run.font.size = Pt(18)
|
| 84 |
title_run.bold = True
|
| 85 |
-
title_run.font.color.rgb = RGBColor(27, 58, 107)
|
| 86 |
|
| 87 |
# 1. κ³΅μ¬ κ°μ
|
| 88 |
add_styled_heading(doc, "1. κ³΅μ¬ κ°μ", bg_color="1B3A6B")
|
|
@@ -104,7 +103,6 @@ def create_advanced_document(
|
|
| 104 |
cells[2].text = row_data[2]
|
| 105 |
cells[3].text = row_data[3]
|
| 106 |
|
| 107 |
-
# ν€λ μ»¬λΌ λ°°κ²½μ (μ°ν νμλΉ λΈλ£¨) λ° μ λ ¬
|
| 108 |
for c_idx in [0, 2]:
|
| 109 |
set_cell_background(cells[c_idx], "E8EEF5")
|
| 110 |
cells[c_idx].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
|
@@ -115,7 +113,6 @@ def create_advanced_document(
|
|
| 115 |
if len(cells[c_idx].paragraphs[0].runs) > 0:
|
| 116 |
cells[c_idx].paragraphs[0].runs[0].font.size = Pt(9.5)
|
| 117 |
|
| 118 |
-
# μ¬μ§ μΉμ
κ³΅ν΅ ν¨μ (μμμ μ΄λ‘μ ν
λ§ μ μ©: 착곡μ /μ€/ν)
|
| 119 |
def add_photo_section(section_title, files, label_prefix, header_color="2D8A4E"):
|
| 120 |
add_styled_heading(doc, section_title, bg_color=header_color)
|
| 121 |
|
|
@@ -142,4 +139,144 @@ def create_advanced_document(
|
|
| 142 |
|
| 143 |
if j < len(chunk) and os.path.exists(chunk[j]):
|
| 144 |
try:
|
| 145 |
-
p.add_run().add_picture(chunk
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
run.font.size = Pt(11)
|
| 56 |
run.font.color.rgb = RGBColor(255, 255, 255) # ν°μ ν
μ€νΈ
|
| 57 |
|
|
|
|
| 58 |
sp = doc.add_paragraph()
|
| 59 |
sp.paragraph_format.space_before = Pt(0)
|
| 60 |
sp.paragraph_format.space_after = Pt(4)
|
|
|
|
| 81 |
title_run = title_p.add_run(f"[{project_name}] {category} μ¬μ§λμ₯")
|
| 82 |
title_run.font.size = Pt(18)
|
| 83 |
title_run.bold = True
|
| 84 |
+
title_run.font.color.rgb = RGBColor(27, 58, 107)
|
| 85 |
|
| 86 |
# 1. κ³΅μ¬ κ°μ
|
| 87 |
add_styled_heading(doc, "1. κ³΅μ¬ κ°μ", bg_color="1B3A6B")
|
|
|
|
| 103 |
cells[2].text = row_data[2]
|
| 104 |
cells[3].text = row_data[3]
|
| 105 |
|
|
|
|
| 106 |
for c_idx in [0, 2]:
|
| 107 |
set_cell_background(cells[c_idx], "E8EEF5")
|
| 108 |
cells[c_idx].paragraphs[0].alignment = WD_ALIGN_PARAGRAPH.CENTER
|
|
|
|
| 113 |
if len(cells[c_idx].paragraphs[0].runs) > 0:
|
| 114 |
cells[c_idx].paragraphs[0].runs[0].font.size = Pt(9.5)
|
| 115 |
|
|
|
|
| 116 |
def add_photo_section(section_title, files, label_prefix, header_color="2D8A4E"):
|
| 117 |
add_styled_heading(doc, section_title, bg_color=header_color)
|
| 118 |
|
|
|
|
| 139 |
|
| 140 |
if j < len(chunk) and os.path.exists(chunk[j]):
|
| 141 |
try:
|
| 142 |
+
p.add_run().add_picture(chunk[j], width=Inches(3.2))
|
| 143 |
+
except Exception:
|
| 144 |
+
p.add_run("(μ΄λ―Έμ§ λ‘λ μ€ν¨)")
|
| 145 |
+
|
| 146 |
+
row_text_cells = table.add_row().cells
|
| 147 |
+
for j in range(2):
|
| 148 |
+
cell = row_text_cells[j]
|
| 149 |
+
cell.vertical_alignment = WD_ALIGN_VERTICAL.CENTER
|
| 150 |
+
set_cell_background(cell, "F4F9F5")
|
| 151 |
+
p = cell.paragraphs[0]
|
| 152 |
+
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 153 |
+
p.paragraph_format.space_before = Pt(3)
|
| 154 |
+
p.paragraph_format.space_after = Pt(3)
|
| 155 |
+
if j < len(chunk):
|
| 156 |
+
r = p.add_run(f"{label_prefix} - μ¬μ§ {i+j+1}")
|
| 157 |
+
r.font.size = Pt(9.5)
|
| 158 |
+
r.bold = True
|
| 159 |
+
r.font.color.rgb = RGBColor(45, 138, 78)
|
| 160 |
+
|
| 161 |
+
add_photo_section("2. 착곡 μ (κ³΅μ¬ μ μν)", pre_files, "착곡 μ ", header_color="2D8A4E")
|
| 162 |
+
add_photo_section("3. κ³΅μ¬ μ§ν μ€", mid_files, "μ§ν μ€", header_color="1B3A6B")
|
| 163 |
+
add_photo_section("4. κ³΅μ¬ μλ£", post_files, "κ³΅μ¬ μλ£", header_color="C25975")
|
| 164 |
+
|
| 165 |
+
if compare_before and compare_after:
|
| 166 |
+
add_styled_heading(doc, "5. κ³΅μ¬ μ Β·ν λΉκ΅", bg_color="1B3A6B")
|
| 167 |
+
|
| 168 |
+
comp_table = doc.add_table(rows=2, cols=2)
|
| 169 |
+
comp_table.alignment = WD_TABLE_ALIGNMENT.CENTER
|
| 170 |
+
comp_table.style = 'Table Grid'
|
| 171 |
+
|
| 172 |
+
cb_paths = [f.name for f in compare_before]
|
| 173 |
+
ca_paths = [f.name for f in compare_after]
|
| 174 |
+
|
| 175 |
+
cells_b = comp_table.rows[0].cells
|
| 176 |
+
for idx, path in enumerate(cb_paths[:2]):
|
| 177 |
+
set_cell_margins_zero(cells_b[idx])
|
| 178 |
+
p = cells_b[idx].paragraphs[0]
|
| 179 |
+
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 180 |
+
if os.path.exists(path):
|
| 181 |
+
p.add_run().add_picture(path, width=Inches(3.2))
|
| 182 |
+
|
| 183 |
+
cells_a = comp_table.rows[1].cells
|
| 184 |
+
for idx, path in enumerate(ca_paths[:2]):
|
| 185 |
+
set_cell_margins_zero(cells_a[idx])
|
| 186 |
+
p = cells_a[idx].paragraphs[0]
|
| 187 |
+
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 188 |
+
if os.path.exists(path):
|
| 189 |
+
p.add_run().add_picture(path, width=Inches(3.2))
|
| 190 |
+
|
| 191 |
+
add_styled_heading(doc, "6. νΉμ΄μ¬ν λ° μ’
ν© μ견", bg_color="1B3A6B")
|
| 192 |
+
|
| 193 |
+
default_remarks = (
|
| 194 |
+
"- 곡μ¬κΈ°κ° μ€ μμ μ¬κ³ μμ΄ κ³΅μ¬λ₯Ό μλ£νμμ.\n"
|
| 195 |
+
"- κ΅μ€ νκ²½μ΄ κ°μ λμ΄ νμλ€μ νμ΅νκ²½μ΄ ν₯μλ κ²μΌλ‘ κΈ°λλ¨."
|
| 196 |
+
)
|
| 197 |
+
rem_p = doc.add_paragraph()
|
| 198 |
+
rem_p.paragraph_format.space_before = Pt(3)
|
| 199 |
+
rem_p.paragraph_format.space_after = Pt(6)
|
| 200 |
+
r_run = rem_p.add_run(remarks if remarks else default_remarks)
|
| 201 |
+
r_run.font.size = Pt(10)
|
| 202 |
+
|
| 203 |
+
add_styled_heading(doc, "7. νμΈ", bg_color="1B3A6B")
|
| 204 |
+
|
| 205 |
+
sign_table = doc.add_table(rows=2, cols=3)
|
| 206 |
+
sign_table.alignment = WD_TABLE_ALIGNMENT.CENTER
|
| 207 |
+
sign_table.style = 'Table Grid'
|
| 208 |
+
|
| 209 |
+
headers = ["μμ±μ", "κ²ν μ", "νμΈμ"]
|
| 210 |
+
for j, h in enumerate(headers):
|
| 211 |
+
cell = sign_table.rows[0].cells[j]
|
| 212 |
+
cell.text = h
|
| 213 |
+
set_cell_background(cell, "E8EEF5")
|
| 214 |
+
p = cell.paragraphs[0]
|
| 215 |
+
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 216 |
+
p.runs[0].bold = True
|
| 217 |
+
p.runs[0].font.size = Pt(9.5)
|
| 218 |
+
p.runs[0].font.color.rgb = RGBColor(27, 58, 107)
|
| 219 |
+
|
| 220 |
+
for j in range(3):
|
| 221 |
+
cell = sign_table.rows[1].cells[j]
|
| 222 |
+
p = cell.paragraphs[0]
|
| 223 |
+
p.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 224 |
+
p.paragraph_format.space_before = Pt(15)
|
| 225 |
+
p.paragraph_format.space_after = Pt(15)
|
| 226 |
+
r = p.add_run("(μλͺ
)")
|
| 227 |
+
r.font.size = Pt(9)
|
| 228 |
+
r.font.color.rgb = RGBColor(120, 120, 120)
|
| 229 |
+
|
| 230 |
+
output_dir = os.path.join(os.getcwd(), "output")
|
| 231 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 232 |
+
output_path = os.path.join(output_dir, f"{project_name}_μ¬μ§λμ₯.docx")
|
| 233 |
+
doc.save(output_path)
|
| 234 |
+
|
| 235 |
+
return output_path, f"μ±κ³΅! '{project_name}' νμ€ μ¬μ§λμ₯ λ¬Έμκ° μ§μ λ μ»¬λ¬ ν
λ§λ‘ μμ±λμμ΅λλ€."
|
| 236 |
+
|
| 237 |
+
except Exception as e:
|
| 238 |
+
return None, f"μ€λ₯ λ°μ: {str(e)}"
|
| 239 |
+
|
| 240 |
+
with gr.Blocks(title="νμ€ κ³΅μ¬Β·μ©μ μ¬μ§λμ₯ μλ μμ±κΈ°") as demo:
|
| 241 |
+
gr.Markdown("# π νμ€ κ³΅μ¬Β·μ©μ μ¬μ§λμ₯ μλ μμ±κΈ°")
|
| 242 |
+
gr.Markdown("λμμΈ μμμ μμ ν
λ§μ νλͺ©μ΄ μλ²½ν λ°μλ Word λ¬Έμλ₯Ό μμ±ν©λλ€.")
|
| 243 |
+
|
| 244 |
+
with gr.Row():
|
| 245 |
+
with gr.Column(scale=1):
|
| 246 |
+
category = gr.Dropdown(choices=["곡μ¬", "μ©μ"], value="곡μ¬", label="κ³μ½ μ’
λ₯")
|
| 247 |
+
project_name = gr.Textbox(value="OOνκ΅ κ΅μ€ νκ²½κ°μ 곡μ¬", label="곡μ¬λͺ
")
|
| 248 |
+
company = gr.Textbox(value="(μ£Ό)OO건μ€", label="μ곡μ
체")
|
| 249 |
+
period = gr.Textbox(value="2026. 07. 01. ~ 2026. 07. 15.", label="곡μ¬κΈ°κ°")
|
| 250 |
+
location = gr.Textbox(value="λ³Έκ΄ 2μΈ΅ 3νλ
κ΅μ€", label="곡μ¬μμΉ")
|
| 251 |
+
amount = gr.Textbox(value="15,000,000μ", label="κ³μ½κΈμ‘")
|
| 252 |
+
department = gr.Textbox(value="νμ μ€", label="μμ±λΆμ")
|
| 253 |
+
date_str = gr.Textbox(value="2026. 07. 15.", label="μμ±μΌμ")
|
| 254 |
+
|
| 255 |
+
gr.Markdown("---")
|
| 256 |
+
pre_input = gr.File(file_count="multiple", file_types=["image"], label="2. 착곡 μ μ¬μ§ μ
λ‘λ")
|
| 257 |
+
mid_input = gr.File(file_count="multiple", file_types=["image"], label="3. κ³΅μ¬ μ§ν μ€ μ¬μ§ μ
λ‘λ")
|
| 258 |
+
post_input = gr.File(file_count="multiple", file_types=["image"], label="4. κ³΅μ¬ μλ£ μ¬μ§ μ
λ‘λ")
|
| 259 |
+
|
| 260 |
+
gr.Markdown("---")
|
| 261 |
+
compare_before = gr.File(file_count="multiple", file_types=["image"], label="5. [λΉκ΅] μ μ¬μ§ (μ΅λ 2μ₯)")
|
| 262 |
+
compare_after = gr.File(file_count="multiple", file_types=["image"], label="5. [λΉκ΅] ν μ¬μ§ (μ΅λ 2μ₯)")
|
| 263 |
+
|
| 264 |
+
remarks = gr.Textbox(value="- 곡μ¬κΈ°κ° μ€ μμ μ¬κ³ μμ΄ κ³΅μ¬λ₯Ό μλ£νμμ.\n- κ΅μ€ νκ²½μ΄ κ°μ λμ΄ νμλ€μ νμ΅νκ²½μ΄ ν₯μλ κ²μΌλ‘ κΈ°λλ¨.", label="6. νΉμ΄μ¬ν λ° μ’
ν© μ견", lines=3)
|
| 265 |
+
|
| 266 |
+
submit_btn = gr.Button("νμ€ μ¬μ§λμ₯ λ¬Έμ μμ±νκΈ°", variant="primary")
|
| 267 |
+
|
| 268 |
+
with gr.Column(scale=1):
|
| 269 |
+
output_file = gr.File(label="λ€μ΄λ‘λν Word λ¬Έμ νμΌ (.docx)")
|
| 270 |
+
status_text = gr.Textbox(label="μ§ν μν", interactive=False)
|
| 271 |
+
|
| 272 |
+
submit_btn.click(
|
| 273 |
+
fn=create_advanced_document,
|
| 274 |
+
inputs=[
|
| 275 |
+
category, project_name, company, period, location, amount, department, date_str,
|
| 276 |
+
pre_input, mid_input, post_input, compare_before, compare_after, remarks
|
| 277 |
+
],
|
| 278 |
+
outputs=[output_file, status_text]
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
if __name__ == "__main__":
|
| 282 |
+
demo.launch()
|