chanmin0723 commited on
Commit
b4604df
Β·
verified Β·
1 Parent(s): 80e5977

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -61
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(4)
50
- p.paragraph_format.space_after = Pt(4)
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.5)
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