Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,7 +38,7 @@ def set_cell_background(cell, fill_color):
|
|
| 38 |
cell._tc.get_or_add_tcPr().append(shading_elm)
|
| 39 |
|
| 40 |
def add_styled_heading(doc, text, bg_color="1B3A6B"):
|
| 41 |
-
"""
|
| 42 |
table = doc.add_table(rows=1, cols=1)
|
| 43 |
table.alignment = WD_TABLE_ALIGNMENT.CENTER
|
| 44 |
cell = table.rows[0].cells[0]
|
|
@@ -46,13 +46,13 @@ def add_styled_heading(doc, text, bg_color="1B3A6B"):
|
|
| 46 |
set_cell_margins_zero(cell)
|
| 47 |
|
| 48 |
p = cell.paragraphs[0]
|
| 49 |
-
p.paragraph_format.space_before = Pt(
|
| 50 |
-
p.paragraph_format.space_after = Pt(
|
| 51 |
p.paragraph_format.left_indent = Inches(0.1)
|
| 52 |
|
| 53 |
run = p.add_run(text)
|
| 54 |
run.bold = True
|
| 55 |
-
run.font.size = Pt(10
|
| 56 |
run.font.color.rgb = RGBColor(255, 255, 255)
|
| 57 |
|
| 58 |
sp = doc.add_paragraph()
|
|
@@ -66,7 +66,7 @@ def create_advanced_document(
|
|
| 66 |
try:
|
| 67 |
doc = Document()
|
| 68 |
|
| 69 |
-
# νμ΄μ§ μ¬λ°±
|
| 70 |
for section in doc.sections:
|
| 71 |
section.top_margin = Inches(0.4)
|
| 72 |
section.bottom_margin = Inches(0.4)
|
|
@@ -81,7 +81,7 @@ def create_advanced_document(
|
|
| 81 |
title_run = title_p.add_run(f"[{project_name}] {category} μ¬μ§λμ₯")
|
| 82 |
title_run.font.size = Pt(15)
|
| 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")
|
|
@@ -113,8 +113,8 @@ def create_advanced_document(
|
|
| 113 |
if len(cells[c_idx].paragraphs[0].runs) > 0:
|
| 114 |
cells[c_idx].paragraphs[0].runs[0].font.size = Pt(9)
|
| 115 |
|
| 116 |
-
# 2. 착곡 μ λ° κ³΅μ¬ μ§ν μ€ (
|
| 117 |
-
add_styled_heading(doc, "2. 착곡 μ λ° κ³΅μ¬ μ§ν μ€", bg_color="2D8A4E")
|
| 118 |
|
| 119 |
pre_paths = [f.name for f in pre_files] if pre_files else []
|
| 120 |
mid_paths = [f.name for f in mid_files] if mid_files else []
|
|
@@ -165,7 +165,7 @@ def create_advanced_document(
|
|
| 165 |
r.bold = True
|
| 166 |
r.font.color.rgb = RGBColor(45, 138, 78)
|
| 167 |
|
| 168 |
-
# 3. κ³΅μ¬ μλ£ μΉμ
|
| 169 |
add_styled_heading(doc, "3. κ³΅μ¬ μλ£", bg_color="C25975")
|
| 170 |
post_paths = [f.name for f in post_files] if post_files else []
|
| 171 |
if not post_paths:
|
|
@@ -285,55 +285,4 @@ def create_advanced_document(
|
|
| 285 |
output_path = os.path.join(output_dir, f"{project_name}_μ¬μ§λμ₯.docx")
|
| 286 |
doc.save(output_path)
|
| 287 |
|
| 288 |
-
return output_path, f"μ±κ³΅! '{project_name
|
| 289 |
-
|
| 290 |
-
except Exception as e:
|
| 291 |
-
return None, f"μ€λ₯ λ°μ: {str(e)}"
|
| 292 |
-
|
| 293 |
-
with gr.Blocks(title="νμ€ κ³΅μ¬Β·μ©μ μ¬μ§λμ₯ μλ μμ±κΈ°") as demo:
|
| 294 |
-
gr.Markdown("# π νμ€ κ³΅μ¬Β·μ©μ μ¬μ§λμ₯ μλ μμ±κΈ°")
|
| 295 |
-
gr.Markdown("착곡 μ κ³Ό κ³΅μ¬ μ§ν μ€ μ¬μ§μ΄ ν μ€μ λλν λ°°μΉλλ©°, ν νμ΄μ§μ μλ§κ² λ€μ΄κ°λ μ΅μ νλ μμμ μμ±ν©λλ€.")
|
| 296 |
-
|
| 297 |
-
with gr.Row():
|
| 298 |
-
with gr.Column(scale=1):
|
| 299 |
-
category = gr.Dropdown(choices=["곡μ¬", "μ©μ"], value="곡μ¬", label="κ³μ½ μ’
λ₯")
|
| 300 |
-
project_name = gr.Textbox(value="OOνκ΅ κ΅μ€ νκ²½κ°μ 곡μ¬", label="곡μ¬λͺ
")
|
| 301 |
-
company = gr.Textbox(value="(μ£Ό)OO건μ€", label="μ곡μ
체")
|
| 302 |
-
period = gr.Textbox(value="2026. 07. 01. ~ 2026. 07. 15.", label="곡μ¬κΈ°κ°")
|
| 303 |
-
location = gr.Textbox(value="λ³Έκ΄ 2μΈ΅ 3νλ
κ΅μ€", label="곡μ¬μμΉ")
|
| 304 |
-
amount = gr.Textbox(value="15,000,000μ", label="κ³μ½κΈμ‘")
|
| 305 |
-
department = gr.Textbox(value="νμ μ€", label="μμ±λΆμ")
|
| 306 |
-
date_str = gr.Textbox(value="2026. 07. 15.", label="μμ±μΌμ")
|
| 307 |
-
|
| 308 |
-
gr.Markdown("---")
|
| 309 |
-
pre_input = gr.File(file_count="multiple", file_types=["image"], label="착곡 μ μ¬μ§ μ
λ‘λ")
|
| 310 |
-
mid_input = gr.File(file_count="multiple", file_types=["image"], label="κ³΅μ¬ μ§ν μ€ μ¬μ§ μ
λ‘λ")
|
| 311 |
-
post_input = gr.File(file_count="multiple", file_types=["image"], label="κ³΅μ¬ μλ£ μ¬μ§ μ
λ‘λ")
|
| 312 |
-
|
| 313 |
-
gr.Markdown("---")
|
| 314 |
-
compare_before = gr.File(file_count="multiple", file_types=["image"], label="[λΉκ΅] μ μ¬μ§ (μ΅λ 2μ₯)")
|
| 315 |
-
compare_after = gr.File(file_count="multiple", file_types=["image"], label="[λΉκ΅] ν μ¬μ§ (μ΅λ 2μ₯)")
|
| 316 |
-
|
| 317 |
-
default_remarks_str = (
|
| 318 |
-
"- 곡μ¬κΈ°κ° μ€ μμ μ¬κ³ μμ΄ κ³΅μ¬λ₯Ό μλ£νμμ.\n"
|
| 319 |
-
"- κ΅μ€ νκ²½μ΄ κ°μ λμ΄ νμλ€μ νμ΅νκ²½μ΄ ν₯μλ κ²μΌλ‘ κΈ°λλ¨."
|
| 320 |
-
)
|
| 321 |
-
remarks = gr.Textbox(value=default_remarks_str, label="νΉμ΄μ¬ν λ° μ’
ν© μ견", lines=3)
|
| 322 |
-
|
| 323 |
-
submit_btn = gr.Button("νμ€ μ¬μ§λμ₯ λ¬Έμ μμ±νκΈ°", variant="primary")
|
| 324 |
-
|
| 325 |
-
with gr.Column(scale=1):
|
| 326 |
-
output_file = gr.File(label="λ€μ΄λ‘λν Word λ¬Έμ νμΌ (.docx)")
|
| 327 |
-
status_text = gr.Textbox(label="μ§ν μν", interactive=False)
|
| 328 |
-
|
| 329 |
-
submit_btn.click(
|
| 330 |
-
fn=create_advanced_document,
|
| 331 |
-
inputs=[
|
| 332 |
-
category, project_name, company, period, location, amount, department, date_str,
|
| 333 |
-
pre_input, mid_input, post_input, compare_before, compare_after, remarks
|
| 334 |
-
],
|
| 335 |
-
outputs=[output_file, status_text]
|
| 336 |
-
)
|
| 337 |
-
|
| 338 |
-
if __name__ == "__main__":
|
| 339 |
-
demo.launch()
|
|
|
|
| 38 |
cell._tc.get_or_add_tcPr().append(shading_elm)
|
| 39 |
|
| 40 |
def add_styled_heading(doc, text, bg_color="1B3A6B"):
|
| 41 |
+
"""μΆλ ₯ νλ©΄κ³Ό λμΌν μμμ μΉμ
ν€λ"""
|
| 42 |
table = doc.add_table(rows=1, cols=1)
|
| 43 |
table.alignment = WD_TABLE_ALIGNMENT.CENTER
|
| 44 |
cell = table.rows[0].cells[0]
|
|
|
|
| 46 |
set_cell_margins_zero(cell)
|
| 47 |
|
| 48 |
p = cell.paragraphs[0]
|
| 49 |
+
p.paragraph_format.space_before = Pt(3)
|
| 50 |
+
p.paragraph_format.space_after = Pt(3)
|
| 51 |
p.paragraph_format.left_indent = Inches(0.1)
|
| 52 |
|
| 53 |
run = p.add_run(text)
|
| 54 |
run.bold = True
|
| 55 |
+
run.font.size = Pt(10)
|
| 56 |
run.font.color.rgb = RGBColor(255, 255, 255)
|
| 57 |
|
| 58 |
sp = doc.add_paragraph()
|
|
|
|
| 66 |
try:
|
| 67 |
doc = Document()
|
| 68 |
|
| 69 |
+
# νμ΄μ§ μ¬λ°± μ΅μ ν (ν νμ΄μ§ ꡬμ±)
|
| 70 |
for section in doc.sections:
|
| 71 |
section.top_margin = Inches(0.4)
|
| 72 |
section.bottom_margin = Inches(0.4)
|
|
|
|
| 81 |
title_run = title_p.add_run(f"[{project_name}] {category} μ¬μ§λμ₯")
|
| 82 |
title_run.font.size = Pt(15)
|
| 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")
|
|
|
|
| 113 |
if len(cells[c_idx].paragraphs[0].runs) > 0:
|
| 114 |
cells[c_idx].paragraphs[0].runs[0].font.size = Pt(9)
|
| 115 |
|
| 116 |
+
# 2. 착곡 μ λ° κ³΅μ¬ μ§ν μ€ (νλ©΄ ꡬμ±κ³Ό λμΌνκ² λλν λ°°μΉ)
|
| 117 |
+
add_styled_heading(doc, "2. 착곡 μ λ° κ³΅μ¬ μ§ν μ€", bg_color="2D8A4E") # κ·Έλ¦° ν
λ§
|
| 118 |
|
| 119 |
pre_paths = [f.name for f in pre_files] if pre_files else []
|
| 120 |
mid_paths = [f.name for f in mid_files] if mid_files else []
|
|
|
|
| 165 |
r.bold = True
|
| 166 |
r.font.color.rgb = RGBColor(45, 138, 78)
|
| 167 |
|
| 168 |
+
# 3. κ³΅μ¬ μλ£ μΉμ
(νν¬/μμ£Όμ ν
λ§)
|
| 169 |
add_styled_heading(doc, "3. κ³΅μ¬ μλ£", bg_color="C25975")
|
| 170 |
post_paths = [f.name for f in post_files] if post_files else []
|
| 171 |
if not post_paths:
|
|
|
|
| 285 |
output_path = os.path.join(output_dir, f"{project_name}_μ¬μ§λμ₯.docx")
|
| 286 |
doc.save(output_path)
|
| 287 |
|
| 288 |
+
return output_path, f"μ±κ³΅! '{project_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|