Update app.py
Browse files
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,
|
119 |
-
full_content = analyze_info(category, topic, references1, references2, references3)
|
120 |
-
|
|
|
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,
|
125 |
-
full_content = analyze_info(category, topic, references1, references2, references3)
|
126 |
content = f"{full_content}\nTitle: {title}"
|
127 |
-
|
|
|
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,
|
132 |
-
full_content = analyze_info(category, topic, references1, references2, references3)
|
133 |
content = f"{full_content}\nTitle: {title}\nOutline: {outline}"
|
134 |
-
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
title = "์ ๋ณด์ฑ ํฌ์คํ
์๋์์ฑ๊ธฐ(์ ๋ชฉ์ถ์ฒ ํ ์๋)"
|
210 |
|
211 |
-
def
|
212 |
title_prompt = get_title_prompt(category)
|
213 |
outline_prompt = get_outline_prompt(category)
|
214 |
blog_post_prompt = get_blog_post_prompt(category)
|
215 |
-
|
|
|
|
|
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("###
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|