Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,381 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import os
|
4 |
+
import re
|
5 |
+
from huggingface_hub import InferenceClient
|
6 |
+
from fpdf import FPDF
|
7 |
+
from datetime import datetime
|
8 |
+
|
9 |
+
def create_client(model_name):
|
10 |
+
return InferenceClient(model_name, token=os.getenv("HF_TOKEN"))
|
11 |
+
|
12 |
+
client = create_client("CohereForAI/c4ai-command-r-plus")
|
13 |
+
|
14 |
+
def call_api(content, system_message, max_tokens, temperature, top_p):
|
15 |
+
messages = [{"role": "system", "content": system_message}, {"role": "user", "content": content}]
|
16 |
+
random_seed = random.randint(0, 1000000)
|
17 |
+
response = client.chat_completion(messages=messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p, seed=random_seed)
|
18 |
+
return response.choices[0].message.content
|
19 |
+
|
20 |
+
def analyze_info(category, style, topic, references1, references2, references3):
|
21 |
+
return f"์ ํํ ์นดํ
๊ณ ๋ฆฌ: {category}\n์ ํํ ํฌ์คํ
์คํ์ผ: {style}\n๋ธ๋ก๊ทธ ์ฃผ์ : {topic}\n์ฐธ๊ณ ๊ธ1: {references1}\n์ฐธ๊ณ ๊ธ2: {references2}\n์ฐธ๊ณ ๊ธ3: {references3}"
|
22 |
+
|
23 |
+
def suggest_title(category, style, topic, references1, references2, references3, category_prompt, style_prompt, max_tokens, temperature, top_p):
|
24 |
+
full_content = analyze_info(category, style, topic, references1, references2, references3)
|
25 |
+
combined_prompt = f"{category_prompt}\n\n{style_prompt}"
|
26 |
+
modified_text = call_api(full_content, combined_prompt, max_tokens, temperature, top_p)
|
27 |
+
return modified_text
|
28 |
+
|
29 |
+
def generate_outline(category, style, topic, references1, references2, references3, title, category_prompt, style_prompt, max_tokens, temperature, top_p):
|
30 |
+
full_content = analyze_info(category, style, topic, references1, references2, references3)
|
31 |
+
content = f"{full_content}\nTitle: {title}"
|
32 |
+
combined_prompt = f"{category_prompt}\n\n{style_prompt}"
|
33 |
+
modified_text = call_api(content, combined_prompt, max_tokens, temperature, top_p)
|
34 |
+
return modified_text
|
35 |
+
|
36 |
+
def generate_blog_post(category, style, topic, references1, references2, references3, title, outline, category_prompt, style_prompt, max_tokens, temperature, top_p):
|
37 |
+
full_content = analyze_info(category, style, topic, references1, references2, references3)
|
38 |
+
content = f"{full_content}\nTitle: {title}\nOutline: {outline}"
|
39 |
+
combined_prompt = f"{category_prompt}\n\n{style_prompt}"
|
40 |
+
modified_text = call_api(content, combined_prompt, max_tokens, temperature, top_p)
|
41 |
+
formatted_text = modified_text.replace('\n', '\n\n')
|
42 |
+
return formatted_text
|
43 |
+
|
44 |
+
def get_title_prompt(category):
|
45 |
+
if (category == "๊ณ ๊ฐ๋ฐ์ํ"):
|
46 |
+
return """
|
47 |
+
#๋ธ๋ก๊ทธ ์ ๋ชฉ ์์ฑ ๊ท์น(์ํ๋ฆฌ๋ทฐ_๊ณ ๊ฐ๋ฐ์ํ)
|
48 |
+
##[๊ธฐ๋ณธ๊ท์น]
|
49 |
+
1. ๋ฐ๋์ ํ๊ตญ์ด(ํ๊ธ)๋ก ์์ฑํ๋ผ.
|
50 |
+
2. ๋๋ ๊ฐ์ฅ ์ฃผ๋ชฉ๋ฐ๋ ๋ง์ผํฐ์ด๋ฉฐ ๋ธ๋ก๊ทธ ๋ง์ผํ
์ ๋ฌธ๊ฐ์ด๋ค.
|
51 |
+
3. ํนํ ๋๋ '๊ณ ๊ฐ๋ฐ์ ์ํ๋ฆฌ๋ทฐ' ์ ๋ฌธ ๋ธ๋ก๊ทธ ๋ง์ผํฐ์ด๋ค.
|
52 |
+
4. ์ํ ๋ฆฌ๋ทฐ๋ฅผ ์์ฑํ๋, ๊ณ ๊ฐ์ ์ค์ ๋ฐ์์ด ํฌํจ๋ ๊ธ์ ์์ฑํ๋ผ.
|
53 |
+
5. ์ ํ๋ ํฌ์คํ
์คํ์ผ์ ์ ์ฉํ์ฌ ๊ธ์ ์์ฑํ๋ผ.
|
54 |
+
|
55 |
+
##[๋ธ๋ก๊ทธ ์ ๋ชฉ ์์ฑ ๊ท์น]
|
56 |
+
1. ์ํ๋ฆฌ๋ทฐ ๋ธ๋ก๊ทธ ํฌ์คํ
์ค ๊ณ ๊ฐ์ ์ค์ ๋ฐ์์ ํนํ๋ ์ ๋ชฉ์ ์์ฑํ๋ผ.
|
57 |
+
2. ์ฐธ๊ณ ๊ธ์ ๋ฐํ์ผ๋ก ๋ธ๋ก๊ทธ ์ ๋ชฉ 10๊ฐ๋ฅผ ์์ฑํ๊ณ ์ ๋ชฉ 10๊ฐ๋ง ์ถ๋ ฅํ๋ผ.
|
58 |
+
3. ์ ๋ชฉ์ 40์ ์ด๋ด๋ก ์์ฑํ๋ผ.
|
59 |
+
4. ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ๋ธ๋ก๊ทธ ์ฃผ์ , ํต์ฌํค์๋(Topic), ์ํ๋ช
์ด ๋ฌธ์ฅ ์์ชฝ์ ๋ค์ด๊ฐ๋๋ก ์ ๋ชฉ์ ์์ฑํ๋ผ.
|
60 |
+
5. '์ฟ ํก'์ด๋ ๋จ์ด๋ ์ ๋ชฉ์ ํํํ์ง ๋ง ๊ฒ.
|
61 |
+
"""
|
62 |
+
|
63 |
+
def get_outline_prompt(category):
|
64 |
+
if (category == "๊ณ ๊ฐ๋ฐ์ํ"):
|
65 |
+
return """
|
66 |
+
#๋ธ๋ก๊ทธ ์์ฃผ์ (Subtitle) ์์๋ผ์ธ ์์ฑ ๊ท์น
|
67 |
+
##[๊ธฐ๋ณธ๊ท์น]
|
68 |
+
1. ๋ฐ๋์ ํ๊ตญ์ด(ํ๊ธ)๋ก ์์ฑํ๋ผ.
|
69 |
+
2. ๋๋ ๊ฐ์ฅ ์ฃผ๋ชฉ๋ฐ๋ ๋ง์ผํฐ์ด๋ฉฐ ๋ธ๋ก๊ทธ ๋ง์ผํ
์ ๋ฌธ๊ฐ์ด๋ค.
|
70 |
+
3. ํนํ ๋๋ '๊ณ ๊ฐ๋ฐ์ ์ํ๋ฆฌ๋ทฐ' ์ ๋ฌธ ๋ธ๋ก๊ทธ ๋ง์ผํฐ์ด๋ค.
|
71 |
+
4. ์ํ ๋ฆฌ๋ทฐ๋ฅผ ์์ฑํ๋, ๊ณ ๊ฐ์ ์ค์ ๋ฐ์์ด ํฌํจ๋ ๊ธ์ ์์ฑํ๋ผ.
|
72 |
+
5. ์ ํ๋ ํฌ์คํ
์คํ์ผ์ ์ ์ฉํ์ฌ ๊ธ์ ์์ฑํ๋ผ.
|
73 |
+
|
74 |
+
##[์์ฃผ์ ์์ฑ๊ท์น]
|
75 |
+
1. ๋ธ๋ก๊ทธ ๊ธ์ ์์ฑํ๊ธฐ ์ํ ์์ฃผ์ ๋ฅผ ์์ฑํ๋ผ.
|
76 |
+
2. ๋ฐ๋์ ์ํ์ ๊ณ ๊ฐ์ ์ค์ ๋ฐ์์ด ํฌํจ๋ ์ฃผ์ ๋ก๋ง ์์ฃผ์ ๋ฅผ ์์ฑํ๋ผ.
|
77 |
+
3. ์์ ๋ชฉ์ผ๋ก ์ฌ์ฉํ ์ ์๋๋ก 30์ ์ด๋ด๋ก ์์ฑํ๋ผ.
|
78 |
+
4. ๋
์๊ฐ ์ป๊ณ ์ ํ๋ ํฅ๋ฏธ๋ก์ด ์ ๋ณด์ ๊ณ ๊ฐ์ ์ค์ ๋ฐ์์ ์ ๊ณตํ๋๋ก ์์ฃผ์ ๋ฅผ ์์ฑํ๋ผ.
|
79 |
+
5. ๋ฐ๋์ [์์ฃผ์ ๊ตฌ์ฑ]์ ๋ง๊ฒ ์ถ๋ ฅํ๋ผ.
|
80 |
+
6. ์ํ๋ช
์ ์์ฃผ์ ์ ํฌํจํ์ง ๋ง ๊ฒ.
|
81 |
+
|
82 |
+
##[์์ฃผ์ ๊ตฌ์ฑ]
|
83 |
+
1. ๋ฐ๋์ [๋์
๋ถ] - 1๊ฐ, [๋ณธ๋ก 1~5] - 5๊ฐ, [๊ฒฐ๋ก ] - 1๊ฐ๋ก ๊ตฌ์ฑํ์ฌ ์ถ๋ ฅํ๋ผ.
|
84 |
+
2. ๋ฐ๋์ [๋์
๋ถ]์ [๊ฒฐ๋ก ]์ ์ ๋ชฉ์ด ์ค๋ณต๋์ง ์๋๋ก ์์ฑํ๋ผ.
|
85 |
+
3. [๋์
๋ถ]์๋ ๊ณ ๊ฐ์ ์ค์ ๋ฆฌ๋ทฐ๋ฅผ ๋ถ์ํ์ฌ ๊ณต๊ฐ, ๋ฌธ์ ์ ๊ธฐ, ๊ตฌ๋งคํฌ์ธํธ ๋ฑ์ ์ ์ํ๋ผ.
|
86 |
+
"""
|
87 |
+
|
88 |
+
def get_blog_post_prompt(category):
|
89 |
+
if (category == "๊ณ ๊ฐ๋ฐ์ํ"):
|
90 |
+
return """
|
91 |
+
#๋ธ๋ก๊ทธ ํ
์คํธ ์์ฑ ๊ท์น(์ํ๋ฆฌ๋ทฐ_๊ณ ๊ฐ๋ฐ์ํ)
|
92 |
+
##[๊ธฐ๋ณธ๊ท์น]
|
93 |
+
1. ๋ฐ๋์ ํ๊ตญ์ด(ํ๊ธ)๋ก ์์ฑํ๋ผ.
|
94 |
+
2. ๋๋ ๊ฐ์ฅ ์ฃผ๋ชฉ๋ฐ๋ ๋ง์ผํฐ์ด๋ฉฐ ๋ธ๋ก๊ทธ ๋ง์ผํ
์ ๋ฌธ๊ฐ์ด๋ค.
|
95 |
+
3. ํนํ ๋๋ '๊ณ ๊ฐ๋ฐ์ ์ํ๋ฆฌ๋ทฐ' ์ ๋ฌธ ๋ธ๋ก๊ทธ ๋ง์ผํฐ์ด๋ค.
|
96 |
+
4. ์ํ ๋ฆฌ๋ทฐ๋ฅผ ์์ฑํ๋, ๊ณ ๊ฐ์ ์ค์ ๋ฐ์์ด ํฌํจ๋ ๊ธ์ ์์ฑํ๋ผ.
|
97 |
+
5. ์ ํ๋ ํฌ์คํ
์คํ์ผ์ ์ ์ฉํ์ฌ ๊ธ์ ์์ฑํ๋ผ.
|
98 |
+
|
99 |
+
##๊ธฐ๋ฅ์ง์คํ ์ํ๋ฆฌ๋ทฐ ์์ฑ๊ท์น]
|
100 |
+
1. ๋ฐ๋์ ์
๋ ฅ๋ [์์ฃผ์ ]์ ๋ง๊ฒ ํ
์คํธ๋ฅผ ์์ฑํ๋ผ.
|
101 |
+
2. ๋ธ๋ก๊ทธ์ฃผ์ ์ ์ฐธ๊ณ ๊ธ์ ๋ฐํ์ผ๋ก ์ํ๋ช
์ ํ์
ํ์ฌ ๊ธฐ์ตํ๊ณ , ์์ฃผ์ ์์ ๋ฐ๋์ ์ํ๋ช
์ ์ต๋ 1ํ๋ง ์ถ๋ ฅ๋๊ฒํ๋ผ.
|
102 |
+
3. ์์ฃผ์ ๋ณ ๊ฐ๊ฐ 400์ ์ด์์ผ๋ก ์์ฑํ๊ณ , ๋ฐ๋์ ์ ์ฒด๊ธ์ด 2200์ ์ด์ ๋๋๋ก ์์ฑํ๋ผ.
|
103 |
+
4. ์ ์ฒด ๋งฅ๋ฝ์ ์ดํดํ๊ณ ๋ฌธ์ฅ์ ์ผ๊ด์ฑ์ ์ ์งํ๋, ๋ด์ฉ์ด ์ค๋ณต๋์ง ์๊ฒ ์์ฑํ๋ผ.
|
104 |
+
5. ์ ๋๋ก ์ฐธ๊ณ ๊ธ์ ํ๋ฌธ์ฅ ์ด์ ๊ทธ๋๋ก ์ถ๋ ฅํ์ง ๋ง ๊ฒ.
|
105 |
+
6. ์ํ์ ๋ํ ๋ถ์(์์น๋ฅผ ํฌํจ), ๊ธฐ๋ฅ๊ณผ ์ฌ์ฉ๋ฒ๋ฑ์ ์ ๋ณด๋ฅผ ์์ฑํ๊ณ ๊ทธ์ ๋ํ ๊ณ ๊ฐ์ ์ค์ ๋ฐ์์ ํฌํจํ์ฌ ๋ฆฌ๋ทฐ๋ฅผ ์์ฑํ๋ผ.
|
106 |
+
7. ๋ด์ฉ์ ๊ธ์ ์ ์ผ๋ก ์์ฑํ๋, ๊ณ ๊ฐ์ ์ค์ ๋ฐ์์ด ๋๋ณด์ด๋๋ก ์์ฑํ๋ผ.
|
107 |
+
8. ๊ณ ๊ฐ์ ์ค์ ๋ฆฌ๋ทฐ๋ฅผ ๋ฐํ์ผ๋ก ํฌ์คํ
์คํ์ผ์ ๋ง๋ ์ํฉ์ ์ฐ์ถํ๋ผ.
|
108 |
+
9. ๊ณ ๊ฐ์ ์ค์ ๋ฆฌ๋ทฐ๋ฅผ ๋ฌธ์ฅ์ ๋ฐ์ํ ๋๋ '๊ตฌ๋งค์์ ๋ฆฌ๋ทฐ', '๊ณ ๊ฐ์ ๋ฆฌ๋ทฐ', '์ฌ์ฉ์ ๋ฆฌ๋ทฐ' ๋ฑ์ ๋ค์ํ ํํ์ ์ฌ์ฉํ๋ผ.
|
109 |
+
|
110 |
+
##[์ ์ธ ๊ท์น]
|
111 |
+
1. ๋ฐ๋์ ์ฐธ๊ณ ๊ธ์ ๋งํฌ(URL)๋ ์ ์ธํ๋ผ.
|
112 |
+
2. ์ฐธ๊ณ ๊ธ์์ '๋งํฌ๋ฅผ ํ์ธํด์ฃผ์ธ์'์ ๊ฐ์ ๋งํฌ ์ด๋์ ๋ฌธ๊ตฌ๋ ์ ์ธํ๋ผ.
|
113 |
+
3. ์ฐธ๊ณ ๊ธ์ ์๋ ์์ฑ์, ํ์, ์ ํ๋ฒ, ๊ธฐ์(Writer, speaker, YouTuber, reporter)์ ์ด๋ฆ, ์ ์นญ, ๋๋ค์(Name, Nkickname)์ ๋ฐ๋์ ์ ์ธํ๋ผ.
|
114 |
+
4. '์
์ฒด๋ก ๋ถํฐ ์ ๊ณต ๋ฐ์์ ์์ฑ', '์ฟ ํก ํํธ๋์ค'๋ฑ์ ํํ์ ๋ฐ๋์ ์ ์ธํ๋ผ.
|
115 |
+
"""
|
116 |
+
|
117 |
+
def get_style_prompt(style):
|
118 |
+
prompts = {
|
119 |
+
"์น๊ทผํ": """
|
120 |
+
#์น๊ทผํ ๋ธ๋ก๊ทธ ํฌ์คํ
์คํ์ผ ๊ฐ์ด๋
|
121 |
+
1. ํค๊ณผ ์ด์กฐ
|
122 |
+
- ๋ํํ๋ฏ ํธ์ํ๊ณ ์น๊ทผํ ๋งํฌ ์ฌ์ฉ
|
123 |
+
- ๋
์๋ฅผ "์ฌ๋ฌ๋ถ" ๋๋ "๋
์๋๋ค"๋ก ์ง์นญ
|
124 |
+
- ์ ์ ํ ์ด๋ชจ์ง๋ฅผ sparseํ๊ฒ ์ฌ์ฉํ์ฌ ์น๊ทผ๊ฐ ํํ
|
125 |
+
2. ๋ฌธ์ฅ ๋ฐ ๋ด์ฉ ๊ตฌ์ฑ
|
126 |
+
- ์งง๊ณ ๊ฐ๊ฒฐํ ๋ฌธ์ฅ ์์ฃผ๋ก ์์ฑ
|
127 |
+
- ๊ตฌ์ด์ฒด ํํ ์ฌ์ฉ (์: "~ํ์ด์", "~์ธ ๊ฒ ๊ฐ์์")
|
128 |
+
- '~๋๋ค', '~ํ์ฃ '๋ ์ฌ์ฉํ์ง ๋ง ๊ฒ.
|
129 |
+
- ๊ฐ์ธ์ ์ธ ๊ฒฝํ์ด๋ ์ผํ๋ก ์์
|
130 |
+
- ์ค์ํ์์ ์ฝ๊ฒ ์ ์ฉํ ์ ์๋ ํ ์ ๊ณต
|
131 |
+
- ๋
์์ ๊ณต๊ฐ์ ์ป์ ์ ์๋ ์ฌ๋ก ํฌํจ
|
132 |
+
3. ์ฉ์ด ๋ฐ ์ค๋ช
๋ฐฉ์
|
133 |
+
- ์ ๋ฌธ ์ฉ์ด ๋์ ์ฌ์ด ๋จ์ด๋ก ํ์ด์ ์ค๋ช
|
134 |
+
- ๋น์ ๋ ์์ ๋ฅผ ํ์ฉํ์ฌ ๋ณต์กํ ๊ฐ๋
์ค๋ช
|
135 |
+
- ์์ฌ์๋ฌธ๋ฌธ ํ์ฉํ์ฌ ๋
์์ ์ํตํ๋ ๋๋ ์ฃผ๊ธฐ
|
136 |
+
4. ๋
์์์ ์ํธ์์ฉ
|
137 |
+
- ๋
์์ ์๊ฒฌ์ ๋ฌผ์ด๋ณด๋ ์ง๋ฌธ ํฌํจ
|
138 |
+
- ๋๊ธ ๋ฌ๊ธฐ๋ฅผ ๋
๋ คํ๋ ๋ฌธ๊ตฌ ์ฌ์ฉ
|
139 |
+
5. ์ด๋ชจ์ง ํ์ฉ
|
140 |
+
- ์ฃผ์ ํฌ์ธํธ๋ ์๋ก์ด ์น์
์ ์์ํ ๋๋ง ๊ด๋ จ ์ด๋ชจ์ง ์ฌ์ฉ
|
141 |
+
- ์ ์ฒด ๊ธ์์ 3-5๊ฐ ์ ๋์ ์ด๋ชจ์ง๋ง ์ฌ์ฉํ์ฌ ๊ณผ๋ํ์ง ์๊ฒ ์ ์ง
|
142 |
+
6. ๋ง๋ฌด๋ฆฌ
|
143 |
+
- ์น๊ทผํ๊ณ ๊ฒฉ๋ คํ๋ ํค์ผ๋ก ๋ง๋ฌด๋ฆฌ
|
144 |
+
- ๋ค์ ํฌ์คํ
์ ๋ํ ๊ธฐ๋๊ฐ ์ ๋ฐ
|
145 |
+
์ฃผ์์ฌํญ: ๋๋ฌด ๊ฐ๋ฒผ์ด ํค์ ์ง์ํ๊ณ , ์ฃผ์ ์ ์ค์์ฑ์ ํด์น์ง ์๋ ์ ์์ ์น๊ทผํจ ์ ์ง
|
146 |
+
""",
|
147 |
+
"์ผ๋ฐ": """
|
148 |
+
#์ผ๋ฐ์ ์ธ ๋ธ๋ก๊ทธ ํฌ์คํ
์คํ์ผ ๊ฐ์ด๋
|
149 |
+
1. ํค๊ณผ ์ด์กฐ
|
150 |
+
- ์ค๋ฆฝ์ ์ด๊ณ ๊ฐ๊ด์ ์ธ ํค ์ ์ง
|
151 |
+
- ์ ์ ํ ์กด๋๋ง ์ฌ์ฉ (์: "~ํฉ๋๋ค", "~์
๋๋ค")
|
152 |
+
|
153 |
+
2. ๋ด์ฉ ๊ตฌ์กฐ ๋ฐ ์ ๊ฐ
|
154 |
+
- ๋ช
ํํ ์ฃผ์ ์ ์๋ก ์์
|
155 |
+
- ๋
ผ๋ฆฌ์ ์ธ ์์๋ก ์ ๋ณด ์ ๊ฐ
|
156 |
+
- ์ฃผ์ ํฌ์ธํธ๋ฅผ ๊ฐ์กฐํ๋ ์์ ๋ชฉ ํ์ฉ
|
157 |
+
- ์ ์ ํ ๊ธธ์ด์ ๋จ๋ฝ์ผ๋ก ๊ตฌ์ฑ
|
158 |
+
|
159 |
+
3. ์ฉ์ด ๋ฐ ์ค๋ช
๋ฐฉ์
|
160 |
+
- ์ผ๋ฐ์ ์ผ๋ก ์ดํดํ๊ธฐ ์ฌ์ด ์ฉ์ด ์ ํ
|
161 |
+
- ํ์์ ๊ฐ๋จํ ์ค๋ช
์ถ๊ฐ
|
162 |
+
- ๊ฐ๊ด์ ์ธ ์ ๋ณด ์ ๊ณต์ ์ค์
|
163 |
+
|
164 |
+
4. ํ
์คํธ ๊ตฌ์กฐํ
|
165 |
+
- ๋ถ๋ฆฟ ํฌ์ธํธ๋ ๋ฒํธ ๋งค๊ธฐ๊ธฐ๋ฅผ ํ์ฉํ์ฌ ์ ๋ณด ๊ตฌ์กฐํ
|
166 |
+
- ์ค์ํ ์ ๋ณด๋ ๊ตต์ ๊ธ์จ๋ ๊ธฐ์ธ์๊ผด๋ก ๊ฐ์กฐ
|
167 |
+
|
168 |
+
5. ๋
์ ์ํธ์์ฉ
|
169 |
+
- ์ ์ ํ ๋
์์ ์๊ฐ์ ๋ฌป๋ ์ง๋ฌธ ํฌํจ
|
170 |
+
- ์ถ๊ฐ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์๋ ํค์๋ ์ ์
|
171 |
+
|
172 |
+
6. ๋ง๋ฌด๋ฆฌ
|
173 |
+
- ์ฃผ์ ๋ด์ฉ ๊ฐ๋จํ ์์ฝ
|
174 |
+
- ์ถ๊ฐ ์ ๋ณด์ ๋ํ ์๋ด ์ ๊ณต
|
175 |
+
|
176 |
+
์ฃผ์์ฌํญ: ๋๋ฌด ๋ฑ๋ฑํ๊ฑฐ๋ ์ง๋ฃจํ์ง ์๋๋ก ๊ท ํ ์ ์ง
|
177 |
+
""",
|
178 |
+
"์ ๋ฌธ์ ์ธ": """
|
179 |
+
#์ ๋ฌธ๏ฟฝ๏ฟฝ์ธ ๋ธ๋ก๊ทธ ํฌ์คํ
์คํ์ผ ๊ฐ์ด๋
|
180 |
+
|
181 |
+
1. ํค๊ณผ ๊ตฌ์กฐ
|
182 |
+
- ๊ณต์์ ์ด๊ณ ํ์ ์ ์ธ ํค ์ฌ์ฉ
|
183 |
+
- ๊ฐ๊ด์ ์ด๊ณ ๋ถ์์ ์ธ ์ ๊ทผ ์ ์ง
|
184 |
+
- ๋ช
ํํ ์๋ก , ๋ณธ๋ก , ๊ฒฐ๋ก ๊ตฌ์กฐ
|
185 |
+
- ์ฒด๊ณ์ ์ธ ๋
ผ์ ์ ๊ฐ
|
186 |
+
- ์ธ๋ถ ์น์
์ ์ํ ๋ช
ํํ ์์ ๋ชฉ ์ฌ์ฉ
|
187 |
+
|
188 |
+
2. ๋ด์ฉ ๊ตฌ์ฑ ๋ฐ ์ ๊ฐ
|
189 |
+
- ๋ณต์กํ ๊ฐ๋
์ ์ ํํ ์ ๋ฌํ ์ ์๋ ๋ฌธ์ฅ ๊ตฌ์กฐ ์ฌ์ฉ
|
190 |
+
- ๋
ผ๋ฆฌ์ ์ฐ๊ฒฐ์ ์ํ ์ ํ์ด ํ์ฉ
|
191 |
+
- ํด๋น ๋ถ์ผ์ ์ ๋ฌธ ์ฉ์ด ์ ๊ทน ํ์ฉ (ํ์์ ๊ฐ๋ตํ ์ค๋ช
์ ๊ณต)
|
192 |
+
- ์ฌ์ธต์ ์ธ ๋ถ์๊ณผ ๋นํ์ ์ฌ๊ณ ์ ๊ฐ
|
193 |
+
- ๋ค์ํ ๊ด์ ์ ์ ๋ฐ ๋น๊ต
|
194 |
+
|
195 |
+
3. ๋ฐ์ดํฐ ๋ฐ ๊ทผ๊ฑฐ ํ์ฉ
|
196 |
+
- ํต๊ณ, ์ฐ๊ตฌ ๊ฒฐ๊ณผ, ์ ๋ฌธ๊ฐ ์๊ฒฌ ๋ฑ ์ ๋ขฐํ ์ ์๋ ์ถ์ฒ ์ธ์ฉ
|
197 |
+
- ํ์์ ๊ฐ์ฃผ๋ ์ฐธ๊ณ ๋ฌธํ ๋ชฉ๋ก ํฌํจ
|
198 |
+
- ์์น ๋ฐ์ดํฐ๋ ํ
์คํธ๋ก ๋ช
ํํ ์ค๋ช
|
199 |
+
|
200 |
+
4. ํ
์คํธ ๊ตฌ์กฐํ
|
201 |
+
- ๋
ผ๋ฆฌ์ ๊ตฌ์กฐ๋ฅผ ๊ฐ์กฐํ๊ธฐ ์ํด ๋ฒํธ ๋งค๊ธฐ๊ธฐ ์ฌ์ฉ
|
202 |
+
- ํต์ฌ ๊ฐ๋
์ด๋ ์ฉ์ด๋ ๊ธฐ์ธ์๊ผด๋ก ๊ฐ์กฐ
|
203 |
+
- ๊ธด ์ธ์ฉ๋ฌธ์ ๋ค์ฌ์ฐ๊ธฐ๋ก ๊ตฌ๋ถ
|
204 |
+
|
205 |
+
5. ๋ง๋ฌด๋ฆฌ
|
206 |
+
- ํต์ฌ ๋
ผ์ ์ฌ๊ฐ์กฐ
|
207 |
+
- ํฅํ ์ฐ๊ตฌ ๋ฐฉํฅ์ด๋ ์ค๋ฌด์ ํจ์ ์ ์
|
208 |
+
|
209 |
+
์ฃผ์์ฌํญ: ์ ๋ฌธ์ฑ์ ์ ์งํ๋, ์์ ํ ์ดํดํ๊ธฐ ์ด๋ ค์ด ์์ค์ ์ง์
|
210 |
+
"""
|
211 |
+
}
|
212 |
+
return prompts.get(style, "ํฌ์คํ
์คํ์ผ ํ๋กฌํํธ")
|
213 |
+
|
214 |
+
def get_style_description(style):
|
215 |
+
descriptions = {
|
216 |
+
"์น๊ทผํ": "๋
์์ ๊ฐ๊น์ด ์น๊ตฌ์ฒ๋ผ ๋ํํ๋ ๋ฏํ ์น๊ทผํ ์คํ์ผ์
๋๋ค.",
|
217 |
+
"์ผ๋ฐ": "์ผ๋ฐ์ ์ด๊ณ ์ค๋ฆฝ์ ์ธ ํค์ผ๋ก ์ ๋ณด๋ฅผ ์ ๋ฌํ๋ ์คํ์ผ์
๋๋ค.",
|
218 |
+
"์ ๋ฌธ์ ์ธ": "์ ๋ฌธ๊ฐ์ ์๊ฐ์์ ๊น์ด ์๋ ์ ๋ณด๋ฅผ ์ ๋ฌํ๋ ์คํ์ผ์
๋๋ค."
|
219 |
+
}
|
220 |
+
return descriptions.get(style, "ํฌ์คํ
์คํ์ผ์ ์ ํํ์ธ์.")
|
221 |
+
|
222 |
+
def update_prompts(category, style):
|
223 |
+
title_prompt = get_title_prompt(category)
|
224 |
+
outline_prompt = get_outline_prompt(category)
|
225 |
+
blog_post_prompt = get_blog_post_prompt(category)
|
226 |
+
style_prompt = get_style_prompt(style)
|
227 |
+
style_description = get_style_description(style)
|
228 |
+
return title_prompt, outline_prompt, blog_post_prompt, style_prompt, style_description
|
229 |
+
|
230 |
+
class PDF(FPDF):
|
231 |
+
def __init__(self):
|
232 |
+
super().__init__()
|
233 |
+
current_dir = os.path.dirname(__file__)
|
234 |
+
self.add_font("NanumGothic", "", os.path.join(current_dir, "NanumGothic.ttf"))
|
235 |
+
self.add_font("NanumGothic", "B", os.path.join(current_dir, "NanumGothicBold.ttf"))
|
236 |
+
self.add_font("NanumGothicExtraBold", "", os.path.join(current_dir, "NanumGothicExtraBold.ttf"))
|
237 |
+
self.add_font("NanumGothicLight", "", os.path.join(current_dir, "NanumGothicLight.ttf"))
|
238 |
+
|
239 |
+
def header(self):
|
240 |
+
self.set_font('NanumGothic', '', 10)
|
241 |
+
|
242 |
+
def footer(self):
|
243 |
+
self.set_y(-15)
|
244 |
+
self.set_font('NanumGothic', '', 8)
|
245 |
+
self.cell(0, 10, f'Page {self.page_no()}', 0, 0, 'C')
|
246 |
+
|
247 |
+
def format_filename(text):
|
248 |
+
text = re.sub(r'[^\w\s-]', '', text)
|
249 |
+
return text[:50].strip()
|
250 |
+
|
251 |
+
def extract_first_recommended_title(blog_post):
|
252 |
+
match = re.search(r'## ์ถ์ฒ ์ ๋ชฉ\s*\n\s*(?:\n\s*)*\d+\.\s*(.*?)\s*(?:\n|$)', blog_post, re.DOTALL)
|
253 |
+
if match:
|
254 |
+
title = match.group(1).strip()
|
255 |
+
print(f"Extracted title: {title}")
|
256 |
+
return title
|
257 |
+
print("No title found")
|
258 |
+
return "๋ธ๋ก๊ทธ_๊ธ"
|
259 |
+
|
260 |
+
def save_to_pdf(blog_post):
|
261 |
+
pdf = PDF()
|
262 |
+
|
263 |
+
pdf.add_page()
|
264 |
+
pdf.set_font("NanumGothic", 'B', size=14)
|
265 |
+
pdf.cell(0, 10, "๋ธ๋ก๊ทธ ๊ธ", ln=True, align='C')
|
266 |
+
pdf.ln(10)
|
267 |
+
pdf.set_font("NanumGothic", '', size=11)
|
268 |
+
pdf.multi_cell(0, 5, blog_post)
|
269 |
+
|
270 |
+
title = extract_first_recommended_title(blog_post)
|
271 |
+
filename = format_filename(title) + ".pdf"
|
272 |
+
print(f"Saving PDF as: {filename}")
|
273 |
+
pdf.output(filename)
|
274 |
+
return filename
|
275 |
+
|
276 |
+
def save_content_to_pdf(blog_post):
|
277 |
+
filename = save_to_pdf(blog_post)
|
278 |
+
return filename
|
279 |
+
|
280 |
+
title = "์ํ๋ฆฌ๋ทฐ ๊ณ ๊ฐ๋ฐ์ํ_์๋"
|
281 |
+
|
282 |
+
with gr.Blocks() as demo:
|
283 |
+
gr.Markdown(f"# {title}")
|
284 |
+
|
285 |
+
gr.Markdown("### 1๋จ๊ณ: ํฌ์คํ
์นดํ
๊ณ ๋ฆฌ๋ฅผ ์ง์ ํด์ฃผ์ธ์", elem_id="step-title")
|
286 |
+
category = gr.Radio(choices=["๊ณ ๊ฐ๋ฐ์ํ"], label="ํฌ์คํ
์นดํ
๊ณ ๋ฆฌ", value="๊ณ ๊ฐ๋ฐ์ํ")
|
287 |
+
|
288 |
+
gr.Markdown("---\n\n")
|
289 |
+
|
290 |
+
gr.Markdown("### 2๋จ๊ณ: ํฌ์คํ
์คํ์ผ์ ์ ํํด์ฃผ์ธ์", elem_id="step-title")
|
291 |
+
style = gr.Radio(choices=["์น๊ทผํ", "์ผ๋ฐ", "์ ๋ฌธ์ ์ธ"], label="ํฌ์คํ
์คํ์ผ", value="์น๊ทผํ")
|
292 |
+
style_description = gr.Markdown(f"_{get_style_description('์น๊ทผํ')}_", elem_id="style-description")
|
293 |
+
|
294 |
+
gr.Markdown("---\n\n")
|
295 |
+
|
296 |
+
gr.Markdown("### 3๋จ๊ณ: ๋ธ๋ก๊ทธ ์ฃผ์ , ๋๋ ํค์๋๋ฅผ ์์ธํ ์
๋ ฅํ์ธ์", elem_id="step-title")
|
297 |
+
topic = gr.Textbox(label="๋ธ๋ก๊ทธ ์ฃผ์ (์์: ์ค์ง์ด ๋ฌด์นจํ(X), ์ค์ง์ด ๋ฌด์นจํ ๋ ์ํผ(O))", placeholder="์์: ์ฌํ์ง ์ถ์ฒ(X), 8์ ๊ตญ๋ด ์ฌํ์ง ์ถ์ฒ(O)")
|
298 |
+
|
299 |
+
gr.Markdown("---\n\n")
|
300 |
+
|
301 |
+
gr.Markdown("### 4๋จ๊ณ: ์ฐธ๊ณ ๊ธ์ ์
๋ ฅํ์ธ์", elem_id="step-title")
|
302 |
+
references1 = gr.Textbox(label="์ฐธ๊ณ ๊ธ 1", placeholder="์ฐธ๊ณ ํ ๋ธ๋ก๊ทธ ํฌ์คํ
๊ธ์ ๋ณต์ฌํ์ฌ ๋ถ์ฌ๋ฃ์ผ์ธ์", lines=10, visible=True)
|
303 |
+
references2 = gr.Textbox(label="์ฐธ๊ณ ๊ธ 2", placeholder="์ฐธ๊ณ ํ ๋ธ๋ก๊ทธ ํฌ์คํ
๊ธ์ ๋ณต์ฌํ์ฌ ๋ถ์ฌ๋ฃ์ผ์ธ์", lines=10, visible=True)
|
304 |
+
references3 = gr.Textbox(label="์ฐธ๊ณ ๊ธ 3", placeholder="์ฐธ๊ณ ํ ๋ธ๋ก๊ทธ ํฌ์คํ
๊ธ์ ๋ณต์ฌํ์ฌ ๋ถ์ฌ๋ฃ์ผ์ธ์", lines=10, visible=True)
|
305 |
+
|
306 |
+
gr.Markdown("---\n\n")
|
307 |
+
|
308 |
+
gr.Markdown("### 5๋จ๊ณ: ๋ธ๋ก๊ทธ ์ ๋ชฉ์ ์
๋ ฅํ์ธ์", elem_id="step-title")
|
309 |
+
|
310 |
+
with gr.Accordion("์ ๋ชฉ ์ค์ ", visible=True):
|
311 |
+
title_system_message = gr.Textbox(label="์นดํ
๊ณ ๋ฆฌ ํ๋กฌํํธ", value=get_title_prompt("๊ณ ๊ฐ๋ฐ์ํ"), lines=15, visible=True)
|
312 |
+
title_max_tokens = gr.Slider(label="Max Tokens", minimum=1000, maximum=8000, value=5000, step=1000)
|
313 |
+
title_temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, value=0.8, step=0.1)
|
314 |
+
title_top_p = gr.Slider(label="Top P", minimum=0.1, maximum=1.0, value=0.95, step=0.05)
|
315 |
+
|
316 |
+
title_btn = gr.Button("์ ๋ชฉ ์ถ์ฒํ๊ธฐ")
|
317 |
+
title_suggestions = gr.Textbox(label="์ ๋ชฉ ์ถ์ฒ", lines=10)
|
318 |
+
|
319 |
+
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])
|
320 |
+
gr.HTML("<span style='color: grey;'>[์ ๋ชฉ ์ถ์ฒ ํญ๋ชฉ์ ์ฐธ๊ณ ํ์ฌ ํ๋๋ฅผ ๋ณต์ฌํ์ฌ ์ฌ์ฉํ์
๋ ๋ฉ๋๋ค.]</span>")
|
321 |
+
blog_title = gr.Textbox(label="๋ธ๋ก๊ทธ ์ ๋ชฉ", placeholder="๋ธ๋ก๊ทธ ์ ๋ชฉ์ ์
๋ ฅํด์ฃผ์ธ์")
|
322 |
+
|
323 |
+
gr.Markdown("---\n\n")
|
324 |
+
|
325 |
+
gr.Markdown("### 6๋จ๊ณ: ์์๋ผ์ธ์ ์์ฑํด์ฃผ์ธ์", elem_id="step-title")
|
326 |
+
gr.HTML("<span style='color: grey;'>[์์๋ผ์ธ์์ ๋์จ ๊ฒฐ๊ณผ๋ฅผ ์์ ํด์ ์ฌ์ฉํด์ฃผ์ธ์]</span>")
|
327 |
+
|
328 |
+
with gr.Accordion("์์๋ผ์ธ ์ค์ ", visible=True):
|
329 |
+
outline_system_message = gr.Textbox(label="์นดํ
๊ณ ๋ฆฌ ํ๋กฌํํธ", value=get_outline_prompt("๊ณ ๊ฐ๋ฐ์ํ"), lines=20, visible=True)
|
330 |
+
outline_max_tokens = gr.Slider(label="Max Tokens", minimum=1000, maximum=8000, value=6000, step=1000)
|
331 |
+
outline_temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, value=0.8, step=0.1)
|
332 |
+
outline_top_p = gr.Slider(label="Top P", minimum=0.1, maximum=1.0, value=0.95, step=0.05)
|
333 |
+
|
334 |
+
outline_generate_btn = gr.Button("์์๋ผ์ธ ์์ฑํ๊ธฐ")
|
335 |
+
outline_result = gr.Textbox(label="์์๋ผ์ธ ๊ฒฐ๊ณผ", lines=15)
|
336 |
+
outline_input = gr.Textbox(label="์์ฑํ ์์๋ผ์ธ์ ์
๋ ฅํด์ฃผ์ธ์", placeholder="์์ฑ๋ ์์๋ผ์ธ ๋ณต์ฌ, ์์ ํด์ ์ฌ์ฉํ์ธ์", lines=10)
|
337 |
+
|
338 |
+
outline_generate_btn.click(fn=generate_outline, inputs=[category, style, topic, references1, references2, references3, blog_title, outline_system_message, style, outline_max_tokens, outline_temperature, outline_top_p], outputs=[outline_result])
|
339 |
+
|
340 |
+
gr.Markdown("---\n\n")
|
341 |
+
|
342 |
+
gr.Markdown("### 7๋จ๊ณ: ๊ธ ์์ฑํ๊ธฐ", elem_id="step-title")
|
343 |
+
gr.HTML("<span style='color: grey;'>[์์๋ผ์ธ ๋ณ ํ
์คํธ๋์ ์ ํ๊ณ ๊ธ ์์ฑํ๊ธฐ ๋ฒํผ์ ์ ํํด์ฃผ์ธ์]</span>")
|
344 |
+
|
345 |
+
with gr.Accordion("๋ธ๋ก๊ทธ ๊ธ ์ค์ ", visible=True):
|
346 |
+
blog_system_message = gr.Textbox(label="์นดํ
๊ณ ๋ฆฌ ํ๋กฌํํธ", value=get_blog_post_prompt("๊ณ ๊ฐ๋ฐ์ํ"), lines=20, visible=True)
|
347 |
+
blog_max_tokens = gr.Slider(label="Max Tokens", minimum=1000, maximum=12000, value=8000, step=1000)
|
348 |
+
blog_temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, value=0.8, step=0.1)
|
349 |
+
blog_top_p = gr.Slider(label="Top P", minimum=0.1, maximum=1.0, value=0.95, step=0.05)
|
350 |
+
|
351 |
+
generate_btn = gr.Button("๋ธ๋ก๊ทธ ๊ธ ์์ฑํ๊ธฐ")
|
352 |
+
output = gr.Textbox(label="์์ฑ๋ ๋ธ๋ก๊ทธ ๊ธ", lines=30)
|
353 |
+
|
354 |
+
generate_btn.click(fn=generate_blog_post, inputs=[category, style, topic, references1, references2, references3, blog_title, outline_input, blog_system_message, style, blog_max_tokens, blog_temperature, blog_top_p], outputs=[output])
|
355 |
+
|
356 |
+
save_pdf_btn = gr.Button("PDF๋ก ์ ์ฅํ๊ธฐ")
|
357 |
+
pdf_output = gr.File(label="์์ฑ๋ PDF ํ์ผ")
|
358 |
+
|
359 |
+
save_pdf_btn.click(fn=save_content_to_pdf, inputs=[output], outputs=[pdf_output])
|
360 |
+
|
361 |
+
def update_prompts_and_description(category, style):
|
362 |
+
title_prompt, outline_prompt, blog_post_prompt, style_prompt, style_description = update_prompts(category, style)
|
363 |
+
return title_prompt, outline_prompt, blog_post_prompt, style_description
|
364 |
+
|
365 |
+
category.change(fn=update_prompts_and_description, inputs=[category, style], outputs=[title_system_message, outline_system_message, blog_system_message, style_description])
|
366 |
+
style.change(fn=update_prompts_and_description, inputs=[category, style], outputs=[title_system_message, outline_system_message, blog_system_message, style_description])
|
367 |
+
|
368 |
+
demo.launch()
|
369 |
+
|
370 |
+
gr.HTML("""
|
371 |
+
<style>
|
372 |
+
#step-title {
|
373 |
+
font-size: 1.7em;
|
374 |
+
font-weight: bold;
|
375 |
+
}
|
376 |
+
#style-description {
|
377 |
+
font-size: 1.2em;
|
378 |
+
font-style: italic;
|
379 |
+
}
|
380 |
+
</style>
|
381 |
+
""")
|