ssboost commited on
Commit
c8b9002
ยท
verified ยท
1 Parent(s): 36c30ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +191 -22
app.py CHANGED
@@ -8,6 +8,7 @@ import time
8
  import random
9
  import os
10
  from huggingface_hub import InferenceClient
 
11
 
12
  def setup_session():
13
  try:
@@ -112,26 +113,29 @@ def call_api(content, system_message, max_tokens, temperature, top_p):
112
  total_tokens = response.usage.total_tokens
113
  return modified_text, input_tokens, output_tokens, total_tokens
114
 
115
- def analyze_info(category, topic, references1, references2, references3):
116
- return f"์„ ํƒํ•œ ์นดํ…Œ๊ณ ๋ฆฌ: {category}\n๋ธ”๋กœ๊ทธ ์ฃผ์ œ: {topic}\n์ฐธ๊ณ  ๊ธ€1: {references1}\n์ฐธ๊ณ  ๊ธ€2: {references2}\n์ฐธ๊ณ  ๊ธ€3: {references3}"
117
 
118
- def suggest_title(category, topic, references1, references2, references3, system_message, max_tokens, temperature, top_p):
119
- full_content = analyze_info(category, topic, references1, references2, references3)
120
- modified_text, input_tokens, output_tokens, total_tokens = call_api(full_content, system_message, max_tokens, temperature, top_p)
 
121
  token_usage_message = f"[์ž…๋ ฅ ํ† ํฐ์ˆ˜: {input_tokens}]\n[์ถœ๋ ฅ ํ† ํฐ์ˆ˜: {output_tokens}]\n[์ด ํ† ํฐ์ˆ˜: {total_tokens}]"
122
  return modified_text, token_usage_message
123
 
124
- def generate_outline(category, topic, references1, references2, references3, title, system_message, max_tokens, temperature, top_p):
125
- full_content = analyze_info(category, topic, references1, references2, references3)
126
  content = f"{full_content}\nTitle: {title}"
127
- modified_text, input_tokens, output_tokens, total_tokens = call_api(content, system_message, max_tokens, temperature, top_p)
 
128
  token_usage_message = f"[์ž…๋ ฅ ํ† ํฐ์ˆ˜: {input_tokens}]\n[์ถœ๋ ฅ ํ† ํฐ์ˆ˜: {output_tokens}]\n[์ด ํ† ํฐ์ˆ˜: {total_tokens}]"
129
  return modified_text, token_usage_message
130
 
131
- def generate_blog_post(category, topic, references1, references2, references3, title, outline, system_message, max_tokens, temperature, top_p):
132
- full_content = analyze_info(category, topic, references1, references2, references3)
133
  content = f"{full_content}\nTitle: {title}\nOutline: {outline}"
134
- modified_text, input_tokens, output_tokens, total_tokens = call_api(content, system_message, max_tokens, temperature, top_p)
 
135
  formatted_text = modified_text.replace('\n', '\n\n')
136
  token_usage_message = f"[์ž…๋ ฅ ํ† ํฐ์ˆ˜: {input_tokens}]\n[์ถœ๋ ฅ ํ† ํฐ์ˆ˜: {output_tokens}]\n[์ด ํ† ํฐ์ˆ˜: {total_tokens}]"
137
  return formatted_text, token_usage_message
@@ -152,7 +156,7 @@ def fetch_references(topic):
152
 
153
  return "์ฐธ๊ณ ๊ธ€ ์ƒ์„ฑ ์™„๋ฃŒ", references1_content, references2_content, references3_content
154
 
155
- def fetch_references_and_generate_all_steps(category, topic, blog_title, system_message_outline, max_tokens_outline, temperature_outline, top_p_outline, system_message_blog_post, max_tokens_blog_post, temperature_blog_post, top_p_blog_post):
156
  search_url = generate_naver_search_url(topic)
157
  session = setup_session()
158
  if session is None:
@@ -168,10 +172,10 @@ def fetch_references_and_generate_all_steps(category, topic, blog_title, system_
168
  references3_content = f"์ œ๋ชฉ: {selected_results[2]['์ œ๋ชฉ']}\n๋‚ด์šฉ: {crawl_blog_content(selected_results[2]['๋งํฌ'], session)}"
169
 
170
  # ์•„์›ƒ๋ผ์ธ ์ƒ์„ฑ
171
- outline_result, outline_token_usage = generate_outline(category, topic, references1_content, references2_content, references3_content, blog_title, system_message_outline, max_tokens_outline, temperature_outline, top_p_outline)
172
 
173
  # ๋ธ”๋กœ๊ทธ ๊ธ€ ์ƒ์„ฑ
174
- blog_post_result, blog_post_token_usage = generate_blog_post(category, topic, references1_content, references2_content, references3_content, blog_title, outline_result, system_message_blog_post, max_tokens_blog_post, temperature_blog_post, top_p_blog_post)
175
 
176
  return references1_content, references2_content, references3_content, outline_result, outline_token_usage, blog_post_result, blog_post_token_usage
177
 
@@ -205,24 +209,183 @@ def get_blog_post_prompt(category):
205
  # ๋ธ”๋กœ๊ทธ ํ…์ŠคํŠธ ์ƒ์„ฑ ๊ทœ์น™(๊ฑด๊ฐ•์ •๋ณด)
206
  """
207
 
208
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  title = "์ •๋ณด์„ฑ ํฌ์ŠคํŒ… ์ž๋™์ƒ์„ฑ๊ธฐ(์ œ๋ชฉ์ถ”์ฒœ ํ›„ ์ž๋™)"
210
 
211
- def update_prompts(category):
212
  title_prompt = get_title_prompt(category)
213
  outline_prompt = get_outline_prompt(category)
214
  blog_post_prompt = get_blog_post_prompt(category)
215
- return title_prompt, outline_prompt, blog_post_prompt
 
 
216
 
217
  with gr.Blocks() as demo:
218
  gr.Markdown(f"# {title}")
219
 
220
- # 1๋‹จ๊ณ„
221
  gr.Markdown("### 1๋‹จ๊ณ„ : ํฌ์ŠคํŒ… ์นดํ…Œ๊ณ ๋ฆฌ๋ฅผ ์ง€์ •ํ•ด์ฃผ์„ธ์š”")
222
  category = gr.Radio(choices=["์ผ๋ฐ˜", "๊ฑด๊ฐ•์ •๋ณด"], label="ํฌ์ŠคํŒ… ์นดํ…Œ๊ณ ๋ฆฌ", value="์ผ๋ฐ˜")
223
 
 
 
 
 
 
 
 
 
224
  # 2๋‹จ๊ณ„
225
- gr.Markdown("### 2๋‹จ๊ณ„ : ๋ธ”๋กœ๊ทธ ์ฃผ์ œ, ๋˜๋Š” ํ‚ค์›Œ๋“œ๋ฅผ ์ƒ์„ธํžˆ ์ž…๋ ฅํ•˜์„ธ์š”")
226
  topic = gr.Textbox(label="๋ธ”๋กœ๊ทธ ์ฃผ์ œ(์˜ˆ์‹œ: ์˜ค์ง•์–ด ๋ฌด์นจํšŒ(X), ์˜ค์ง•์–ด ๋ฌด์นจํšŒ ๋ ˆ์‹œํ”ผ(O))", placeholder="์˜ˆ์‹œ: ์—ฌํ–‰์ง€ ์ถ”์ฒœ(X), 8์›” ๊ตญ๋‚ด ์—ฌํ–‰์ง€ ์ถ”์ฒœ(O)")
227
 
228
  # 3๋‹จ๊ณ„: ์ฐธ๊ณ  ๊ธ€์„ ์œ„ํ•œ ๋ณ€์ˆ˜๋“ค ๋ฏธ๋ฆฌ ์ •์˜
@@ -244,7 +407,7 @@ with gr.Blocks() as demo:
244
 
245
  # ์ œ๋ชฉ ์ถ”์ฒœ ๋ฒ„ํŠผ
246
  title_btn = gr.Button("์ œ๋ชฉ ์ถ”์ฒœํ•˜๊ธฐ")
247
- title_btn.click(fn=suggest_title, inputs=[category, topic, references1, references2, references3, title_system_message, title_max_tokens, title_temperature, title_top_p], outputs=[title_suggestions, title_token_output])
248
 
249
  blog_title = gr.Textbox(label="๋ธ”๋กœ๊ทธ ์ œ๋ชฉ", placeholder="๋ธ”๋กœ๊ทธ ์ œ๋ชฉ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”")
250
 
@@ -272,10 +435,16 @@ with gr.Blocks() as demo:
272
  generate_post_btn = gr.Button("๋ธ”๋กœ๊ทธ ๊ธ€ ์ƒ์„ฑํ•˜๊ธฐ")
273
  generate_post_btn.click(
274
  fn=fetch_references_and_generate_all_steps,
275
- inputs=[category, topic, blog_title, outline_system_message, outline_max_tokens, outline_temperature, outline_top_p, blog_system_message, blog_max_tokens, blog_temperature, blog_top_p],
276
  outputs=[references1, references2, references3, outline_result, outline_token_output, output, token_output]
277
  )
278
 
279
- category.change(fn=update_prompts, inputs=category, outputs=[title_system_message, outline_system_message, blog_system_message])
 
 
 
 
 
 
280
 
281
  demo.launch()
 
8
  import random
9
  import os
10
  from huggingface_hub import InferenceClient
11
+ from fpdf import FPDF
12
 
13
  def setup_session():
14
  try:
 
113
  total_tokens = response.usage.total_tokens
114
  return modified_text, input_tokens, output_tokens, total_tokens
115
 
116
+ def analyze_info(category, style, topic, references1, references2, references3):
117
+ return f"์„ ํƒํ•œ ์นดํ…Œ๊ณ ๋ฆฌ: {category}\n์„ ํƒํ•œ ํฌ์ŠคํŒ… ์Šคํƒ€์ผ: {style}\n๋ธ”๋กœ๊ทธ ์ฃผ์ œ: {topic}\n์ฐธ๊ณ  ๊ธ€1: {references1}\n์ฐธ๊ณ  ๊ธ€2: {references2}\n์ฐธ๊ณ  ๊ธ€3: {references3}"
118
 
119
+ def suggest_title(category, style, topic, references1, references2, references3, category_prompt, style_prompt, max_tokens, temperature, top_p):
120
+ full_content = analyze_info(category, style, topic, references1, references2, references3)
121
+ combined_prompt = f"{category_prompt}\n\n{style_prompt}"
122
+ modified_text, input_tokens, output_tokens, total_tokens = call_api(full_content, combined_prompt, max_tokens, temperature, top_p)
123
  token_usage_message = f"[์ž…๋ ฅ ํ† ํฐ์ˆ˜: {input_tokens}]\n[์ถœ๋ ฅ ํ† ํฐ์ˆ˜: {output_tokens}]\n[์ด ํ† ํฐ์ˆ˜: {total_tokens}]"
124
  return modified_text, token_usage_message
125
 
126
+ def generate_outline(category, style, topic, references1, references2, references3, title, category_prompt, style_prompt, max_tokens, temperature, top_p):
127
+ full_content = analyze_info(category, style, topic, references1, references2, references3)
128
  content = f"{full_content}\nTitle: {title}"
129
+ combined_prompt = f"{category_prompt}\n\n{style_prompt}"
130
+ modified_text, input_tokens, output_tokens, total_tokens = call_api(content, combined_prompt, max_tokens, temperature, top_p)
131
  token_usage_message = f"[์ž…๋ ฅ ํ† ํฐ์ˆ˜: {input_tokens}]\n[์ถœ๋ ฅ ํ† ํฐ์ˆ˜: {output_tokens}]\n[์ด ํ† ํฐ์ˆ˜: {total_tokens}]"
132
  return modified_text, token_usage_message
133
 
134
+ def generate_blog_post(category, style, topic, references1, references2, references3, title, outline, category_prompt, style_prompt, max_tokens, temperature, top_p):
135
+ full_content = analyze_info(category, style, topic, references1, references2, references3)
136
  content = f"{full_content}\nTitle: {title}\nOutline: {outline}"
137
+ combined_prompt = f"{category_prompt}\n\n{style_prompt}"
138
+ modified_text, input_tokens, output_tokens, total_tokens = call_api(content, combined_prompt, max_tokens, temperature, top_p)
139
  formatted_text = modified_text.replace('\n', '\n\n')
140
  token_usage_message = f"[์ž…๋ ฅ ํ† ํฐ์ˆ˜: {input_tokens}]\n[์ถœ๋ ฅ ํ† ํฐ์ˆ˜: {output_tokens}]\n[์ด ํ† ํฐ์ˆ˜: {total_tokens}]"
141
  return formatted_text, token_usage_message
 
156
 
157
  return "์ฐธ๊ณ ๊ธ€ ์ƒ์„ฑ ์™„๋ฃŒ", references1_content, references2_content, references3_content
158
 
159
+ def fetch_references_and_generate_all_steps(category, style, topic, blog_title, system_message_outline, max_tokens_outline, temperature_outline, top_p_outline, system_message_blog_post, max_tokens_blog_post, temperature_blog_post, top_p_blog_post):
160
  search_url = generate_naver_search_url(topic)
161
  session = setup_session()
162
  if session is None:
 
172
  references3_content = f"์ œ๋ชฉ: {selected_results[2]['์ œ๋ชฉ']}\n๋‚ด์šฉ: {crawl_blog_content(selected_results[2]['๋งํฌ'], session)}"
173
 
174
  # ์•„์›ƒ๋ผ์ธ ์ƒ์„ฑ
175
+ outline_result, outline_token_usage = generate_outline(category, style, topic, references1_content, references2_content, references3_content, blog_title, system_message_outline, max_tokens_outline, temperature_outline, top_p_outline)
176
 
177
  # ๋ธ”๋กœ๊ทธ ๊ธ€ ์ƒ์„ฑ
178
+ blog_post_result, blog_post_token_usage = generate_blog_post(category, style, topic, references1_content, references2_content, references3_content, blog_title, outline_result, system_message_blog_post, max_tokens_blog_post, temperature_blog_post, top_p_blog_post)
179
 
180
  return references1_content, references2_content, references3_content, outline_result, outline_token_usage, blog_post_result, blog_post_token_usage
181
 
 
209
  # ๋ธ”๋กœ๊ทธ ํ…์ŠคํŠธ ์ƒ์„ฑ ๊ทœ์น™(๊ฑด๊ฐ•์ •๋ณด)
210
  """
211
 
212
+ def get_style_prompt(style):
213
+ prompts = {
214
+ "์นœ๊ทผํ•œ": """
215
+ #์นœ๊ทผํ•œ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŒ… ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ
216
+ 1. ํ†ค๊ณผ ์–ด์กฐ
217
+ - ๋Œ€ํ™”ํ•˜๋“ฏ ํŽธ์•ˆํ•˜๊ณ  ์นœ๊ทผํ•œ ๋งํˆฌ ์‚ฌ์šฉ
218
+ - ๋…์ž๋ฅผ "์—ฌ๋Ÿฌ๋ถ„" ๋˜๋Š” "๋…์ž๋‹˜๋“ค"๋กœ ์ง€์นญ
219
+ - ์ ์ ˆํ•œ ์ด๋ชจ์ง€๋ฅผ sparseํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜์—ฌ ์นœ๊ทผ๊ฐ ํ‘œํ˜„
220
+ 2. ๋ฌธ์žฅ ๋ฐ ๋‚ด์šฉ ๊ตฌ์„ฑ
221
+ - ์งง๊ณ  ๊ฐ„๊ฒฐํ•œ ๋ฌธ์žฅ ์œ„์ฃผ๋กœ ์ž‘์„ฑ
222
+ - ๊ตฌ์–ด์ฒด ํ‘œํ˜„ ์‚ฌ์šฉ (์˜ˆ: "~ํ–ˆ์–ด์š”", "~์ธ ๊ฒƒ ๊ฐ™์•„์š”")
223
+ - '~๋‹ˆ๋‹ค', '~ํ–ˆ์ฃ '๋Š” ์‚ฌ์šฉํ•˜์ง€ ๋ง ๊ฒƒ.
224
+ - ๊ฐœ์ธ์ ์ธ ๊ฒฝํ—˜์ด๋‚˜ ์ผํ™”๋กœ ์‹œ์ž‘
225
+ - ์‹ค์ƒํ™œ์—์„œ ์‰ฝ๊ฒŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํŒ ์ œ๊ณต
226
+ - ๋…์ž์˜ ๊ณต๊ฐ์„ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์‚ฌ๋ก€ ํฌํ•จ
227
+ 3. ์šฉ์–ด ๋ฐ ์„ค๋ช… ๋ฐฉ์‹
228
+ - ์ „๋ฌธ ์šฉ์–ด ๋Œ€์‹  ์‰ฌ์šด ๋‹จ์–ด๋กœ ํ’€์–ด์„œ ์„ค๋ช…
229
+ - ๋น„์œ ๋‚˜ ์€์œ ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋ณต์žกํ•œ ๊ฐœ๋… ์„ค๋ช…
230
+ - ์ˆ˜์‚ฌ์˜๋ฌธ๋ฌธ ํ™œ์šฉํ•˜์—ฌ ๋…์ž์™€ ์†Œํ†ตํ•˜๋Š” ๋А๋‚Œ ์ฃผ๊ธฐ
231
+ 4. ๋…์ž์™€์˜ ์ƒํ˜ธ์ž‘์šฉ
232
+ - ๋…์ž์˜ ์˜๊ฒฌ์„ ๋ฌผ์–ด๋ณด๋Š” ์งˆ๋ฌธ ํฌํ•จ
233
+ - ๋Œ“๊ธ€ ๋‹ฌ๊ธฐ๋ฅผ ๋…๋ คํ•˜๋Š” ๋ฌธ๊ตฌ ์‚ฌ์šฉ
234
+ 5. ์ด๋ชจ์ง€ ํ™œ์šฉ
235
+ - ์ฃผ์š” ํฌ์ธํŠธ๋‚˜ ์ƒˆ๋กœ์šด ์„น์…˜์„ ์‹œ์ž‘ํ•  ๋•Œ๋งŒ ๊ด€๋ จ ์ด๋ชจ์ง€ ์‚ฌ์šฉ
236
+ - ์ „์ฒด ๊ธ€์—์„œ 3-5๊ฐœ ์ •๋„์˜ ์ด๋ชจ์ง€๋งŒ ์‚ฌ์šฉํ•˜์—ฌ ๊ณผ๋„ํ•˜์ง€ ์•Š๊ฒŒ ์œ ์ง€
237
+ 6. ๋งˆ๋ฌด๋ฆฌ
238
+ - ์นœ๊ทผํ•˜๊ณ  ๊ฒฉ๋ คํ•˜๋Š” ํ†ค์œผ๋กœ ๋งˆ๋ฌด๋ฆฌ
239
+ - ๋‹ค์Œ ํฌ์ŠคํŒ…์— ๋Œ€ํ•œ ๊ธฐ๋Œ€๊ฐ ์œ ๋ฐœ
240
+ ์ฃผ์˜์‚ฌํ•ญ: ๋„ˆ๋ฌด ๊ฐ€๋ฒผ์šด ํ†ค์€ ์ง€์–‘ํ•˜๊ณ , ์ฃผ์ œ์˜ ์ค‘์š”์„ฑ์„ ํ•ด์น˜์ง€ ์•Š๋Š” ์„ ์—์„œ ์นœ๊ทผํ•จ ์œ ์ง€
241
+ ์˜ˆ์‹œ: "์—ฌ๋Ÿฌ๋ถ„, ์˜ค๋Š˜ ํ•˜๋ฃจ๋Š” ์–ด๋– ์…จ๋‚˜์š”? ๐Ÿ˜Š ์ €๋Š” ์˜ค๋Š˜ ์žฌ๋ฏธ์žˆ๋Š” ๊ฒฝํ—˜์„ ํ–ˆ์–ด์š”. ๋ฐ”๋กœ '๋ฏธ๋‹ˆ๋ฉ€ ๋ผ์ดํ”„'์— ๋„์ „ํ•ด๋ณธ ๊ฑด๋ฐ์š”. ์ฒ˜์Œ์—๋Š” ์ข€ ๋ง‰๋ง‰ํ–ˆ์ง€๋งŒ, ์ƒ๊ฐ๋ณด๋‹ค ์ฆ๊ฑฐ์šด ๊ฒฝํ—˜์ด์—ˆ์–ด์š”! ์—ฌ๋Ÿฌ๋ถ„๋„ ํ•œ๋ฒˆ ๋”ฐ๋ผํ•ด๋ณด์‹œ๊ฒ ์–ด์š”? ์ œ๊ฐ€ ์•Œ๊ฒŒ ๋œ ๊ฟ€ํŒ๋“ค์„ ํ•˜๋‚˜ํ•˜๋‚˜ ์•Œ๋ ค๋“œ๋ฆด๊ฒŒ์š”.
242
+ """,
243
+ "์ผ๋ฐ˜": """
244
+ #์ผ๋ฐ˜์ ์ธ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŒ… ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ
245
+ 1. ํ†ค๊ณผ ์–ด์กฐ
246
+ - ์ค‘๋ฆฝ์ ์ด๊ณ  ๊ฐ๊ด€์ ์ธ ํ†ค ์œ ์ง€
247
+ - ์ ์ ˆํ•œ ์กด๋Œ“๋ง ์‚ฌ์šฉ (์˜ˆ: "~ํ•ฉ๋‹ˆ๋‹ค", "~์ž…๋‹ˆ๋‹ค")
248
+ 2. ๋‚ด์šฉ ๊ตฌ์กฐ ๋ฐ ์ „๊ฐœ
249
+ - ๋ช…ํ™•ํ•œ ์ฃผ์ œ ์ œ์‹œ๋กœ ์‹œ์ž‘
250
+ - ๋…ผ๋ฆฌ์ ์ธ ์ˆœ์„œ๋กœ ์ •๋ณด ์ „๊ฐœ
251
+ - ์ฃผ์š” ํฌ์ธํŠธ๋ฅผ ๊ฐ•์กฐํ•˜๋Š” ์†Œ์ œ๋ชฉ ํ™œ์šฉ
252
+ - ์ ์ ˆํ•œ ๊ธธ์ด์˜ ๋‹จ๋ฝ์œผ๋กœ ๊ตฌ์„ฑ
253
+ 3. ์šฉ์–ด ๋ฐ ์„ค๋ช… ๋ฐฉ์‹
254
+ - ์ผ๋ฐ˜์ ์œผ๋กœ ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์šด ์šฉ์–ด ์„ ํƒ
255
+ - ํ•„์š”์‹œ ๊ฐ„๋‹จํ•œ ์„ค๋ช… ์ถ”๊ฐ€
256
+ - ๊ฐ๊ด€์ ์ธ ์ •๋ณด ์ œ๊ณต์— ์ค‘์ 
257
+ 4. ํ…์ŠคํŠธ ๊ตฌ์กฐํ™”
258
+ - ๋ถˆ๋ฆฟ ํฌ์ธํŠธ๋‚˜ ๋ฒˆํ˜ธ ๋งค๊ธฐ๊ธฐ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ •๋ณด ๊ตฌ์กฐํ™”
259
+ - ์ค‘์š”ํ•œ ์ •๋ณด๋Š” ๊ตต์€ ๊ธ€์”จ๋‚˜ ๊ธฐ์šธ์ž„๊ผด๋กœ ๊ฐ•์กฐ
260
+ 5. ๋…์ž ์ƒํ˜ธ์ž‘์šฉ
261
+ - ์ ์ ˆํžˆ ๋…์ž์˜ ์ƒ๊ฐ์„ ๋ฌป๋Š” ์งˆ๋ฌธ ํฌํ•จ
262
+ - ์ถ”๊ฐ€ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ๋Š” ํ‚ค์›Œ๋“œ ์ œ์‹œ
263
+ 6. ๋งˆ๋ฌด๋ฆฌ
264
+ - ์ฃผ์š” ๋‚ด์šฉ ๊ฐ„๋‹จํžˆ ์š”์•ฝ
265
+ - ์ถ”๊ฐ€ ์ •๋ณด์— ๋Œ€ํ•œ ์•ˆ๋‚ด ์ œ๊ณต
266
+ ์ฃผ์˜์‚ฌํ•ญ: ๋„ˆ๋ฌด ๋”ฑ๋”ฑํ•˜๊ฑฐ๋‚˜ ์ง€๋ฃจํ•˜์ง€ ์•Š๋„๋ก ๊ท ํ˜• ์œ ์ง€
267
+ ์˜ˆ์‹œ: "์ตœ๊ทผ ํ™˜๊ฒฝ ๋ฌธ์ œ๊ฐ€ ๋Œ€๋‘๋˜๋ฉด์„œ '์ œ๋กœ ์›จ์ด์ŠคํŠธ' ๋ผ์ดํ”„์Šคํƒ€์ผ์— ๋Œ€ํ•œ ๊ด€์‹ฌ์ด ๋†’์•„์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ œ๋กœ ์›จ์ด์ŠคํŠธ๋ž€ ์ผ์ƒ์ƒํ™œ์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์“ฐ๋ ˆ๊ธฐ๋ฅผ ์ตœ์†Œํ™”ํ•˜๋Š” ์ƒํ™œ ๋ฐฉ์‹์„ ๋งํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ธ€์—์„œ๋Š” ์ œ๋กœ ์›จ์ด์ŠคํŠธ์˜ ๊ฐœ๋…, ์‹ค์ฒœ ๋ฐฉ๋ฒ•, ๊ทธ๋ฆฌ๊ณ  ๊ทธ ํšจ๊ณผ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋จผ์ € ์ œ๋กœ ์›จ์ด์ŠคํŠธ์˜ ์ •์˜๋ถ€ํ„ฐ ์‚ดํŽด๋ณด๋ฉด...
268
+ """,
269
+ "์ „๋ฌธ์ ์ธ": """
270
+ #์ „๋ฌธ์ ์ธ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŒ… ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ
271
+ 1. ํ†ค๊ณผ ๊ตฌ์กฐ
272
+ - ๊ณต์‹์ ์ด๊ณ  ํ•™์ˆ ์ ์ธ ํ†ค ์‚ฌ์šฉ
273
+ - ๊ฐ๊ด€์ ์ด๊ณ  ๋ถ„์„์ ์ธ ์ ‘๊ทผ ์œ ์ง€
274
+ - ๋ช…ํ™•ํ•œ ์„œ๋ก , ๋ณธ๋ก , ๊ฒฐ๋ก  ๊ตฌ์กฐ
275
+ - ์ฒด๊ณ„์ ์ธ ๋…ผ์  ์ „๊ฐœ
276
+ - ์„ธ๋ถ€ ์„น์…˜์„ ์œ„ํ•œ ๋ช…ํ™•ํ•œ ์†Œ์ œ๋ชฉ ์‚ฌ์šฉ
277
+ 2. ๋‚ด์šฉ ๊ตฌ์„ฑ ๋ฐ ์ „๊ฐœ
278
+ - ๋ณต์žกํ•œ ๊ฐœ๋…์„ ์ •ํ™•ํžˆ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์žฅ ๊ตฌ์กฐ ์‚ฌ์šฉ
279
+ - ๋…ผ๋ฆฌ์  ์—ฐ๊ฒฐ์„ ์œ„ํ•œ ์ „ํ™˜์–ด ๏ฟฝ๏ฟฝ์šฉ
280
+ - ํ•ด๋‹น ๋ถ„์•ผ์˜ ์ „๋ฌธ ์šฉ์–ด ์ ๊ทน ํ™œ์šฉ (ํ•„์š”์‹œ ๊ฐ„๋žตํ•œ ์„ค๋ช… ์ œ๊ณต)
281
+ - ์‹ฌ์ธต์ ์ธ ๋ถ„์„๊ณผ ๋น„ํŒ์  ์‚ฌ๊ณ  ์ „๊ฐœ
282
+ - ๋‹ค์–‘ํ•œ ๊ด€์  ์ œ์‹œ ๋ฐ ๋น„๊ต
283
+ 3. ๋ฐ์ดํ„ฐ ๋ฐ ๊ทผ๊ฑฐ ํ™œ์šฉ
284
+ - ํ†ต๊ณ„, ์—ฐ๊ตฌ ๊ฒฐ๊ณผ, ์ „๋ฌธ๊ฐ€ ์˜๊ฒฌ ๋“ฑ ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ์ถœ์ฒ˜ ์ธ์šฉ
285
+ - ํ•„์š”์‹œ ๊ฐ์ฃผ๋‚˜ ์ฐธ๊ณ ๋ฌธํ—Œ ๋ชฉ๋ก ํฌํ•จ
286
+ - ์ˆ˜์น˜ ๋ฐ์ดํ„ฐ๋Š” ํ…์ŠคํŠธ๋กœ ๋ช…ํ™•ํžˆ ์„ค๋ช…
287
+ 4. ํ…์ŠคํŠธ ๊ตฌ์กฐํ™”
288
+ - ๋…ผ๋ฆฌ์  ๊ตฌ์กฐ๋ฅผ ๊ฐ•์กฐํ•˜๊ธฐ ์œ„ํ•ด ๋ฒˆํ˜ธ ๋งค๊ธฐ๊ธฐ ์‚ฌ์šฉ
289
+ - ํ•ต์‹ฌ ๊ฐœ๋…์ด๋‚˜ ์šฉ์–ด๋Š” ๊ธฐ์šธ์ž„๊ผด๋กœ ๊ฐ•์กฐ
290
+ - ๊ธด ์ธ์šฉ๋ฌธ์€ ๋“ค์—ฌ์“ฐ๊ธฐ๋กœ ๊ตฌ๋ถ„
291
+ 5. ๋งˆ๋ฌด๋ฆฌ
292
+ - ํ•ต์‹ฌ ๋…ผ์  ์žฌ๊ฐ•์กฐ
293
+ - ํ–ฅํ›„ ์—ฐ๊ตฌ ๋ฐฉํ–ฅ์ด๋‚˜ ์‹ค๋ฌด์  ํ•จ์˜ ์ œ์‹œ
294
+ ์ฃผ์˜์‚ฌํ•ญ: ์ „๋ฌธ์„ฑ์„ ์œ ์ง€ํ•˜๋˜, ์™„์ „ํžˆ ์ดํ•ดํ•˜๊ธฐ ์–ด๋ ค์šด ์ˆ˜์ค€์€ ์ง€์–‘
295
+ ์˜ˆ์‹œ: "๋ณธ ์—ฐ๊ตฌ์—์„œ๋Š” ์ธ๊ณต์ง€๋Šฅ(AI)์˜ ์œค๋ฆฌ์  ํ•จ์˜์— ๋Œ€ํ•ด ๊ณ ์ฐฐํ•œ๋‹ค. ํŠนํžˆ, ์ž์œจ์ฃผํ–‰ ์ž๋™์ฐจ์˜ ์˜์‚ฌ๊ฒฐ์ • ์•Œ๊ณ ๋ฆฌ์ฆ˜์—์„œ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ์œค๋ฆฌ์  ๋”œ๋ ˆ๋งˆ์— ์ดˆ์ ์„ ๋งž์ถ˜๋‹ค. Bonnefon et al. (2016)์˜ ์—ฐ๊ตฌ์— ๋”ฐ๋ฅด๋ฉด, ์ž์œจ์ฃผํ–‰ ์ฐจ๋Ÿ‰์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์ง๋ฉดํ•  ์ˆ˜ ์žˆ๋Š” ์œค๋ฆฌ์  ์„ ํƒ์˜ ๋ณต์žก์„ฑ์ด ์ง€์ ๋œ ๋ฐ” ์žˆ๋‹ค. ๋ณธ๊ณ ์—์„œ๋Š” ์ด๋Ÿฌํ•œ ์œค๋ฆฌ์  ๋”œ๋ ˆ๋งˆ๋ฅผ ์„ธ ๊ฐ€์ง€ ์ฃผ์š” ๊ด€์ ์—์„œ ๋ถ„์„ํ•œ๋‹ค: 1) ๊ณต๋ฆฌ์ฃผ์˜์  ์ ‘๊ทผ, 2) ์˜๋ฌด๋ก ์  ์ ‘๊ทผ, 3) ๋• ์œค๋ฆฌ์  ์ ‘๊ทผ. ๊ฐ ์ ‘๊ทผ๋ฒ•์˜ ์žฅ๋‹จ์ ์„ ๋น„๊ต ๋ถ„์„ํ•˜๊ณ , ์ด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ž์œจ์ฃผํ–‰ ์ฐจ๋Ÿ‰์˜ ์œค๋ฆฌ์  ์˜์‚ฌ๊ฒฐ์ • ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์ œ์•ˆํ•˜๊ณ ์ž ํ•œ๋‹ค...
296
+ """
297
+ }
298
+ return prompts.get(style, "ํฌ์ŠคํŒ… ์Šคํƒ€์ผ ํ”„๋กฌํ”„ํŠธ")
299
+
300
+ def get_style_description(style):
301
+ descriptions = {
302
+ "์นœ๊ทผํ•œ": "๋…์ž์™€ ๊ฐ€๊นŒ์šด ์นœ๊ตฌ์ฒ˜๋Ÿผ ๋Œ€ํ™”ํ•˜๋Š” ๋“ฏํ•œ ์นœ๊ทผํ•œ ์Šคํƒ€์ผ์ž…๋‹ˆ๋‹ค.",
303
+ "์ผ๋ฐ˜": "์ผ๋ฐ˜์ ์ด๊ณ  ์ค‘๋ฆฝ์ ์ธ ํ†ค์œผ๋กœ ์ •๋ณด๋ฅผ ์ „๋‹ฌํ•˜๋Š” ์Šคํƒ€์ผ์ž…๋‹ˆ๋‹ค.",
304
+ "์ „๋ฌธ์ ์ธ": "์ „๋ฌธ๊ฐ€์˜ ์‹œ๊ฐ์—์„œ ๊นŠ์ด ์žˆ๋Š” ์ •๋ณด๋ฅผ ์ „๋‹ฌํ•˜๋Š” ์Šคํƒ€์ผ์ž…๋‹ˆ๋‹ค."
305
+ }
306
+ return descriptions.get(style, "ํฌ์ŠคํŒ… ์Šคํƒ€์ผ์„ ์„ ํƒํ•˜์„ธ์š”.")
307
+
308
+ def update_prompts(category, style):
309
+ title_prompt = get_title_prompt(category)
310
+ outline_prompt = get_outline_prompt(category)
311
+ blog_post_prompt = get_blog_post_prompt(category)
312
+ style_prompt = get_style_prompt(style)
313
+ style_description = get_style_description(style)
314
+ return title_prompt, outline_prompt, blog_post_prompt, style_prompt, style_description
315
+
316
+ #PDFํŒŒ์ผ ๋งŒ๋“ค
317
+ class PDF(FPDF):
318
+ def __init__(self):
319
+ super().__init__()
320
+ current_dir = os.path.dirname(__file__)
321
+ self.add_font("NanumGothic", "", os.path.join(current_dir, "NanumGothic.ttf"), uni=True)
322
+ self.add_font("NanumGothic", "B", os.path.join(current_dir, "NanumGothicBold.ttf"), uni=True)
323
+ self.add_font("NanumGothicExtraBold", "", os.path.join(current_dir, "NanumGothicExtraBold.ttf"), uni=True)
324
+ self.add_font("NanumGothicLight", "", os.path.join(current_dir, "NanumGothicLight.ttf"), uni=True)
325
+
326
+ def header(self):
327
+ self.set_font('NanumGothic', '', 10)
328
+
329
+ def footer(self):
330
+ self.set_y(-15)
331
+ self.set_font('NanumGothic', '', 8)
332
+ self.cell(0, 10, f'Page {self.page_no()}', 0, 0, 'C')
333
+
334
+ def save_to_pdf(blog_post):
335
+ pdf = PDF()
336
+ pdf.add_page()
337
+
338
+ lines = blog_post.split('\n')
339
+ title = lines[0].strip()
340
+ content = '\n'.join(lines[1:]).strip()
341
+
342
+ filename = format_filename(title) + ".pdf"
343
+
344
+ pdf.set_font("NanumGothic", 'B', size=14)
345
+ pdf.cell(0, 10, title, ln=True, align='C')
346
+ pdf.ln(10)
347
+
348
+ pdf.set_font("NanumGothic", '', size=11)
349
+ pdf.multi_cell(0, 5, content)
350
+
351
+ print(f"Saving PDF as: {filename}")
352
+ pdf.output(filename)
353
+ return filename
354
+
355
+ def format_filename(text):
356
+ text = re.sub(r'[^\w\s-]', '', text)
357
+ return text[:50].strip()
358
+
359
+ # save_content_to_pdf ํ•จ์ˆ˜๋„ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ˆ˜์ •
360
+ def save_content_to_pdf(blog_post):
361
+ return save_to_pdf(blog_post)
362
+
363
  title = "์ •๋ณด์„ฑ ํฌ์ŠคํŒ… ์ž๋™์ƒ์„ฑ๊ธฐ(์ œ๋ชฉ์ถ”์ฒœ ํ›„ ์ž๋™)"
364
 
365
+ def update_prompts_and_description(category, style):
366
  title_prompt = get_title_prompt(category)
367
  outline_prompt = get_outline_prompt(category)
368
  blog_post_prompt = get_blog_post_prompt(category)
369
+ style_prompt = get_style_prompt(style)
370
+ style_description = get_style_description(style)
371
+ return title_prompt, outline_prompt, blog_post_prompt, style_prompt, style_description
372
 
373
  with gr.Blocks() as demo:
374
  gr.Markdown(f"# {title}")
375
 
 
376
  gr.Markdown("### 1๋‹จ๊ณ„ : ํฌ์ŠคํŒ… ์นดํ…Œ๊ณ ๋ฆฌ๋ฅผ ์ง€์ •ํ•ด์ฃผ์„ธ์š”")
377
  category = gr.Radio(choices=["์ผ๋ฐ˜", "๊ฑด๊ฐ•์ •๋ณด"], label="ํฌ์ŠคํŒ… ์นดํ…Œ๊ณ ๋ฆฌ", value="์ผ๋ฐ˜")
378
 
379
+ gr.Markdown("---\n\n")
380
+
381
+ gr.Markdown("### 2๋‹จ๊ณ„: ํฌ์ŠคํŒ… ์Šคํƒ€์ผ์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”", elem_id="step-title")
382
+ style = gr.Radio(choices=["์นœ๊ทผํ•œ", "์ผ๋ฐ˜", "์ „๋ฌธ์ ์ธ"], label="ํฌ์ŠคํŒ… ์Šคํƒ€์ผ", value="์นœ๊ทผํ•œ")
383
+ style_description = gr.Markdown(f"_{get_style_description('์นœ๊ทผํ•œ')}_", elem_id="style-description")
384
+
385
+ gr.Markdown("---\n\n")
386
+
387
  # 2๋‹จ๊ณ„
388
+ gr.Markdown("### 3๋‹จ๊ณ„ : ๋ธ”๋กœ๊ทธ ์ฃผ์ œ, ๋˜๋Š” ํ‚ค์›Œ๋“œ๋ฅผ ์ƒ์„ธํžˆ ์ž…๋ ฅํ•˜์„ธ์š”")
389
  topic = gr.Textbox(label="๋ธ”๋กœ๊ทธ ์ฃผ์ œ(์˜ˆ์‹œ: ์˜ค์ง•์–ด ๋ฌด์นจํšŒ(X), ์˜ค์ง•์–ด ๋ฌด์นจํšŒ ๋ ˆ์‹œํ”ผ(O))", placeholder="์˜ˆ์‹œ: ์—ฌํ–‰์ง€ ์ถ”์ฒœ(X), 8์›” ๊ตญ๋‚ด ์—ฌํ–‰์ง€ ์ถ”์ฒœ(O)")
390
 
391
  # 3๋‹จ๊ณ„: ์ฐธ๊ณ  ๊ธ€์„ ์œ„ํ•œ ๋ณ€์ˆ˜๋“ค ๋ฏธ๋ฆฌ ์ •์˜
 
407
 
408
  # ์ œ๋ชฉ ์ถ”์ฒœ ๋ฒ„ํŠผ
409
  title_btn = gr.Button("์ œ๋ชฉ ์ถ”์ฒœํ•˜๊ธฐ")
410
+ title_btn.click(fn=suggest_title, inputs=[category, style, topic, references1, references2, references3, title_system_message, style, title_max_tokens, title_temperature, title_top_p], outputs=[title_suggestions, title_token_output])
411
 
412
  blog_title = gr.Textbox(label="๋ธ”๋กœ๊ทธ ์ œ๋ชฉ", placeholder="๋ธ”๋กœ๊ทธ ์ œ๋ชฉ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”")
413
 
 
435
  generate_post_btn = gr.Button("๋ธ”๋กœ๊ทธ ๊ธ€ ์ƒ์„ฑํ•˜๊ธฐ")
436
  generate_post_btn.click(
437
  fn=fetch_references_and_generate_all_steps,
438
+ inputs=[category, style, topic, blog_title, outline_system_message, outline_max_tokens, outline_temperature, outline_top_p, blog_system_message, blog_max_tokens, blog_temperature, blog_top_p],
439
  outputs=[references1, references2, references3, outline_result, outline_token_output, output, token_output]
440
  )
441
 
442
+ save_pdf_btn = gr.Button("PDF๋กœ ์ €์žฅํ•˜๊ธฐ")
443
+ pdf_output = gr.File(label="์ƒ์„ฑ๋œ PDF ํŒŒ์ผ")
444
+
445
+ save_pdf_btn.click(fn=save_content_to_pdf, inputs=[output], outputs=[pdf_output])
446
+
447
+ category.change(fn=update_prompts_and_description, inputs=category, outputs=[title_system_message, outline_system_message, blog_system_message, style_description])
448
+ style.change(fn=update_prompts_and_description, inputs=category, outputs=[title_system_message, outline_system_message, blog_system_message, style_description])
449
 
450
  demo.launch()