ssboost commited on
Commit
7dad958
ยท
verified ยท
1 Parent(s): 9691e07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +116 -133
app.py CHANGED
@@ -3,181 +3,164 @@ import pandas as pd
3
  import tempfile
4
  import re
5
 
6
- ########################################
7
- # 1) ๋ณธ๋ฌธ ์ „์ฒ˜๋ฆฌ: ํ•œ๊ธ€๋งŒ ๋‚จ๊ธฐ๊ณ  ์ œ๊ฑฐ #
8
- ########################################
9
  def preprocess_text(text: str) -> str:
10
  """
11
- ์‰ผํ‘œ, ๋งˆ์นจํ‘œ, ๊ณต๋ฐฑ, ์ˆซ์ž, ์˜์–ด ๋“ฑ
12
- ํ•œ๊ธ€(๊ฐ€-ํžฃ) ์ด์™ธ์˜ ๋ชจ๋“  ๋ฌธ์ž๋ฅผ ์ œ๊ฑฐํ•˜์—ฌ
13
  ํ•œ๊ธ€๋งŒ ์—ฐ์†์œผ๋กœ ๋‚จ๊ธด๋‹ค.
14
  """
15
  return re.sub(r'[^๊ฐ€-ํžฃ]', '', text)
16
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- ########################################
19
- # 2) ๋ฉ”์ธ ํ•จ์ˆ˜
20
- ########################################
21
  def count_keywords(main_text, excel_file, direct_input):
22
  """
23
- 1) ๋ณธ๋ฌธ ์ „์ฒ˜๋ฆฌ (ํ•œ๊ธ€๋งŒ).
24
- 2) ํ‚ค์›Œ๋“œ:
25
- - ์ง์ ‘ ์ž…๋ ฅ(๊ณต๋ฐฑ ์ œ์™ธ)์ด ์žˆ์œผ๋ฉด ์šฐ์„ 
26
- - ๋น„์–ด์žˆ์œผ๋ฉด ์—‘์…€ ์‚ฌ์šฉ
27
- * A5~A10000 โ†’ ํ‚ค์›Œ๋“œ
28
- * N5~N10000 โ†’ ์นด์šดํŠธ
29
- - ๋‘˜ ๋‹ค ์—†์œผ๋ฉด ์—๋Ÿฌ
30
- 3) ์นด์šดํŠธ ๋กœ์ง:
31
- - .count(ํ‚ค์›Œ๋“œ)
32
- - 1ํšŒ ์ด์ƒ๋งŒ ๊ฒฐ๊ณผ ํ‘œ(Markdown)์— ํ‘œ์‹œ
33
- 4) ์—‘์…€ ๊ฒฐ๊ณผ:
34
- - ์ง์ ‘ ์ž…๋ ฅ์ผ ๊ฒฝ์šฐ: A์—ด=ํ‚ค์›Œ๋“œ, B์—ด=์นด์šดํŠธ
35
- - ์—‘์…€ ์—…๋กœ๋“œ์ผ ๊ฒฝ์šฐ:
36
- * ๊ธฐ์กด ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„ ์‚ฌ์šฉ
37
- * A5~A10000 ์ฝ์–ด ํ‚ค์›Œ๋“œ
38
- * N5~N10000์— ์นด์šดํŠธ
39
  """
40
- # 1) ๋ณธ๋ฌธ ์ „์ฒ˜๋ฆฌ
41
  cleaned_text = preprocess_text(main_text)
42
 
43
- ####################################
44
- # ์ง์ ‘ ์ž…๋ ฅ vs ์—‘์…€ ํŒŒ์ผ ์šฐ์„ ์ˆœ์œ„
45
- ####################################
46
- direct_input = direct_input.strip() # ์•ž๋’ค ๊ณต๋ฐฑ ์ œ๊ฑฐ
47
- used_excel = False # ์—‘์…€์„ ์‚ฌ์šฉํ–ˆ๋Š”์ง€ ์—ฌ๋ถ€
48
-
49
- # ํ‚ค์›Œ๋“œ ๋ชฉ๋ก๊ณผ ์นด์šดํŠธ ๊ธฐ๋ก์„ ๋‹ด์„ df
50
- df = None
51
-
52
- # CASE A) ์ง์ ‘ ์ž…๋ ฅ์ด ์žˆ์œผ๋ฉด โ†’ ์šฐ์„  ์‚ฌ์šฉ
53
  if direct_input:
54
- # ์—ฌ๋Ÿฌ ์ค„(์—”ํ„ฐ)๋กœ ๊ตฌ๋ถ„๋œ ํ‚ค์›Œ๋“œ
55
  keywords = [kw.strip() for kw in direct_input.split('\n') if kw.strip()]
56
  if not keywords:
57
- return ("์ง์ ‘ ์ž…๋ ฅ ํ‚ค์›Œ๋“œ๊ฐ€ ๋น„์–ด์žˆ์Šต๋‹ˆ๋‹ค.", None)
58
- # DataFrame: A์—ด=ํ‚ค์›Œ๋“œ, B์—ด=์นด์šดํŠธ
59
- df = pd.DataFrame({"A": keywords})
60
-
61
- # CASE B) ์ง์ ‘ ์ž…๋ ฅ์ด ๋น„์—ˆ์œผ๋ฉด โ†’ ์—‘์…€ ํŒŒ์ผ ํ™•์ธ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  else:
 
63
  if not excel_file:
64
- return ("ํ‚ค์›Œ๋“œ๋ฅผ ์ง์ ‘ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ์—‘์…€์„ ์—…๋กœ๋“œํ•˜์„ธ์š”.", None)
65
- used_excel = True
66
- # ์—‘์…€ ์ฝ๊ธฐ
67
- temp_df = pd.read_excel(excel_file.name)
68
- # A5 ~ A10000๋งŒ ํ‚ค์›Œ๋“œ๋กœ ์‚ฌ์šฉ (์ธ๋ฑ์Šค 4~9999)
69
- # ๋งŒ์•ฝ ํ–‰ ๊ฐœ์ˆ˜๊ฐ€ 10,000๋ณด๋‹ค ์ ์œผ๋ฉด ๊ฐ€๋Šฅํ•œ ๋ฒ”์œ„๊นŒ์ง€๋งŒ ์ฒ˜๋ฆฌ
70
- max_row = min(temp_df.shape[0], 10000) # ์‹ค์ œ ํ–‰ ๊ฐœ์ˆ˜ vs 10000 ์ค‘ ์ž‘์€ ๊ฒƒ
71
- sub_df = temp_df.iloc[4:max_row, 0] # A์—ด(์ธ๋ฑ์Šค 0), 5~10000ํ–‰ โ†’ ์‹ค์ œ๋กœ๋Š” 4~9999 ์ธ๋ฑ์Šค
72
- # NaN ์ œ๊ฑฐ, ๋ฌธ์ž์—ดํ™”
73
- keywords = sub_df.dropna().astype(str).tolist()
 
74
  if not keywords:
75
  return ("A5~A10000 ๋ฒ”์œ„์— ํ‚ค์›Œ๋“œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.", None)
76
-
77
- # ๊ธฐ์กด ์—‘์…€ ์ „์ฒด๋ฅผ df๋กœ ์‚ฌ์šฉ
78
- df = temp_df.copy()
79
- # ํ˜น์‹œ ์ด๋ฏธ 'N' ์—ด์ด ์žˆ๋”๋ผ๋„ ๋ฎ์–ด์“ฐ๊ธฐ
80
- if 'N' not in df.columns:
81
- # ๋งŒ์•ฝ df๊ฐ€ 14์—ด ์ด์ƒ ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด?
82
- # ์ผ๋‹จ ์ƒˆ ์ปฌ๋Ÿผ 'N'์„ ๋งจ ๋์— ์ถ”๊ฐ€
83
- df['N'] = None
84
-
85
- # ์—ฌ๊ธฐ๊นŒ์ง€ ์˜ค๋ฉด df์™€ keywords๊ฐ€ ์กด์žฌ
86
-
87
- # 2) ์‹ค์ œ ์นด์šดํŒ…
88
- counts = [cleaned_text.count(kw) for kw in keywords]
89
-
90
- # 3) 1ํšŒ ์ด์ƒ์ธ ํ‚ค์›Œ๋“œ๋งŒ ๊ฒฐ๊ณผ ํ‘œ(Markdown)์— ํ‘œ์‹œ
91
- filtered = []
92
- for kw, cnt in zip(keywords, counts):
93
- if cnt > 0:
94
- filtered.append((kw, cnt))
95
-
96
- if not filtered:
97
- msg_no_keywords = "๋ณธ๋ฌธ์— ํ•ด๋‹น ํ‚ค์›Œ๋“œ๊ฐ€ ์ „ํ˜€ ๋“ฑ์žฅํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค (0ํšŒ)."
98
- # ๊ทธ๋ž˜๋„ ์—‘์…€ ํŒŒ์ผ์€ ๋งŒ๋“ค์–ด์ฃผ์–ด์•ผ ํ•จ
99
- # CASE A) ์ง์ ‘ ์ž…๋ ฅ
100
- if not used_excel:
101
- # ์ƒˆ df(A,B)
102
- out_df = pd.DataFrame({"A": keywords, "B": counts})
103
- with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
104
- out_df.to_excel(tmp.name, index=False)
105
- tmp_path = tmp.name
106
- return (msg_no_keywords, tmp_path)
107
- else:
108
- # CASE B) ์—‘์…€
109
- # N์—ด์— counts ๊ธฐ๋ก (A5~A10000 โ†’ N5~N10000)
110
  for i, cnt_val in enumerate(counts):
111
- row_idx = 4 + i # 0-based, 4๋ฉด ์‹ค์ œ ์—‘์…€5ํ–‰
112
  if row_idx < df.shape[0]:
113
- df.loc[row_idx, 'N'] = cnt_val
114
-
115
  with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
116
- df.to_excel(tmp.name, index=False)
117
  tmp_path = tmp.name
118
- return (msg_no_keywords, tmp_path)
119
-
120
- # (filtered) โ†’ 1ํšŒ ์ด์ƒ
121
- # ํ‘œ ๋งŒ๋“ค๊ธฐ (Markdown)
122
- lines = ["| ํ‚ค์›Œ๋“œ | ๋“ฑ์žฅ ํšŸ์ˆ˜ |", "|---|---|"]
123
- for (kw, cnt) in filtered:
124
- lines.append(f"| {kw} | {cnt} |")
125
- result_md = "\n".join(lines)
126
-
127
- # 4) ์—‘์…€ ํŒŒ์ผ ์ƒ์„ฑ/๊ฐฑ์‹ 
128
- if not used_excel:
129
- # ์ง์ ‘ ์ž…๋ ฅ:
130
- # A์—ด=ํ‚ค์›Œ๋“œ, B์—ด=์นด์šดํŠธ
131
- out_df = pd.DataFrame({"A": keywords, "B": counts})
132
- with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
133
- out_df.to_excel(tmp.name, index=False)
134
- tmp_path = tmp.name
135
- return (result_md, tmp_path)
136
- else:
137
- # ์—…๋กœ๋“œ ์—‘์…€์— N์—ด=์นด์šดํŠธ
138
  for i, cnt_val in enumerate(counts):
139
- row_idx = 4 + i # A5 ~ โ†’ N5 ~
140
  if row_idx < df.shape[0]:
141
- df.loc[row_idx, 'N'] = cnt_val
142
-
143
  with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
144
- df.to_excel(tmp.name, index=False)
145
  tmp_path = tmp.name
146
- return (result_md, tmp_path)
 
147
 
148
 
149
- #######################################
150
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค
151
- #######################################
152
  with gr.Blocks() as demo:
153
- gr.Markdown("## ๋ณธ๋ฌธ & ํ‚ค์›Œ๋“œ ๋ถ„์„ (ํŠน์ • ์…€ ๋ฒ”์œ„ ์‚ฌ์šฉ)")
154
 
155
  with gr.Row():
156
  with gr.Column():
157
- main_text = gr.Textbox(
158
  label="๋ณธ๋ฌธ ํ…์ŠคํŠธ",
159
- placeholder="์—ฌ๊ธฐ์— ๋ณธ๋ฌธ์„ ๋ณต์‚ฌํ•ด์„œ ๋ถ™์—ฌ๋„ฃ์œผ์„ธ์š”\n(ํ•œ๊ธ€ ์ด์™ธ๋Š” ์ž๋™ ์ œ๊ฑฐ๋ฉ๋‹ˆ๋‹ค)",
160
- lines=18
161
  )
162
  with gr.Column():
163
- keyword_direct = gr.Textbox(
164
- label="์ง์ ‘ ์ž…๋ ฅ ํ‚ค์›Œ๋“œ(์—”ํ„ฐ๋กœ ๊ตฌ๋ถ„)",
165
- placeholder="๊ฐ€์Šต๊ธฐ\n๊ฐ€์Šต\n์ดˆ์ŒํŒŒ\n...",
166
- lines=6
167
  )
168
- keyword_excel = gr.File(
169
- label="์—‘์…€ ์—…๋กœ๋“œ(A5~A10000: ํ‚ค์›Œ๋“œ, N5~N10000: ์นด์šดํŠธ)",
170
  file_types=[".xlsx"]
171
  )
172
- submit_btn = gr.Button("์นด์šดํŠธํ•˜๊ธฐ")
173
 
174
- output_md = gr.Markdown(label="๊ฒฐ๊ณผ (๋งˆํฌ๋‹ค์šด ํ‘œ)")
175
- output_file = gr.File(label="์—‘์…€ ๋‹ค์šด๋กœ๋“œ (์นด์šดํŠธ ๊ธฐ๋ก)")
176
 
177
- # ํด๋ฆญ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
178
- submit_btn.click(
179
  fn=count_keywords,
180
- inputs=[main_text, keyword_excel, keyword_direct],
181
  outputs=[output_md, output_file]
182
  )
183
 
 
3
  import tempfile
4
  import re
5
 
 
 
 
6
  def preprocess_text(text: str) -> str:
7
  """
8
+ ์‰ผํ‘œ, ๋งˆ์นจํ‘œ, ๊ณต๋ฐฑ, ์ˆซ์ž, ์˜์–ด ๋“ฑ
9
+ ํ•œ๊ธ€(๊ฐ€-ํžฃ) ์ด์™ธ์˜ ๋ฌธ์ž๋ฅผ ๋ชจ๋‘ ์ œ๊ฑฐํ•˜๊ณ 
10
  ํ•œ๊ธ€๋งŒ ์—ฐ์†์œผ๋กœ ๋‚จ๊ธด๋‹ค.
11
  """
12
  return re.sub(r'[^๊ฐ€-ํžฃ]', '', text)
13
 
14
+ def expand_columns_if_needed(df, needed_index: int):
15
+ """
16
+ df์— (needed_index + 1)๋ฒˆ์งธ ์—ด์ด ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฉด
17
+ ์ž„์‹œ๋กœ ํ™•์žฅํ•ด์„œ ๋นˆ ์—ด์„ ๋งŒ๋“ ๋‹ค.
18
+ ์˜ˆ) needed_index=13 โ†’ N์—ด(14๋ฒˆ์งธ ์—ด)์„ ์“ฐ๋ ค๋ฉด
19
+ df.shape[1]์ด 14 ์ด์ƒ์ด ๋˜๋„๋ก ํ™•์žฅ
20
+ """
21
+ while df.shape[1] <= needed_index:
22
+ # ๋งจ ๋์— ๋นˆ ์—ด ์ถ”๊ฐ€
23
+ df[df.shape[1]] = None
24
+
25
 
 
 
 
26
  def count_keywords(main_text, excel_file, direct_input):
27
  """
28
+ - ์ง์ ‘ ์ž…๋ ฅ ํ‚ค์›Œ๋“œ(์ค„๋ฐ”๊ฟˆ ๊ตฌ๋ถ„)๊ฐ€ ์žˆ์œผ๋ฉด ์šฐ์„  ์‚ฌ์šฉ(A์—ด=ํ‚ค์›Œ๋“œ, B์—ด=์นด์šดํŠธ)
29
+ - ์—†์œผ๋ฉด ์—‘์…€ ์‚ฌ์šฉ:
30
+ * ํ—ค๋”๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Œ(header=None) โ†’ 1ํ–‰ ๊ทธ๋Œ€๋กœ ๋ณด์กด
31
+ * A5~A10000: ํ‚ค์›Œ๋“œ
32
+ * N5~N10000: ์นด์šดํŠธ ๊ธฐ๋ก(์—ด ์ธ๋ฑ์Šค 13)
33
+ - ๋ณธ๋ฌธ์€ ํ•œ๊ธ€๋งŒ ๋‚จ๊ธฐ๊ณ  .count(ํ‚ค์›Œ๋“œ)๋กœ ๋“ฑ์žฅ ํšŸ์ˆ˜๋ฅผ ๊ณ„์‚ฐ
34
+ - 1ํšŒ ์ด์ƒ์ธ ํ‚ค์›Œ๋“œ๋งŒ ๊ฒฐ๊ณผ ํ‘œ(Markdown)์— ํ‘œ์‹œ
 
 
 
 
 
 
 
 
 
35
  """
36
+ # ๋ณธ๋ฌธ ์ „์ฒ˜๋ฆฌ
37
  cleaned_text = preprocess_text(main_text)
38
 
39
+ direct_input = direct_input.strip()
 
 
 
 
 
 
 
 
 
40
  if direct_input:
41
+ # ===== ์ง์ ‘ ์ž…๋ ฅ ํ‚ค์›Œ๋“œ ์‚ฌ์šฉ =====
42
  keywords = [kw.strip() for kw in direct_input.split('\n') if kw.strip()]
43
  if not keywords:
44
+ return ("์ง์ ‘ ์ž…๋ ฅ ํ‚ค์›Œ๋“œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.", None)
45
+
46
+ # counts
47
+ counts = [cleaned_text.count(k) for k in keywords]
48
+
49
+ # 1ํšŒ ์ด์ƒ ํ•„ํ„ฐ
50
+ filtered = [(k, c) for k, c in zip(keywords, counts) if c > 0]
51
+
52
+ if not filtered:
53
+ # ์ „๋ถ€ 0ํšŒ
54
+ msg = "๋ณธ๋ฌธ์— ํ•ด๋‹น ํ‚ค์›Œ๋“œ๊ฐ€ ์ „ํ˜€ ๋“ฑ์žฅํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค."
55
+ # ๊ทธ๋ž˜๋„ ๊ฒฐ๊ณผ ์—‘์…€(A,B) ๋งŒ๋“ค์–ด์„œ ๋ฐ˜ํ™˜
56
+ tmp_df = pd.DataFrame({"A": keywords, "B": counts})
57
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
58
+ tmp_df.to_excel(tmp.name, index=False, header=False)
59
+ # header=False โ†’ 1ํ–‰์— "A,B" ๊ฐ™์€ ์—ด์ด๋ฆ„ ์•ˆ ์“ฐ๋„๋ก
60
+ tmp_path = tmp.name
61
+ return (msg, tmp_path)
62
+
63
+ # 1ํšŒ ์ด์ƒ ํ‘œ(Markdown)
64
+ lines = ["| ํ‚ค์›Œ๋“œ | ๋“ฑ์žฅ ํšŸ์ˆ˜ |", "|---|---|"]
65
+ for (k, c) in filtered:
66
+ lines.append(f"| {k} | {c} |")
67
+ md_table = "\n".join(lines)
68
+
69
+ # ์—‘์…€(A,B) ์ €์žฅ
70
+ tmp_df = pd.DataFrame({"A": keywords, "B": counts})
71
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
72
+ tmp_df.to_excel(tmp.name, index=False, header=False)
73
+ tmp_path = tmp.name
74
+
75
+ return (md_table, tmp_path)
76
+
77
  else:
78
+ # ===== ์—‘์…€ ํŒŒ์ผ ์‚ฌ์šฉ =====
79
  if not excel_file:
80
+ return ("์—‘์…€ ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜๊ฑฐ๋‚˜ ํ‚ค์›Œ๋“œ๋ฅผ ์ง์ ‘ ์ž…๋ ฅํ•˜์„ธ์š”.", None)
81
+
82
+ # 1) ์—‘์…€ ์ „์ฒด๋ฅผ header=None๋กœ ์ฝ์Œ โ†’ 1ํ–‰ ๊ทธ๋Œ€๋กœ ๋ณด์กด
83
+ df = pd.read_excel(excel_file.name, header=None)
84
+
85
+ # 2) A5~A10000 โ†’ (์ธ๋ฑ์Šค 4~9999) ํ‚ค์›Œ๋“œ
86
+ max_row = min(df.shape[0], 10000) # ์‹ค์ œ ํ–‰ ๊ฐœ์ˆ˜ vs 10000 ์ค‘ ๋” ์ž‘์€ ๊ฒƒ
87
+ sub_df = df.iloc[4:max_row, 0] # ์ฒซ ๋ฒˆ์งธ ์—ด(์ธ๋ฑ์Šค=0)
88
+
89
+ # strip + NaN ์ œ๊ฑฐ
90
+ keywords = sub_df.dropna().astype(str).apply(lambda x: x.strip()).tolist()
91
  if not keywords:
92
  return ("A5~A10000 ๋ฒ”์œ„์— ํ‚ค์›Œ๋“œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.", None)
93
+
94
+ # counts
95
+ counts = [cleaned_text.count(k) for k in keywords]
96
+
97
+ # 1ํšŒ ์ด์ƒ ํ•„ํ„ฐ
98
+ filtered = [(k, c) for k, c in zip(keywords, counts) if c > 0]
99
+ if not filtered:
100
+ msg = "๋ณธ๋ฌธ์— ํ•ด๋‹น ํ‚ค์›Œ๋“œ๊ฐ€ ์ „ํ˜€ ๋“ฑ์žฅํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค(0ํšŒ)."
101
+ # ๊ทธ๋ž˜๋„ N5~N10000์— ๊ธฐ๋ก
102
+ expand_columns_if_needed(df, 13) # N์—ด=13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  for i, cnt_val in enumerate(counts):
104
+ row_idx = 4 + i
105
  if row_idx < df.shape[0]:
106
+ df.iloc[row_idx, 13] = cnt_val
107
+
108
  with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
109
+ df.to_excel(tmp.name, index=False, header=False)
110
  tmp_path = tmp.name
111
+ return (msg, tmp_path)
112
+
113
+ # 1ํšŒ ์ด์ƒ ํ‘œ(Markdown)
114
+ lines = ["| ํ‚ค์›Œ๋“œ | ๋“ฑ์žฅ ํšŸ์ˆ˜ |", "|---|---|"]
115
+ for (k, c) in filtered:
116
+ lines.append(f"| {k} | {c} |")
117
+ md_table = "\n".join(lines)
118
+
119
+ # N5~N10000์— ๊ธฐ๋ก
120
+ expand_columns_if_needed(df, 13) # ์—ด์ด 14๊ฐœ ๋ฏธ๋งŒ์ด๋ฉด N์—ด(13)๊นŒ์ง€ ํ™•์žฅ
 
 
 
 
 
 
 
 
 
 
121
  for i, cnt_val in enumerate(counts):
122
+ row_idx = 4 + i
123
  if row_idx < df.shape[0]:
124
+ df.iloc[row_idx, 13] = cnt_val
125
+
126
  with tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
127
+ df.to_excel(tmp.name, index=False, header=False)
128
  tmp_path = tmp.name
129
+
130
+ return (md_table, tmp_path)
131
 
132
 
133
+ ########################
134
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค #
135
+ ########################
136
  with gr.Blocks() as demo:
137
+ gr.Markdown("## ๋ณธ๋ฌธ & ํ‚ค์›Œ๋“œ ๋ถ„์„ - (A5~A10000, N5~N10000)")
138
 
139
  with gr.Row():
140
  with gr.Column():
141
+ main_textbox = gr.Textbox(
142
  label="๋ณธ๋ฌธ ํ…์ŠคํŠธ",
143
+ lines=16,
144
+ placeholder="์—ฌ๊ธฐ์— ๊ธด ๋ณธ๋ฌธ์„ ๋ถ™์—ฌ๋„ฃ์œผ์„ธ์š”. ํ•œ๊ธ€๋งŒ ๋‚จ๊ธฐ๊ณ  ๋‚˜๋จธ์ง€๋Š” ์ œ๊ฑฐ๋ฉ๋‹ˆ๋‹ค."
145
  )
146
  with gr.Column():
147
+ keyword_input = gr.Textbox(
148
+ label="(์„ ํƒ) ์ง์ ‘ ์ž…๋ ฅ ํ‚ค์›Œ๋“œ - ์—”ํ„ฐ๋กœ ๊ตฌ๋ถ„",
149
+ lines=6,
150
+ placeholder="์˜ˆ)\n์ดˆ์ŒํŒŒ๊ฐ€์Šต๊ธฐ\n๊ฐ€์Šต๊ธฐ\n..."
151
  )
152
+ excel_input = gr.File(
153
+ label="(์„ ํƒ) ์—‘์…€ ์—…๋กœ๋“œ (A5~A10000=ํ‚ค์›Œ๋“œ, N5~N10000=์นด์šดํŠธ)",
154
  file_types=[".xlsx"]
155
  )
156
+ run_button = gr.Button("์นด์šดํŠธํ•˜๊ธฐ")
157
 
158
+ output_md = gr.Markdown(label="๊ฒฐ๊ณผ ํ‘œ")
159
+ output_file = gr.File(label="๊ฒฐ๊ณผ ์—‘์…€ ๋‹ค์šด๋กœ๋“œ")
160
 
161
+ run_button.click(
 
162
  fn=count_keywords,
163
+ inputs=[main_textbox, excel_input, keyword_input],
164
  outputs=[output_md, output_file]
165
  )
166