chanmin0723 commited on
Commit
84d982f
Β·
verified Β·
1 Parent(s): 4bdf24c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +142 -5
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()