fantaxy's picture
Rename app (6).py to app-backup.py
d45a028 verified
import html
import gradio as gr
import requests
from bs4 import BeautifulSoup
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
import re
import time
import random
import os
from huggingface_hub import InferenceClient
from fpdf import FPDF
from transformers import pipeline
import torch
from diffusers import StableDiffusionXLPipeline
import uuid
import json
from huggingface_hub.utils._errors import HfHubHTTPError
from gradio_client import Client
from urllib.parse import urljoin
import requests
from pexels_api import API
import logging
# ๋กœ๊น… ์„ค์ •
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def setup_session():
try:
session = requests.Session()
retries = Retry(total=5, backoff_factor=1, status_forcelist=[502, 503, 504])
session.mount('https://', HTTPAdapter(max_retries=retries))
return session
except Exception as e:
return None
def generate_naver_search_url(query):
base_url = "https://search.naver.com/search.naver?"
params = {"ssc": "tab.blog.all", "sm": "tab_jum", "query": query}
url = base_url + "&".join(f"{key}={value}" for key, value in params.items())
return url
def crawl_blog_content(url, session):
try:
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive",
"Referer": "https://search.naver.com/search.naver",
}
# ๋žœ๋ค ๋”œ๋ ˆ์ด ์ถ”๊ฐ€
delay = random.uniform(1, 2)
time.sleep(delay)
response = session.get(url, headers=headers)
if response.status_code != 200:
return ""
soup = BeautifulSoup(response.content, "html.parser")
content = soup.find("div", attrs={'class': 'se-main-container'})
if content:
return clean_text(content.get_text())
else:
return ""
except Exception as e:
return ""
def crawl_naver_search_results(url, session):
try:
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive",
"Referer": "https://search.naver.com/search.naver",
}
response = session.get(url, headers=headers)
if response.status_code != 200:
return []
soup = BeautifulSoup(response.content, "html.parser")
results = []
count = 0
for li in soup.find_all("li", class_=re.compile("bx.*")):
if count >= 10:
break
for div in li.find_all("div", class_="detail_box"):
for div2 in div.find_all("div", class_="title_area"):
title = div2.text.strip()
for a in div2.find_all("a", href=True):
link = a["href"]
if "blog.naver" in link:
link = link.replace("https://", "https://m.")
results.append({"์ œ๋ชฉ": title, "๋งํฌ": link})
count += 1
if count >= 10:
break
if count >= 10:
break
if count >= 10:
break
return results
except Exception as e:
return []
def clean_text(text):
text = re.sub(r'\s+', ' ', text).strip()
return text
def create_client(model_name):
return InferenceClient(model_name, token=os.getenv("HF_TOKEN"))
client = create_client("CohereForAI/c4ai-command-r-plus")
def call_api(content, system_message, max_tokens, temperature, top_p, max_retries=3):
for attempt in range(max_retries):
try:
messages = [{"role": "system", "content": system_message}, {"role": "user", "content": content}]
random_seed = random.randint(0, 1000000)
response = client.chat_completion(messages=messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p, seed=random_seed)
modified_text = response.choices[0].message.content
input_tokens = response.usage.prompt_tokens
output_tokens = response.usage.completion_tokens
total_tokens = response.usage.total_tokens
return modified_text, input_tokens, output_tokens, total_tokens
except HfHubHTTPError as e:
if attempt < max_retries - 1:
time.sleep(5) # 5์ดˆ ๋Œ€๊ธฐ ํ›„ ์žฌ์‹œ๋„
else:
return f"API ํ˜ธ์ถœ ์‹คํŒจ: {str(e)}", 0, 0, 0
def analyze_info(category, style, topic, references1, references2, references3):
return f"์„ ํƒํ•œ ์นดํ…Œ๊ณ ๋ฆฌ: {category}\n์„ ํƒํ•œ ํฌ์ŠคํŒ… ์Šคํƒ€์ผ: {style}\n๋ธ”๋กœ๊ทธ ์ฃผ์ œ: {topic}\n์ฐธ๊ณ  ๊ธ€1: {references1}\n์ฐธ๊ณ  ๊ธ€2: {references2}\n์ฐธ๊ณ  ๊ธ€3: {references3}"
def suggest_title(category, style, topic, references1, references2, references3):
full_content = analyze_info(category, style, topic, references1, references2, references3)
category_prompt = get_title_prompt(category)
style_prompt = get_style_prompt(style)
max_tokens = 5000
temperature = 0.8
top_p = 0.95
combined_prompt = f"{category_prompt}\n\n{style_prompt}\n\n์ถ”๊ฐ€ ์ง€์‹œ์‚ฌํ•ญ: ์ ˆ๋Œ€๋กœ ์ œ๋ชฉ์— '๋ธ”๋กœ๊ทธ'๋‚˜ '์ œ๋ชฉ'์ด๋ผ๋Š” ๋‹จ์–ด๋ฅผ ํฌํ•จํ•˜์ง€ ๋งˆ์„ธ์š”. ๊ฐ ์ œ์•ˆ์€ ์‹ค์ œ ํฌ์ŠคํŠธ ์ œ๋ชฉ์œผ๋กœ ๋ฐ”๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."
modified_text, input_tokens, output_tokens, total_tokens = call_api(full_content, combined_prompt, max_tokens, temperature, top_p)
# ๋ฒˆํ˜ธ์™€ ์ (.)์„ ์ œ๊ฑฐํ•˜๊ณ  ๊ฐ ์ค„์„ ์ •๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
titles = [line.strip() for line in modified_text.split('\n') if line.strip()]
titles = [re.sub(r'^\d+\.\s*', '', title) for title in titles]
# "๋ธ”๋กœ๊ทธ"์™€ "์ œ๋ชฉ"์ด๋ผ๋Š” ๋‹จ์–ด๊ฐ€ ํฌํ•จ๋œ ์ œ๋ชฉ์„ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.
titles = [title for title in titles if "๋ธ”๋กœ๊ทธ" not in title and "์ œ๋ชฉ" not in title]
token_usage_message = f"[์ž…๋ ฅ ํ† ํฐ์ˆ˜: {input_tokens}]\n[์ถœ๋ ฅ ํ† ํฐ์ˆ˜: {output_tokens}]\n[์ด ํ† ํฐ์ˆ˜: {total_tokens}]"
return "\n".join(titles), token_usage_message
def process_all_titles(category, style, topic):
# ์ œ๋ชฉ ์ถ”์ฒœ
title_suggestions, _ = suggest_title(category, style, topic, "", "", "")
titles = title_suggestions.split('\n')
results = []
for title in titles[:10]: # ์ฒ˜์Œ 10๊ฐœ์˜ ์ œ๋ชฉ๋งŒ ์‚ฌ์šฉ
try:
# ๋ธ”๋กœ๊ทธ ๊ธ€ ์ƒ์„ฑ
_, _, _, _, _, blog_content, _ = fetch_references_and_generate_all_steps(category, style, topic, title)
if blog_content.startswith("API ํ˜ธ์ถœ ์‹คํŒจ"):
results.append(f"์ œ๋ชฉ: {title}\n์ƒ์„ฑ ์‹คํŒจ: {blog_content}\n\n")
continue
# ํฌ์ŠคํŒ… ์ „์†ก
send_result = send_to_blogger(title, blog_content)
results.append(f"์ œ๋ชฉ: {title}\n์ „์†ก ๊ฒฐ๊ณผ: {send_result}\n\n")
except Exception as e:
results.append(f"์ œ๋ชฉ: {title}\n์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}\n\n")
time.sleep(5) # API ํ˜ธ์ถœ ์‚ฌ์ด์— 5์ดˆ ๋Œ€๊ธฐ
return "\n".join(results)
def generate_outline(category, style, topic, references1, references2, references3, title):
full_content = analyze_info(category, style, topic, references1, references2, references3)
content = f"{full_content}\nTitle: {title}"
category_prompt = get_outline_prompt(category)
style_prompt = get_style_prompt(style)
max_tokens = 6000
temperature = 0.8
top_p = 0.95
combined_prompt = f"{category_prompt}\n\n{style_prompt}"
modified_text, input_tokens, output_tokens, total_tokens = call_api(content, combined_prompt, max_tokens, temperature, top_p)
token_usage_message = f"[์ž…๋ ฅ ํ† ํฐ์ˆ˜: {input_tokens}]\n[์ถœ๋ ฅ ํ† ํฐ์ˆ˜: {output_tokens}]\n[์ด ํ† ํฐ์ˆ˜: {total_tokens}]"
return modified_text, token_usage_message
def generate_blog_post(category, style, topic, references1, references2, references3, title, outline):
full_content = analyze_info(category, style, topic, references1, references2, references3)
content = f"{full_content}\nTitle: {title}\nOutline: {outline}"
category_prompt = get_blog_post_prompt(category)
style_prompt = get_style_prompt(style)
max_tokens = 8000
temperature = 0.8
top_p = 0.95
combined_prompt = f"{category_prompt}\n\n{style_prompt}"
modified_text, input_tokens, output_tokens, total_tokens = call_api(content, combined_prompt, max_tokens, temperature, top_p)
formatted_text = modified_text.replace('\n', '\n\n')
token_usage_message = f"[์ž…๋ ฅ ํ† ํฐ์ˆ˜: {input_tokens}]\n[์ถœ๋ ฅ ํ† ํฐ์ˆ˜: {output_tokens}]\n[์ด ํ† ํฐ์ˆ˜: {total_tokens}]"
return formatted_text, token_usage_message
def fetch_references(topic):
search_url = generate_naver_search_url(topic)
session = setup_session()
if session is None:
return "Failed to set up session.", "", "", ""
results = crawl_naver_search_results(search_url, session)
if not results:
return "No results found.", "", "", ""
selected_results = random.sample(results, 3)
references1_content = f"์ œ๋ชฉ: {selected_results[0]['์ œ๋ชฉ']}\n๋‚ด์šฉ: {crawl_blog_content(selected_results[0]['๋งํฌ'], session)}"
references2_content = f"์ œ๋ชฉ: {selected_results[1]['์ œ๋ชฉ']}\n๋‚ด์šฉ: {crawl_blog_content(selected_results[1]['๋งํฌ'], session)}"
references3_content = f"์ œ๋ชฉ: {selected_results[2]['์ œ๋ชฉ']}\n๋‚ด์šฉ: {crawl_blog_content(selected_results[2]['๋งํฌ'], session)}"
return "์ฐธ๊ณ ๊ธ€ ์ƒ์„ฑ ์™„๋ฃŒ", references1_content, references2_content, references3_content
def fetch_references_and_generate_all_steps(category, style, topic, blog_title):
search_url = generate_naver_search_url(topic)
session = setup_session()
if session is None:
return "", "", "", "", "", "", "", "", "", ""
results = crawl_naver_search_results(search_url, session)
if not results:
return "", "", "", "", "", "", "", "", "", ""
selected_results = random.sample(results, 3)
references1_content = f"์ œ๋ชฉ: {selected_results[0]['์ œ๋ชฉ']}\n๋‚ด์šฉ: {crawl_blog_content(selected_results[0]['๋งํฌ'], session)}"
references2_content = f"์ œ๋ชฉ: {selected_results[1]['์ œ๋ชฉ']}\n๋‚ด์šฉ: {crawl_blog_content(selected_results[1]['๋งํฌ'], session)}"
references3_content = f"์ œ๋ชฉ: {selected_results[2]['์ œ๋ชฉ']}\n๋‚ด์šฉ: {crawl_blog_content(selected_results[2]['๋งํฌ'], session)}"
# ์•„์›ƒ๋ผ์ธ ์ƒ์„ฑ
outline_result, outline_token_usage = generate_outline(category, style, topic, references1_content, references2_content, references3_content, blog_title)
# ๋ธ”๋กœ๊ทธ ๊ธ€ ์ƒ์„ฑ
blog_post_result, blog_post_token_usage = generate_blog_post(category, style, topic, references1_content, references2_content, references3_content, blog_title, outline_result)
return references1_content, references2_content, references3_content, outline_result, outline_token_usage, blog_post_result, blog_post_token_usage
def get_title_prompt(category):
if (category == "์ผ๋ฐ˜"):
return """
# ๋ธ”๋กœ๊ทธ ์ œ๋ชฉ ์ƒ์„ฑ ๊ทœ์น™(์ผ๋ฐ˜)
##[๊ธฐ๋ณธ๊ทœ์น™]
1. ๋ฐ˜๋“œ์‹œ ํ•œ๊ตญ์–ด(ํ•œ๊ธ€)๋กœ ์ž‘์„ฑํ•˜๋ผ.
2. ๋„ˆ๋Š” ๊ฐ€์žฅ ์ฃผ๋ชฉ๋ฐ›๋Š” ๋งˆ์ผ€ํ„ฐ์ด๋ฉฐ ๋ธ”๋กœ๊ทธ ๋งˆ์ผ€ํŒ… ์ „๋ฌธ๊ฐ€์ด๋‹ค.
3. ํŠนํžˆ ๋„ˆ๋Š” '์ •๋ณด์„ฑ(Informative)' ์ „๋ฌธ ๋ธ”๋กœ๊ทธ ๋งˆ์ผ€ํŒ… ์ „๋ฌธ๊ฐ€์ด๋‹ค.
4. ์ •๋ณด ์ œ๊ณต์— ์ดˆ์ ์„ ๋งž์ถ”์–ด ์ž‘์„ฑํ•œ๋‹ค.
##[๋ธ”๋กœ๊ทธ ์ œ๋ชฉ ์ž‘์„ฑ ๊ทœ์น™]
1. ๋ธ”๋กœ๊ทธ ์ œ๋ชฉ 10๊ฐœ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ์ œ๋ชฉ 10๊ฐœ๋งŒ ์ถœ๋ ฅํ•˜๋ผ.
2. ์ œ๋ชฉ์€ 40์ž ์ด๋‚ด๋กœ ์ž‘์„ฑํ•˜๋ผ.
3. ์ œ๊ณต๋œ ์ฐธ๊ณ ๊ธ€์— ๋งž์ถฐ ๋ธ”๋กœ๊ทธ ์ œ๋ชฉ 10๊ฐœ๋ฅผ ์ž‘์„ฑํ•˜๋ผ.
4. ๋ฐ˜๋“œ์‹œ ํ•ต์‹ฌํ‚ค์›Œ๋“œ(Topic)๊ฐ€ ๋ฌธ์žฅ ์•ž์ชฝ์— ๋“ค์–ด๊ฐ€๋„๋ก ์ž‘์„ฑํ•˜๋ผ.
5. ํ•ต์‹ฌ ํ‚ค์›Œ๋“œ์™€ ์—ฐ๊ด€์„ฑ ๋†’์€ ์ฃผ์ œ๋ฅผ ํฌํ•จํ•˜์—ฌ ์ž‘์„ฑํ•˜๋ผ.
"""
elif (category == "๊ฑด๊ฐ•์ •๋ณด"):
return """
# ๋ธ”๋กœ๊ทธ ์ œ๋ชฉ ์ƒ์„ฑ ๊ทœ์น™(๊ฑด๊ฐ•์ •๋ณด)
##[๊ธฐ๋ณธ๊ทœ์น™]
1. ๋ฐ˜๋“œ์‹œ ํ•œ๊ตญ์–ด(ํ•œ๊ธ€)๋กœ ์ž‘์„ฑํ•˜๋ผ.
2. ๋„ˆ๋Š” ๊ฐ€์žฅ ์ฃผ๋ชฉ๋ฐ›๋Š” ๋งˆ์ผ€ํ„ฐ์ด๋ฉฐ ๋ธ”๋กœ๊ทธ ๋งˆ์ผ€ํŒ… ์ „๋ฌธ๊ฐ€์ด๋‹ค.
3. ํŠนํžˆ ๋„ˆ๋Š” '๊ฑด๊ฐ•, ์˜ํ•™ ์ •๋ณด' ์ „๋ฌธ ๋ธ”๋กœ๊ทธ ๋งˆ์ผ€ํ„ฐ์ด๋‹ค.
4. ์ •ํ™•ํ•˜๊ณ  ์ „๋ฌธ์ ์ธ ์ •๋ณด ์ œ๊ณต์— ์ดˆ์ ์„ ๋งž์ถ”์–ด ์ž‘์„ฑํ•œ๋‹ค.
##[๋ธ”๋กœ๊ทธ ์ œ๋ชฉ ์ž‘์„ฑ ๊ทœ์น™]
1. ๋ธ”๋กœ๊ทธ ์ œ๋ชฉ 10๊ฐœ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ์ œ๋ชฉ 10๊ฐœ๋งŒ ์ถœ๋ ฅํ•˜๋ผ.
2. ์ œ๋ชฉ์€ 40์ž ์ด๋‚ด๋กœ ์ž‘์„ฑํ•˜๋ผ.
3. ์ œ๊ณต๋œ ์ฐธ๊ณ ๊ธ€์— ๋งž์ถฐ ๋ธ”๋กœ๊ทธ ์ œ๋ชฉ 10๊ฐœ๋ฅผ ์ž‘์„ฑํ•˜๋ผ.
4. ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ๋ธ”๋กœ๊ทธ ์ฃผ์ œ, ํ•ต์‹ฌํ‚ค์›Œ๋“œ(Topic)๊ฐ€ ๋ฌธ์žฅ ์•ž์ชฝ์— ๋“ค์–ด๊ฐ€๋„๋ก ์ œ๋ชฉ์„ ์ž‘์„ฑํ•˜๋ผ.
5. ์ฐธ๊ณ ๊ธ€์„ ๋ถ„์„ํ•˜์—ฌ ๋…์ž๋“ค์ด ๊ฑด๊ฐ•ํ•œ ์ƒํ™œ์„ ์œ ์ง€ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ๋ฐ˜์˜ํ•˜๋ผ.
"""
def get_outline_prompt(category):
if (category == "์ผ๋ฐ˜"):
return """
# ๋ธ”๋กœ๊ทธ ์†Œ์ฃผ์ œ(Subtopic) ์ƒ์„ฑ ๊ทœ์น™(์ผ๋ฐ˜)
##[๊ธฐ๋ณธ๊ทœ์น™]
1. ๋ฐ˜๋“œ์‹œ ํ•œ๊ตญ์–ด(ํ•œ๊ธ€)๋กœ ์ž‘์„ฑํ•˜๋ผ.
2. ๋„ˆ๋Š” ๊ฐ€์žฅ ์ฃผ๋ชฉ๋ฐ›๋Š” ๋งˆ์ผ€ํ„ฐ์ด๋ฉฐ ๋ธ”๋กœ๊ทธ ๋งˆ์ผ€ํŒ… ์ „๋ฌธ๊ฐ€์ด๋‹ค.
3. ํŠนํžˆ ๋„ˆ๋Š” '์ •๋ณด์„ฑ(Informative)' ์ „๋ฌธ ๋ธ”๋กœ๊ทธ ๋งˆ์ผ€ํŒ… ์ „๋ฌธ๊ฐ€์ด๋‹ค.
4. ์ •๋ณด ์ œ๊ณต์— ์ดˆ์ ์„ ๋งž์ถ”์–ด ์ž‘์„ฑํ•œ๋‹ค.
##[์†Œ์ฃผ์ œ ์ž‘์„ฑ๊ทœ์น™]
1. [๊ธฐ๋ณธ๊ทœ์น™]์„ ๊ธฐ๋ณธ ์ ์šฉํ•˜๋ผ.
2. ๋ธ”๋กœ๊ทธ ๊ธ€์„ ์ž‘์„ฑํ•˜๊ธฐ ์œ„ํ•œ ์†Œ์ฃผ์ œ๋ฅผ ์ž‘์„ฑํ•˜๋ผ.
3. ์ œ๊ณต๋œ ์ฐธ๊ณ ๊ธ€๊ณผ ๋ธ”๋กœ๊ทธ ์ฃผ์ œ, ์ œ๋ชฉ์„ ๋ฐ”ํƒ•์œผ๋กœ ํ•ต์‹ฌ ์ฃผ์ œ๋ฅผ ํŒŒ์•…ํ•˜์—ฌ ์†Œ์ฃผ์ œ๋ฅผ ์ƒ์„ฑํ•˜๋ผ.
4. ์ „์ฒด ๋งฅ๋ฝ์— ๋งž๊ฒŒ ์†Œ์ฃผ์ œ๋ฅผ ์ž‘์„ฑํ•˜๋ผ.
5. ์†Œ์ œ๋ชฉ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก 20์ž ๋‚ด์™ธ๋กœ ์ž‘์„ฑํ•˜๋ผ.
6. ๋…์ž๊ฐ€ ์–ป๊ณ ์ž ํ•˜๋Š” ์ •๋ณด์™€ ํฅ๋ฏธ๋กœ์šด ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๋„๋ก ์†Œ์ฃผ์ œ๋ฅผ ์ž‘์„ฑํ•˜๋ผ.
7. ์†Œ์ฃผ์ œ์˜ ๋ณธ๋ก ์˜ ๋‚ด์šฉ์ด ์ถฉ๋ถ„ํžˆ ์ž‘์„ฑ๋  ์ˆ˜ ์žˆ๋Š” ์†Œ์ฃผ์ œ๋กœ ์„ค์ •ํ•˜๋ผ.
8. ๋ฐ˜๋“œ์‹œ [์†Œ์ฃผ์ œ ๊ตฌ์„ฑ]์— ๋งž๊ฒŒ ์ถœ๋ ฅํ•˜๋ผ.
##[์†Œ์ฃผ์ œ ๊ตฌ์„ฑ]
1. ๋ฐ˜๋“œ์‹œ [๋„์ž…๋ถ€] - 1๊ฐœ, [๋ณธ๋ก 1~5] - 5๊ฐœ, [๊ฒฐ๋ก ] - 1๊ฐœ๋กœ ๊ตฌ์„ฑํ•˜์—ฌ ์ถœ๋ ฅํ•˜๋ผ.
2. ๋ฐ˜๋“œ์‹œ [๋„์ž…๋ถ€]์™€ [๊ฒฐ๋ก ]์˜ ์ œ๋ชฉ์ด ์ค‘๋ณต๋˜์ง€ ์•Š๋„๋ก ์ž‘์„ฑํ•˜๋ผ.
"""
elif (category == "๊ฑด๊ฐ•์ •๋ณด"):
return """
# ๋ธ”๋กœ๊ทธ ์†Œ์ฃผ์ œ(Subtopic) ์ƒ์„ฑ ๊ทœ์น™(๊ฑด๊ฐ•์ •๋ณด)
##[๊ธฐ๋ณธ๊ทœ์น™]
1. ๋ฐ˜๋“œ์‹œ ํ•œ๊ตญ์–ด(ํ•œ๊ธ€)๋กœ ์ž‘์„ฑํ•˜๋ผ.
2. ๋„ˆ๋Š” ๊ฐ€์žฅ ์ฃผ๋ชฉ๋ฐ›๋Š” ๋งˆ์ผ€ํ„ฐ์ด๋ฉฐ ๋ธ”๋กœ๊ทธ ๋งˆ์ผ€ํŒ… ์ „๋ฌธ๊ฐ€์ด๋‹ค.
3. ํŠนํžˆ ๋„ˆ๋Š” '๊ฑด๊ฐ•, ์˜ํ•™ ์ •๋ณด' ์ „๋ฌธ ๋ธ”๋กœ๊ทธ ๋งˆ์ผ€ํ„ฐ์ด๋‹ค.
4. ์ •ํ™•ํ•˜๊ณ  ์ „๋ฌธ์ ์ธ ์ •๋ณด ์ œ๊ณต์— ์ดˆ์ ์„ ๋งž์ถ”์–ด ์ž‘์„ฑํ•œ๋‹ค.
##[์†Œ์ฃผ์ œ ์ž‘์„ฑ๊ทœ์น™]
1. [๊ธฐ๋ณธ๊ทœ์น™]์„ ๊ธฐ๋ณธ ์ ์šฉํ•˜๋ผ.
2. ๋ธ”๋กœ๊ทธ ๊ธ€์„ ์ž‘์„ฑํ•˜๊ธฐ ์œ„ํ•œ ์†Œ์ฃผ์ œ๋ฅผ ์ž‘์„ฑํ•˜๋ผ.
3. ์ œ๊ณต๋œ ์ฐธ๊ณ ๊ธ€๊ณผ ๋ธ”๋กœ๊ทธ ์ฃผ์ œ, ์ œ๋ชฉ์„ ๋ฐ”ํƒ•์œผ๋กœ ํ•ต์‹ฌ ์ฃผ์ œ๋ฅผ ํŒŒ์•…ํ•˜์—ฌ ์†Œ์ฃผ์ œ๋ฅผ ์ƒ์„ฑํ•˜๋ผ.
4. ์ „์ฒด ๋งฅ๋ฝ์— ๋งž๊ฒŒ ์†Œ์ฃผ์ œ๋ฅผ ์ž‘์„ฑํ•˜๋ผ.
5. ์†Œ์ œ๋ชฉ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก 20์ž ๋‚ด์™ธ๋กœ ์ž‘์„ฑํ•˜๋ผ.
6. ๋…์ž๊ฐ€ ์–ป๊ณ ์ž ํ•˜๋Š” ์ •ํ™•ํ•œ ์ •๋ณด์™€ ๊ฑด๊ฐ•ํ•œ ์ƒํ™œ์„ ์œ ์ง€ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๋„๋ก ์†Œ์ฃผ์ œ๋ฅผ ์ž‘์„ฑํ•˜๋ผ.
7. ์†Œ์ฃผ์ œ์˜ ๋ณธ๋ก ์˜ ๋‚ด์šฉ์ด ์ถฉ๋ถ„ํžˆ ์ž‘์„ฑ๋  ์ˆ˜ ์žˆ๋Š” ์†Œ์ฃผ์ œ๋กœ ์„ค์ •ํ•˜๋ผ.
8. ๋ฐ˜๋“œ์‹œ [์†Œ์ฃผ์ œ ๊ตฌ์„ฑ]์— ๋งž์ถฐ ์†Œ์ฃผ์ œ๋งŒ ์ถœ๋ ฅํ•˜๋ผ.
##[์†Œ์ฃผ์ œ ๊ตฌ์„ฑ]
1. ๋ฐ˜๋“œ์‹œ [๋„์ž…๋ถ€] - 1๊ฐœ, [๋ณธ๋ก 1~5] - 5๊ฐœ, [๊ฒฐ๋ก ] - 1๊ฐœ๋กœ ๊ตฌ์„ฑํ•˜์—ฌ ์ถœ๋ ฅํ•˜๋ผ.
2. ๋ฐ˜๋“œ์‹œ [๋„์ž…๋ถ€]์™€ [๊ฒฐ๋ก ]์˜ ์ œ๋ชฉ์ด ์ค‘๋ณต๋˜์ง€ ์•Š๋„๋ก ์ž‘์„ฑํ•˜๋ผ.
"""
def get_blog_post_prompt(category):
if (category == "์ผ๋ฐ˜"):
return """
# ๋ธ”๋กœ๊ทธ ํ…์ŠคํŠธ ์ƒ์„ฑ ๊ทœ์น™(์ผ๋ฐ˜)
##[๊ธฐ๋ณธ๊ทœ์น™]
1. ๋ฐ˜๋“œ์‹œ ํ•œ๊ตญ์–ด(ํ•œ๊ธ€)๋กœ ์ž‘์„ฑํ•˜๋ผ.
2. ๋„ˆ๋Š” ๊ฐ€์žฅ ์ฃผ๋ชฉ๋ฐ›๋Š” ๋งˆ์ผ€ํ„ฐ์ด๋ฉฐ ๋ธ”๋กœ๊ทธ ๋งˆ์ผ€ํŒ… ์ „๋ฌธ๊ฐ€์ด๋‹ค.
3. ํŠนํžˆ ๋„ˆ๋Š” '์ •๋ณด์„ฑ(Informative)' ์ „๋ฌธ ๋ธ”๋กœ๊ทธ ๋งˆ์ผ€ํŒ… ์ „๋ฌธ๊ฐ€์ด๋‹ค.
4. ์ •๋ณด ์ œ๊ณต์— ์ดˆ์ ์„ ๋งž์ถ”์–ด ์ž‘์„ฑํ•œ๋‹ค.
##[ํ…์ŠคํŠธ ์ž‘์„ฑ ๊ทœ์น™]
1. ๋ฐ˜๋“œ์‹œ ์ž…๋ ฅ๋œ [์†Œ์ฃผ์ œ]์— ๋งž๊ฒŒ ํ…์ŠคํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋ผ.
2. ์†Œ์ฃผ์ œ์˜ [๋ณธ๋ก ] 5๊ฐœ๋ฅผ ๊ฐ๊ฐ 300์ž ์ด์ƒ์œผ๋กœ ์ž‘์„ฑํ•˜๋ผ.
3. ์†Œ์ฃผ์ œ์˜ [๋ณธ๋ก ] ์ด 300์ž ์ด์ƒ ์ƒ์„ฑ๋˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, ์ „์ฒด๊ธ€์ด 2000์ž ์ด์ƒ๋˜๋„๋ก ์ž‘์„ฑํ•˜๋ผ.
4. ์ „์ฒด ๋งฅ๋ฝ์„ ์ดํ•ดํ•˜๊ณ  ๋ฌธ์žฅ์˜ ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๋ผ.
5. ์ฃผ์ œ์— ๋งž๋Š” ๋‹‰๋„ค์ž„, ํŽ˜๋ฅด์†Œ๋‚˜๋ฅผ ์ ์šฉํ•˜์—ฌ ์ž‘์„ฑํ•˜๋ผ.
6. ์ œ๊ณต๋œ ์ฐธ๊ณ ๊ธ€์˜ ์–ดํˆฌ๋ฅผ ๋ฐ˜์˜ํ•˜๋˜, [ํฌ์ŠคํŒ… ์Šคํƒ€์ผ]์— ๋งž๊ฒŒ ์ ์šฉํ•˜๋ผ.
7. ์ ˆ๋Œ€๋กœ ์ฐธ๊ณ ๊ธ€์„ ํ•œ๋ฌธ์žฅ ์ด์ƒ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜์ง€ ๋ง ๊ฒƒ.
8. ์ฃผ์ œ์™€ ์ƒํ™ฉ์— ๋งž๋Š” ์ ์ ˆํ•œ ์–ดํœ˜๋ฅผ ์„ ํƒํ•˜๋ผ.
9. ํ•œ๊ธ€ ์–ดํœ˜์˜ ๋‚œ์ด๋„๋Š” ์‰ฝ๊ฒŒ ์ž‘์„ฑํ•˜๋ผ.
10. ์ ˆ๋Œ€ ๋ฌธ์žฅ์˜ ๋์— '๋‹ต๋‹ˆ๋‹ค'๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋ง ๊ฒƒ.
###[์ •๋ณด์„ฑ ๋ธ”๋กœ๊ทธ ์ž‘์„ฑ ๊ทœ์น™]
1. ๋…์ž๊ฐ€ ์–ป๊ณ ์ž ํ•˜๋Š” ์œ ์šฉํ•œ ์ •๋ณด์™€ ํฅ๋ฏธ๋กœ์šด ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๋„๋ก ์ž‘์„ฑํ•˜๋ผ.
2. ๋…์ž์˜ ๊ณต๊ฐ์„ ์ด๋Œ์–ด๋‚ด๊ณ  ๊ถ๊ธˆ์ฆ์„ ํ•ด๊ฒฐํ•˜๋„๋ก ์ž‘์„ฑํ•˜๋ผ.
3. ๋…์ž์˜ ๊ด€์‹ฌ์‚ฌ๋ฅผ ์ถฉ์กฑ์‹œํ‚ค๋„๋ก ์ž‘์„ฑํ•˜๋ผ.
4. ๋…์ž์—๊ฒŒ ์ด๋“์ด ๋˜๋Š” ์ •๋ณด๋ฅผ ์ž‘์„ฑํ•˜๋ผ.
##[์ œ์™ธ ๊ทœ์น™]
1. ๋ฐ˜๋“œ์‹œ ๋น„์†์–ด ๋ฐ ์š•์„ค(expletive, abusive language, slang)์€ ์ œ์™ธํ•˜๋ผ.
2. ๋ฐ˜๋“œ์‹œ ์ฐธ๊ณ ๊ธ€์˜ ๋งํฌ(URL)๋Š” ์ œ์™ธํ•˜๋ผ.
3. ์ฐธ๊ณ ๊ธ€์—์„œ '๋งํฌ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”'์™€ ๊ฐ™์€ ๋งํฌ ์ด๋™์˜ ๋ฌธ๊ตฌ๋Š” ์ œ์™ธํ•˜๋ผ.
4. ์ฐธ๊ณ ๊ธ€์— ์žˆ๋Š” ์ž‘์„ฑ์ž, ํ™”์ž, ์œ ํŠœ๋ฒ„, ๊ธฐ์ž(Writer, speaker, YouTuber, reporter)์˜ ์ด๋ฆ„, ์• ์นญ, ๋‹‰๋„ค์ž„(Name, Nkickname)์€ ๋ฐ˜๋“œ์‹œ ์ œ์™ธํ•˜๋ผ.
5. ๋ฐ˜๋“œ์‹œ ๋ฌธ์žฅ์˜ ๋๋ถ€๋ถ„์ด ์–ด์ƒ‰ํ•œ ํ•œ๊ตญ์–ด ํ‘œํ˜„์€ ์ œ์™ธํ•˜๋ผ('์˜ˆ์š”', '๋‹ต๋‹ˆ๋‹ค', 'ํ•ด์š”', 'ํ•ด์ฃผ์ฃ ', '๋์ฃ ', '๋์–ด์š”', '๊ณ ์š”' ๋“ฑ.)
"""
elif (category == "๊ฑด๊ฐ•์ •๋ณด"):
return """
# ๋ธ”๋กœ๊ทธ ํ…์ŠคํŠธ ์ƒ์„ฑ ๊ทœ์น™(๊ฑด๊ฐ•์ •๋ณด)
##[๊ธฐ๋ณธ๊ทœ์น™]
1. ๋ฐ˜๋“œ์‹œ ํ•œ๊ตญ์–ด(ํ•œ๊ธ€)๋กœ ์ž‘์„ฑํ•˜๋ผ.
2. ๋„ˆ๋Š” ๊ฐ€์žฅ ์ฃผ๋ชฉ๋ฐ›๋Š” ๋งˆ์ผ€ํ„ฐ์ด๋ฉฐ ๋ธ”๋กœ๊ทธ ๋งˆ์ผ€ํŒ… ์ „๋ฌธ๊ฐ€์ด๋‹ค.
3. ํŠนํžˆ ๋„ˆ๋Š” '๊ฑด๊ฐ•, ์˜ํ•™ ์ •๋ณด' ์ „๋ฌธ ๋ธ”๋กœ๊ทธ ๋งˆ์ผ€ํ„ฐ์ด๋‹ค.
4. ์ •ํ™•ํ•˜๊ณ  ์ „๋ฌธ์ ์ธ ์ •๋ณด ์ œ๊ณต์— ์ดˆ์ ์„ ๋งž์ถ”์–ด ์ž‘์„ฑํ•œ๋‹ค.
##[ํ…์ŠคํŠธ ์ž‘์„ฑ ๊ทœ์น™]
1. ๋ฐ˜๋“œ์‹œ ์ž…๋ ฅ๋œ [์†Œ์ฃผ์ œ]์— ๋งž์ถฐ์„œ ํ…์ŠคํŠธ๋ฅผ ์ž‘์„ฑํ•˜๋ผ.
2. ๋ฐ˜๋“œ์‹œ ์ž…๋ ฅ๋œ [์†Œ์ฃผ์ œ]๋Š” ๋ณ€๊ฒฝํ•˜์ง€ ๋ง๊ณ  ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜๋ผ.
3. ์†Œ์ฃผ์ œ์˜ [๋„์ž…๋ถ€]๋Š” ๊ฐ€๋ณ๊ฒŒ ์ž‘์„ฑํ•˜๋˜ ๊ณต๊ฐ๊ณผ ํฅ๋ฏธ, ๋ฌธ์ œ์ œ๊ธฐ, ๊ธ€์˜ ๋ชฉ์ , ๋ณธ๋ฌธ์œผ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ด์–ด์ง€๋Š” ์ „ํ™˜๋ฌธ์žฅ๋“ฑ์„ ์ถœ๋ ฅํ•˜๋ผ.
3. ์†Œ์ฃผ์ œ์˜ [๋ณธ๋ก ] 5๊ฐœ์˜ ๋‚ด์šฉ์ด ๊ฐ๊ฐ 500์ž ์ด์ƒ์ด ๋˜๋„๋ก ์ž‘์„ฑํ•˜๋ผ.
4. ๋ฐ˜๋“œ์‹œ ๋„ˆ๊ฐ€ ์ž‘์„ฑํ•œ ์ „์ฒด๊ธ€์ด 2500์ž ์ด์ƒ์ด ๋˜๋„๋ก ์ž‘์„ฑํ•˜๋ผ.
5. ์ „์ฒด ๋งฅ๋ฝ์„ ์ดํ•ดํ•˜๊ณ  ๋ฌธ์žฅ์˜ ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•˜๋ผ.
6. ์ฐธ๊ณ ๊ธ€์„ ๋ฐ”ํƒ•์œผ๋กœ ์ž‘์„ฑํ•œ ๊ธ€์— ๋งž๋Š” ๋‹‰๋„ค์ž„, ํŽ˜๋ฅด์†Œ๋‚˜๋ฅผ ์ ์šฉํ•˜์—ฌ ์ž‘์„ฑํ•˜๋ผ.
7. ์–ดํˆฌ๋Š” ์ œ๊ณต๋œ ์ฐธ๊ณ ๊ธ€์˜ ์–ดํˆฌ๋ฅผ ๋ฐ˜์˜ํ•˜๋˜, '๊ฑด๊ฐ•, ์˜ํ•™ ์ •๋ณด' ์ „๋ฌธ ๋ธ”๋กœ๊ทธ ๋งˆ์ผ€ํ„ฐ๋กœ์„œ ์ž‘์„ฑํ•˜๋ผ.
8. ์ ˆ๋Œ€๋กœ ์ฐธ๊ณ ๊ธ€์„ ํ•œ๋ฌธ์žฅ ์ด์ƒ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•˜์ง€ ๋ง ๊ฒƒ.
9. ์ฃผ์ œ์™€ ์ƒํ™ฉ์— ๋งž๋Š” ์ ์ ˆํ•œ ์–ดํœ˜๋ฅผ ์„ ํƒํ•˜๋ผ.
###[์ •๋ณด์„ฑ ๋ธ”๋กœ๊ทธ ์ž‘์„ฑ ๊ทœ์น™]
1. ๋…์ž๊ฐ€ ์–ป๊ณ ์ž ํ•˜๋Š” ์ •ํ™•ํ•œ ์ •๋ณด์™€ ๊ฑด๊ฐ•ํ•œ ์ƒํ™œ์„ ์œ ์ง€ํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๋„๋ก ์†Œ์ฃผ์ œ์— ๋งž๊ฒŒ ๋‚ด์šฉ์„ ์ž‘์„ฑํ•˜๋ผ.
2. ๋…์ž์˜ ๊ณต๊ฐ์„ ์ด๋Œ์–ด๋‚ด๊ณ  ๊ถ๊ธˆ์ฆ์„ ํ•ด๊ฒฐํ•˜๋„๋ก ์ž‘์„ฑํ•˜๋ผ.
3. ๋…์ž์˜ ๊ด€์‹ฌ์‚ฌ๋ฅผ ์ถฉ์กฑ์‹œํ‚ค๋„๋ก ์ž‘์„ฑํ•˜๋ผ.
4. ๋…์ž์—๊ฒŒ ์ด๋“์ด ๋˜๋Š” ์ •๋ณด๋ฅผ ์ž‘์„ฑํ•˜๋ผ.
##[์ œ์™ธ ๊ทœ์น™]
1. ๋ฐ˜๋“œ์‹œ ์ฐธ๊ณ ๊ธ€์˜ ๋งํฌ(URL)๋Š” ์ œ์™ธํ•˜๋ผ.
2. ์ฐธ๊ณ ๊ธ€์—์„œ '๋งํฌ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”'์™€ ๊ฐ™์€ ๋งํฌ ์ด๋™์˜ ๋ฌธ๊ตฌ๋Š” ์ œ์™ธํ•˜๋ผ.
3. ์ฐธ๊ณ ๊ธ€์— ์žˆ๋Š” ์ž‘์„ฑ์ž, ํ™”์ž, ์œ ํŠœ๋ฒ„, ๊ธฐ์ž(Writer, speaker, YouTuber, reporter)์˜ ์ด๋ฆ„, ์• ์นญ, ๋‹‰๋„ค์ž„(Name, Nkickname)์€ ๋ฐ˜๋“œ์‹œ ์ œ์™ธํ•˜๋ผ.
"""
def get_style_prompt(style):
prompts = {
"์นœ๊ทผํ•œ": """
#์นœ๊ทผํ•œ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŒ… ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ
1. ํ†ค๊ณผ ์–ด์กฐ
- ๋Œ€ํ™”ํ•˜๋“ฏ ํŽธ์•ˆํ•˜๊ณ  ์นœ๊ทผํ•œ ๋งํˆฌ ์‚ฌ์šฉ
- ๋…์ž๋ฅผ "์—ฌ๋Ÿฌ๋ถ„" ๋˜๋Š” "๋…์ž๋‹˜๋“ค"๋กœ ์ง€์นญ
- ์ ์ ˆํ•œ ์ด๋ชจ์ง€๋ฅผ sparseํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜์—ฌ ์นœ๊ทผ๊ฐ ํ‘œํ˜„
2. ๋ฌธ์žฅ ๋ฐ ๋‚ด์šฉ ๊ตฌ์„ฑ
- ์งง๊ณ  ๊ฐ„๊ฒฐํ•œ ๋ฌธ์žฅ ์œ„์ฃผ๋กœ ์ž‘์„ฑ
- ๊ตฌ์–ด์ฒด ํ‘œํ˜„ ์‚ฌ์šฉ (์˜ˆ: "~ํ–ˆ์–ด์š”", "~์ธ ๊ฒƒ ๊ฐ™์•„์š”")
- '~๋‹ˆ๋‹ค', '~ํ–ˆ์ฃ '๋Š” ์‚ฌ์šฉํ•˜์ง€ ๋ง ๊ฒƒ.
- ๊ฐœ์ธ์ ์ธ ๊ฒฝํ—˜์ด๋‚˜ ์ผํ™”๋กœ ์‹œ์ž‘
- ์‹ค์ƒํ™œ์—์„œ ์‰ฝ๊ฒŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํŒ ์ œ๊ณต
- ๋…์ž์˜ ๊ณต๊ฐ์„ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์‚ฌ๋ก€ ํฌํ•จ
3. ์šฉ์–ด ๋ฐ ์„ค๋ช… ๋ฐฉ์‹
- ์ „๋ฌธ ์šฉ์–ด ๋Œ€์‹  ์‰ฌ์šด ๋‹จ์–ด๋กœ ํ’€์–ด์„œ ์„ค๋ช…
- ๋น„์œ ๋‚˜ ์€์œ ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋ณต์žกํ•œ ๊ฐœ๋… ์„ค๋ช…
- ์ˆ˜์‚ฌ์˜๋ฌธ๋ฌธ ํ™œ์šฉํ•˜์—ฌ ๋…์ž์™€ ์†Œํ†ตํ•˜๋Š” ๋А๋‚Œ ์ฃผ๊ธฐ
4. ๋…์ž์™€์˜ ์ƒํ˜ธ์ž‘์šฉ
- ๋…์ž์˜ ์˜๊ฒฌ์„ ๋ฌผ์–ด๋ณด๋Š” ์งˆ๋ฌธ ํฌํ•จ
- ๋Œ“๊ธ€ ๋‹ฌ๊ธฐ๋ฅผ ๋…๋ คํ•˜๋Š” ๋ฌธ๊ตฌ ์‚ฌ์šฉ
5. ์ด๋ชจ์ง€ ํ™œ์šฉ
- ์ฃผ์š” ํฌ์ธํŠธ๋‚˜ ์ƒˆ๋กœ์šด ์„น์…˜์„ ์‹œ์ž‘ํ•  ๋•Œ๋งŒ ๊ด€๋ จ ์ด๋ชจ์ง€ ์‚ฌ์šฉ
- ์ „์ฒด ๊ธ€์—์„œ 3-5๊ฐœ ์ •๋„์˜ ์ด๋ชจ์ง€๋งŒ ์‚ฌ์šฉํ•˜์—ฌ ๊ณผ๋„ํ•˜์ง€ ์•Š๊ฒŒ ์œ ์ง€
6. ๋งˆ๋ฌด๋ฆฌ
- ์นœ๊ทผํ•˜๊ณ  ๊ฒฉ๋ คํ•˜๋Š” ํ†ค์œผ๋กœ ๋งˆ๋ฌด๋ฆฌ
- ๋‹ค์Œ ํฌ์ŠคํŒ…์— ๋Œ€ํ•œ ๊ธฐ๋Œ€๊ฐ ์œ ๋ฐœ
์ฃผ์˜์‚ฌํ•ญ: ๋„ˆ๋ฌด ๊ฐ€๋ฒผ์šด ํ†ค์€ ์ง€์–‘ํ•˜๊ณ , ์ฃผ์ œ์˜ ์ค‘์š”์„ฑ์„ ํ•ด์น˜์ง€ ์•Š๋Š” ์„ ์—์„œ ์นœ๊ทผํ•จ ์œ ์ง€
์˜ˆ์‹œ: "์—ฌ๋Ÿฌ๋ถ„, ์˜ค๋Š˜ ํ•˜๋ฃจ๋Š” ์–ด๋– ์…จ๋‚˜์š”? ๐Ÿ˜Š ์ €๋Š” ์˜ค๋Š˜ ์žฌ๋ฏธ์žˆ๋Š” ๊ฒฝํ—˜์„ ํ–ˆ์–ด์š”. ๋ฐ”๋กœ '๋ฏธ๋‹ˆ๋ฉ€ ๋ผ์ดํ”„'์— ๋„์ „ํ•ด๋ณธ ๊ฑด๋ฐ์š”. ์ฒ˜์Œ์—๋Š” ์ข€ ๋ง‰๋ง‰ํ–ˆ์ง€๋งŒ, ์ƒ๊ฐ๋ณด๋‹ค ์ฆ๊ฑฐ์šด ๊ฒฝํ—˜์ด์—ˆ์–ด์š”! ์—ฌ๋Ÿฌ๋ถ„๋„ ํ•œ๋ฒˆ ๋”ฐ๋ผํ•ด๋ณด์‹œ๊ฒ ์–ด์š”? ์ œ๊ฐ€ ์•Œ๊ฒŒ ๋œ ๊ฟ€ํŒ๋“ค์„ ํ•˜๋‚˜ํ•˜๋‚˜ ์•Œ๋ ค๋“œ๋ฆด๊ฒŒ์š”.
""",
"์ผ๋ฐ˜": """
#์ผ๋ฐ˜์ ์ธ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŒ… ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ
1. ํ†ค๊ณผ ์–ด์กฐ
- ์ค‘๋ฆฝ์ ์ด๊ณ  ๊ฐ๊ด€์ ์ธ ํ†ค ์œ ์ง€
- ์ ์ ˆํ•œ ์กด๋Œ“๋ง ์‚ฌ์šฉ (์˜ˆ: "~ํ•ฉ๋‹ˆ๋‹ค", "~์ž…๋‹ˆ๋‹ค")
2. ๋‚ด์šฉ ๊ตฌ์กฐ ๋ฐ ์ „๊ฐœ
- ๋ช…ํ™•ํ•œ ์ฃผ์ œ ์ œ์‹œ๋กœ ์‹œ์ž‘
- ๋…ผ๋ฆฌ์ ์ธ ์ˆœ์„œ๋กœ ์ •๋ณด ์ „๊ฐœ
- ์ฃผ์š” ํฌ์ธํŠธ๋ฅผ ๊ฐ•์กฐํ•˜๋Š” ์†Œ์ œ๋ชฉ ํ™œ์šฉ
- ์ ์ ˆํ•œ ๊ธธ์ด์˜ ๋‹จ๋ฝ์œผ๋กœ ๊ตฌ์„ฑ
3. ์šฉ์–ด ๋ฐ ์„ค๋ช… ๋ฐฉ์‹
- ์ผ๋ฐ˜์ ์œผ๋กœ ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์šด ์šฉ์–ด ์„ ํƒ
- ํ•„์š”์‹œ ๊ฐ„๋‹จํ•œ ์„ค๋ช… ์ถ”๊ฐ€
- ๊ฐ๊ด€์ ์ธ ์ •๋ณด ์ œ๊ณต์— ์ค‘์ 
4. ํ…์ŠคํŠธ ๊ตฌ์กฐํ™”
- ๋ถˆ๋ฆฟ ํฌ์ธํŠธ๋‚˜ ๋ฒˆํ˜ธ ๋งค๊ธฐ๊ธฐ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ •๋ณด ๊ตฌ์กฐํ™”
- ์ค‘์š”ํ•œ ์ •๋ณด๋Š” ๊ตต์€ ๊ธ€์”จ๋‚˜ ๊ธฐ์šธ์ž„๊ผด๋กœ ๊ฐ•์กฐ
5. ๋…์ž ์ƒํ˜ธ์ž‘์šฉ
- ์ ์ ˆํžˆ ๋…์ž์˜ ์ƒ๊ฐ์„ ๋ฌป๋Š” ์งˆ๋ฌธ ํฌํ•จ
- ์ถ”๊ฐ€ ์ •๋ณด๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ๋Š” ํ‚ค์›Œ๋“œ ์ œ์‹œ
6. ๋งˆ๋ฌด๋ฆฌ
- ์ฃผ์š” ๋‚ด์šฉ ๊ฐ„๋‹จํžˆ ์š”์•ฝ
- ์ถ”๊ฐ€ ์ •๋ณด์— ๋Œ€ํ•œ ์•ˆ๋‚ด ์ œ๊ณต
์ฃผ์˜์‚ฌํ•ญ: ๋„ˆ๋ฌด ๋”ฑ๋”ฑํ•˜๊ฑฐ๋‚˜ ์ง€๋ฃจํ•˜์ง€ ์•Š๋„๋ก ๊ท ํ˜• ์œ ์ง€
์˜ˆ์‹œ: "์ตœ๊ทผ ํ™˜๊ฒฝ ๋ฌธ์ œ๊ฐ€ ๋Œ€๋‘๋˜๋ฉด์„œ '์ œ๋กœ ์›จ์ด์ŠคํŠธ' ๋ผ์ดํ”„์Šคํƒ€์ผ์— ๋Œ€ํ•œ ๊ด€์‹ฌ์ด ๋†’์•„์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ œ๋กœ ์›จ์ด์ŠคํŠธ๋ž€ ์ผ์ƒ์ƒํ™œ์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์“ฐ๋ ˆ๊ธฐ๋ฅผ ์ตœ์†Œํ™”ํ•˜๋Š” ์ƒํ™œ ๋ฐฉ์‹์„ ๋งํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ธ€์—์„œ๋Š” ์ œ๋กœ ์›จ์ด์ŠคํŠธ์˜ ๊ฐœ๋…, ์‹ค์ฒœ ๋ฐฉ๋ฒ•, ๊ทธ๋ฆฌ๊ณ  ๊ทธ ํšจ๊ณผ์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋จผ์ € ์ œ๋กœ ์›จ์ด์ŠคํŠธ์˜ ์ •์˜๋ถ€ํ„ฐ ์‚ดํŽด๋ณด๋ฉด...
""",
"์ „๋ฌธ์ ์ธ": """
#์ „๋ฌธ์ ์ธ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŒ… ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ
1. ํ†ค๊ณผ ๊ตฌ์กฐ
- ๊ณต์‹์ ์ด๊ณ  ํ•™์ˆ ์ ์ธ ํ†ค ์‚ฌ์šฉ
- ๊ฐ๊ด€์ ์ด๊ณ  ๋ถ„์„์ ์ธ ์ ‘๊ทผ ์œ ์ง€
- ๋ช…ํ™•ํ•œ ์„œ๋ก , ๋ณธ๋ก , ๊ฒฐ๋ก  ๊ตฌ์กฐ
- ์ฒด๊ณ„์ ์ธ ๋…ผ์  ์ „๊ฐœ
- ์„ธ๋ถ€ ์„น์…˜์„ ์œ„ํ•œ ๋ช…ํ™•ํ•œ ์†Œ์ œ๋ชฉ ์‚ฌ์šฉ
2. ๋‚ด์šฉ ๊ตฌ์„ฑ ๋ฐ ์ „๊ฐœ
- ๋ณต์žกํ•œ ๊ฐœ๋…์„ ์ •ํ™•ํžˆ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์žฅ ๊ตฌ์กฐ ์‚ฌ์šฉ
- ๋…ผ๋ฆฌ์  ์—ฐ๊ฒฐ์„ ์œ„ํ•œ ์ „ํ™˜์–ด ํ™œ์šฉ
- ํ•ด๋‹น ๋ถ„์•ผ์˜ ์ „๋ฌธ ์šฉ์–ด ์ ๊ทน ํ™œ์šฉ (ํ•„์š”์‹œ ๊ฐ„๋žตํ•œ ์„ค๋ช… ์ œ๊ณต)
- ์‹ฌ์ธต์ ์ธ ๋ถ„์„๊ณผ ๋น„ํŒ์  ์‚ฌ๊ณ  ์ „๊ฐœ
- ๋‹ค์–‘ํ•œ ๊ด€์  ์ œ์‹œ ๋ฐ ๋น„๊ต
3. ๋ฐ์ดํ„ฐ ๋ฐ ๊ทผ๊ฑฐ ํ™œ์šฉ
- ํ†ต๊ณ„, ์—ฐ๊ตฌ ๊ฒฐ๊ณผ, ์ „๋ฌธ๊ฐ€ ์˜๊ฒฌ ๋“ฑ ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ์ถœ์ฒ˜ ์ธ์šฉ
- ํ•„์š”์‹œ ๊ฐ์ฃผ๋‚˜ ์ฐธ๊ณ ๋ฌธํ—Œ ๋ชฉ๋ก ํฌํ•จ
- ์ˆ˜์น˜ ๋ฐ์ดํ„ฐ๋Š” ํ…์ŠคํŠธ๋กœ ๋ช…ํ™•ํžˆ ์„ค๋ช…
4. ํ…์ŠคํŠธ ๊ตฌ์กฐํ™”
- ๋…ผ๋ฆฌ์  ๊ตฌ์กฐ๋ฅผ ๊ฐ•์กฐํ•˜๊ธฐ ์œ„ํ•ด ๋ฒˆํ˜ธ ๋งค๊ธฐ๊ธฐ ์‚ฌ์šฉ
- ํ•ต์‹ฌ ๊ฐœ๋…์ด๋‚˜ ์šฉ์–ด๋Š” ๊ธฐ์šธ์ž„๊ผด๋กœ ๊ฐ•์กฐ
- ๊ธด ์ธ์šฉ๋ฌธ์€ ๋“ค์—ฌ์“ฐ๊ธฐ๋กœ ๊ตฌ๋ถ„
5. ๋งˆ๋ฌด๋ฆฌ
- ํ•ต์‹ฌ ๋…ผ์  ์žฌ๊ฐ•์กฐ
- ํ–ฅํ›„ ์—ฐ๊ตฌ ๋ฐฉํ–ฅ์ด๋‚˜ ์‹ค๋ฌด์  ํ•จ์˜ ์ œ์‹œ
์ฃผ์˜์‚ฌํ•ญ: ์ „๋ฌธ์„ฑ์„ ์œ ์ง€ํ•˜๋˜, ์™„์ „ํžˆ ์ดํ•ดํ•˜๊ธฐ ์–ด๋ ค์šด ์ˆ˜์ค€์€ ์ง€์–‘
์˜ˆ์‹œ: "๋ณธ ์—ฐ๊ตฌ์—์„œ๋Š” ์ธ๊ณต์ง€๋Šฅ(AI)์˜ ์œค๋ฆฌ์  ํ•จ์˜์— ๋Œ€ํ•ด ๊ณ ์ฐฐํ•œ๋‹ค. ํŠนํžˆ, ์ž์œจ์ฃผํ–‰ ์ž๋™์ฐจ์˜ ์˜์‚ฌ๊ฒฐ์ • ์•Œ๊ณ ๋ฆฌ์ฆ˜์—์„œ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” ์œค๋ฆฌ์  ๋”œ๋ ˆ๋งˆ์— ์ดˆ์ ์„ ๋งž์ถ˜๋‹ค. Bonnefon et al. (2016)์˜ ์—ฐ๊ตฌ์— ๋”ฐ๋ฅด๋ฉด, ์ž์œจ์ฃผํ–‰ ์ฐจ๋Ÿ‰์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์ง๋ฉดํ•  ์ˆ˜ ์žˆ๋Š” ์œค๋ฆฌ์  ์„ ํƒ์˜ ๋ณต์žก์„ฑ์ด ์ง€์ ๋œ ๋ฐ” ์žˆ๋‹ค. ๋ณธ๊ณ ์—์„œ๋Š” ์ด๋Ÿฌํ•œ ์œค๋ฆฌ์  ๋”œ๋ ˆ๋งˆ๋ฅผ ์„ธ ๊ฐ€์ง€ ์ฃผ์š” ๊ด€์ ์—์„œ ๋ถ„์„ํ•œ๋‹ค: 1) ๊ณต๋ฆฌ์ฃผ์˜์  ์ ‘๊ทผ, 2) ์˜๋ฌด๋ก ์  ์ ‘๊ทผ, 3) ๋• ์œค๋ฆฌ์  ์ ‘๊ทผ. ๊ฐ ์ ‘๊ทผ๋ฒ•์˜ ์žฅ๋‹จ์ ์„ ๋น„๊ต ๋ถ„์„ํ•˜๊ณ , ์ด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ž์œจ์ฃผํ–‰ ์ฐจ๋Ÿ‰์˜ ์œค๋ฆฌ์  ์˜์‚ฌ๊ฒฐ์ • ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์ œ์•ˆํ•˜๊ณ ์ž ํ•œ๋‹ค...
"""
}
return prompts.get(style, "ํฌ์ŠคํŒ… ์Šคํƒ€์ผ ํ”„๋กฌํ”„ํŠธ")
def get_style_description(style):
descriptions = {
"์นœ๊ทผํ•œ": "๋…์ž์™€ ๊ฐ€๊นŒ์šด ์นœ๊ตฌ์ฒ˜๋Ÿผ ๋Œ€ํ™”ํ•˜๋Š” ๋“ฏํ•œ ์นœ๊ทผํ•œ ์Šคํƒ€์ผ์ž…๋‹ˆ๋‹ค.",
"์ผ๋ฐ˜": "์ผ๋ฐ˜์ ์ด๊ณ  ์ค‘๋ฆฝ์ ์ธ ํ†ค์œผ๋กœ ์ •๋ณด๋ฅผ ์ „๋‹ฌํ•˜๋Š” ์Šคํƒ€์ผ์ž…๋‹ˆ๋‹ค.",
"์ „๋ฌธ์ ์ธ": "์ „๋ฌธ๊ฐ€์˜ ์‹œ๊ฐ์—์„œ ๊นŠ์ด ์žˆ๋Š” ์ •๋ณด๋ฅผ ์ „๋‹ฌํ•˜๋Š” ์Šคํƒ€์ผ์ž…๋‹ˆ๋‹ค."
}
return descriptions.get(style, "ํฌ์ŠคํŒ… ์Šคํƒ€์ผ์„ ์„ ํƒํ•˜์„ธ์š”.")
def update_prompts_and_description(category, style):
title_prompt = get_title_prompt(category)
outline_prompt = get_outline_prompt(category)
blog_post_prompt = get_blog_post_prompt(category)
style_prompt = get_style_prompt(style)
style_description = get_style_description(style)
return style_description,
#PDFํŒŒ์ผ ๋งŒ๋“ค
class PDF(FPDF):
def __init__(self):
super().__init__()
current_dir = os.path.dirname(__file__)
self.add_font("NanumGothic", "", os.path.join(current_dir, "NanumGothic.ttf"), uni=True)
self.add_font("NanumGothic", "B", os.path.join(current_dir, "NanumGothicBold.ttf"), uni=True)
self.add_font("NanumGothicExtraBold", "", os.path.join(current_dir, "NanumGothicExtraBold.ttf"), uni=True)
self.add_font("NanumGothicLight", "", os.path.join(current_dir, "NanumGothicLight.ttf"), uni=True)
def header(self):
self.set_font('NanumGothic', '', 10)
def footer(self):
self.set_y(-15)
self.set_font('NanumGothic', '', 8)
self.cell(0, 10, f'Page {self.page_no()}', 0, 0, 'C')
def save_to_pdf(blog_post):
pdf = PDF()
pdf.add_page()
lines = blog_post.split('\n')
title = lines[0].strip()
content = '\n'.join(lines[1:]).strip()
filename = format_filename(title) + ".pdf"
pdf.set_font("NanumGothic", 'B', size=14)
pdf.cell(0, 10, title, ln=True, align='C')
pdf.ln(10)
pdf.set_font("NanumGothic", '', size=11)
pdf.multi_cell(0, 5, content)
print(f"Saving PDF as: {filename}")
pdf.output(filename)
return filename
def format_filename(text):
text = re.sub(r'[^\w\s-]', '', text)
return text[:50].strip()
# save_content_to_pdf ํ•จ์ˆ˜๋„ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ˆ˜์ •
def save_content_to_pdf(blog_post):
return save_to_pdf(blog_post)
title = "๋ธ”๋กœ๊ทธ ํฌ์ŠคํŒ… ์ž๋™์ƒ์„ฑ ๋ฐ ์ „์†ก(์ฃผ์ œ๋งŒ ์ž…๋ ฅํ•˜๋ฉด ๋ฌด์ œํ•œ ๊ฐ๊ธฐ ๋‹ค๋ฅธ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŒ… ์ž๋™ ์ฒ˜๋ฆฌ)"
def update_prompts_and_description(category, style):
title_prompt = get_title_prompt(category)
outline_prompt = get_outline_prompt(category)
blog_post_prompt = get_blog_post_prompt(category)
style_prompt = get_style_prompt(style)
style_description = get_style_description(style)
return style_description
WEBHOOK_URL = os.getenv("WEBHOOK_URL")
BLOGGER_ID = os.getenv("BLOGGER_ID")
PEXELS_API_KEY = "5woz23MGx1QrSY0WHFb0BRi29JvbXPu97Hg0xnklYgHUI8G0w23FKH62"
PEXELS_API_URL = "https://api.pexels.com/v1/search"
# ๋ฒˆ์—ญ ๋ชจ๋ธ ์„ค์ •
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
def get_image_url(topic):
try:
translated = translator(topic, max_length=40)[0]['translation_text']
keywords = ' '.join(translated.split()[:2])
except Exception as e:
logger.error(f"๋ฒˆ์—ญ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}")
keywords = ' '.join(topic.split()[:2])
logger.debug(f"๊ฒ€์ƒ‰ ํ‚ค์›Œ๋“œ: {keywords}")
headers = {
"Authorization": PEXELS_API_KEY
}
params = {
"query": keywords,
"per_page": 60, # ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ์ˆ˜ 60๊ฐœ๋กœ ์ฆ๊ฐ€
}
try:
response = requests.get(PEXELS_API_URL, headers=headers, params=params)
logger.debug(f"Pexels API ์‘๋‹ต ์ƒํƒœ ์ฝ”๋“œ: {response.status_code}")
if response.status_code == 200:
data = response.json()
logger.debug(f"Pexels API ์‘๋‹ต ๋ฐ์ดํ„ฐ: {data}")
if data['photos']:
# ๋žœ๋คํ•˜๊ฒŒ 1์žฅ์˜ ์ด๋ฏธ์ง€ ์„ ํƒ
random_photo = random.choice(data['photos'])
return random_photo['src']['large2x']
else:
logger.warning(f"'{keywords}' ๊ด€๋ จ ์ด๋ฏธ์ง€๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
return None
else:
logger.error(f"Pexels API ์˜ค๋ฅ˜: {response.status_code}")
return None
except Exception as e:
logger.error(f"์ด๋ฏธ์ง€ ๊ฒ€์ƒ‰ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}")
return None
def convert_markdown_images(content):
logger.debug("์›๋ณธ ๋‚ด์šฉ: %s", content)
# Markdown ์ด๋ฏธ์ง€ ๋ฌธ๋ฒ•์„ HTML <img> ํƒœ๊ทธ๋กœ ๋ณ€ํ™˜
markdown_pattern = r'!\[([^\]]*)\]\(([^)]+)\)'
content = re.sub(markdown_pattern, r'<img alt="\1" src="\2">', content)
# ๋‹จ์ˆœ URL์„ <img> ํƒœ๊ทธ๋กœ ๋ณ€ํ™˜
url_pattern = r'(https?://\S+?\.(jpg|jpeg|png|gif))'
content = re.sub(url_pattern, r'<img src="\1">', content)
logger.debug("๋ณ€ํ™˜๋œ ๋‚ด์šฉ: %s", content)
return content
def process_all_titles(category, style, topic, num_titles):
title_suggestions, _ = suggest_title(category, style, topic, "", "", "")
titles = title_suggestions.split('\n')
# ๋นˆ ๋ฌธ์ž์—ด์ด๋‚˜ '###' ๋“ฑ์˜ ๋ถˆํ•„์š”ํ•œ ๋ฌธ์ž์—ด ์ œ๊ฑฐ
titles = [title.strip() for title in titles if title.strip() and not title.strip().startswith('###')]
# "๋ธ”๋กœ๊ทธ"์™€ "์ œ๋ชฉ"์ด๋ผ๋Š” ๋‹จ์–ด๊ฐ€ ํฌํ•จ๋œ ์ œ๋ชฉ์„ ์ œ๊ฑฐ
titles = [title for title in titles if "๋ธ”๋กœ๊ทธ" not in title and "์ œ๋ชฉ" not in title]
results = []
for title in titles[:num_titles]:
try:
# ์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€ URL ๊ฐ€์ ธ์˜ค๊ธฐ
image_url_1 = get_image_url(topic)
# ๋‘ ๋ฒˆ์งธ ์ด๋ฏธ์ง€ URL ๊ฐ€์ ธ์˜ค๊ธฐ
image_url_2 = get_image_url(topic)
# ๋ธ”๋กœ๊ทธ ๋‚ด์šฉ ์ƒ์„ฑ
_, _, _, _, _, blog_content, _ = fetch_references_and_generate_all_steps(category, style, topic, title)
if blog_content.startswith("API ํ˜ธ์ถœ ์‹คํŒจ"):
results.append(f"์ œ๋ชฉ: {title}\n์ƒ์„ฑ ์‹คํŒจ: {blog_content}\n\n")
continue
if image_url_1:
img_tag_1 = f'<img src="{image_url_1}" alt="{topic} 1" style="max-width:100%; height:auto;">'
blog_content = f'{img_tag_1}\n\n{blog_content}'
# ๋‘ ๋ฒˆ์งธ ์ด๋ฏธ์ง€ URL์„ ๋ธ”๋กœ๊ทธ ๋‚ด์šฉ ๋ ๋ถ€๋ถ„์— ์ถ”๊ฐ€
if image_url_2:
img_tag_2 = f'<img src="{image_url_2}" alt="{topic} 2" style="max-width:100%; height:auto;">'
blog_content = f'{blog_content}\n\n{img_tag_2}'
# ํฌ์ŠคํŒ… ์ „์†ก
send_result = send_to_blogger(title, blog_content)
results.append(f"์ œ๋ชฉ: {title}\n์ „์†ก ๊ฒฐ๊ณผ: {send_result}\n์‚ฌ์šฉ๋œ ์ด๋ฏธ์ง€ URL 1: {image_url_1 if image_url_1 else '์ด๋ฏธ์ง€ ์—†์Œ'}\n์‚ฌ์šฉ๋œ ์ด๋ฏธ์ง€ URL 2: {image_url_2 if image_url_2 else '์ด๋ฏธ์ง€ ์—†์Œ'}\n\n")
except Exception as e:
logger.error("์ œ๋ชฉ '%s' ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: %s", title, str(e))
results.append(f"์ œ๋ชฉ: {title}\n์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}\n\n")
time.sleep(5) # API ํ˜ธ์ถœ ์‚ฌ์ด์— 5์ดˆ ๋Œ€๊ธฐ
return "\n".join(results)
import html
def send_to_blogger(blog_title, blog_content):
if not WEBHOOK_URL:
logger.error("WEBHOOK_URL์ด ์„ค์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.")
return "WEBHOOK_URL์ด ์„ค์ •๋˜์ง€ ์•Š์•„ ํฌ์ŠคํŒ…์„ ์ „์†กํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
# HTML ์—”ํ‹ฐํ‹ฐ ๋””์ฝ”๋”ฉ
blog_content = html.unescape(blog_content)
payload = {
"blogger_id": BLOGGER_ID,
"title": blog_title,
"content": blog_content
}
try:
logger.debug("๋ธ”๋กœ๊ฑฐ์— ์ „์†กํ•  ํŽ˜์ด๋กœ๋“œ: %s", payload)
response = requests.post(WEBHOOK_URL, json=payload)
logger.debug("๋ธ”๋กœ๊ฑฐ ์‘๋‹ต: %s, %s", response.status_code, response.text)
if response.status_code == 200:
return "ํฌ์ŠคํŒ…์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ „์†ก๋˜์—ˆ์Šต๋‹ˆ๋‹ค."
else:
return f"ํฌ์ŠคํŒ… ์ „์†ก ์‹คํŒจ. ์ƒํƒœ ์ฝ”๋“œ: {response.status_code}, ์‘๋‹ต: {response.text}"
except requests.exceptions.RequestException as e:
logger.error("๋ธ”๋กœ๊ฑฐ์— ์ „์†ก ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: %s", str(e))
return f"๋„คํŠธ์›Œํฌ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
except Exception as e:
logger.error("๋ธ”๋กœ๊ทธ์— ์ „์†ก ์ค‘ ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: %s", str(e))
return f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
with gr.Blocks() as demo:
gr.Markdown(f"# {title}")
gr.Markdown("### 1๋‹จ๊ณ„ : ํฌ์ŠคํŒ… ์นดํ…Œ๊ณ ๋ฆฌ๋ฅผ ์ง€์ •ํ•ด์ฃผ์„ธ์š”")
category = gr.Radio(choices=["์ผ๋ฐ˜", "๊ฑด๊ฐ•์ •๋ณด"], label="ํฌ์ŠคํŒ… ์นดํ…Œ๊ณ ๋ฆฌ", value="์ผ๋ฐ˜")
gr.Markdown("### 2๋‹จ๊ณ„: ํฌ์ŠคํŒ… ์Šคํƒ€์ผ์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”")
style = gr.Radio(choices=["์นœ๊ทผํ•œ", "์ผ๋ฐ˜", "์ „๋ฌธ์ ์ธ"], label="ํฌ์ŠคํŒ… ์Šคํƒ€์ผ", value="์นœ๊ทผํ•œ")
style_description = gr.Markdown(f"_{get_style_description('์นœ๊ทผํ•œ')}_", elem_id="style-description")
gr.Markdown("### 3๋‹จ๊ณ„ : ๋ธ”๋กœ๊ทธ ์ฃผ์ œ, ๋˜๋Š” ํ‚ค์›Œ๋“œ๋ฅผ ์ƒ์„ธํžˆ ์ž…๋ ฅํ•˜์„ธ์š”")
topic = gr.Textbox(label="๋ธ”๋กœ๊ทธ ์ฃผ์ œ", placeholder="์˜ˆ์‹œ: 8์›” ๊ตญ๋‚ด ์—ฌํ–‰์ง€ ์ถ”์ฒœ")
gr.Markdown("### 4๋‹จ๊ณ„ : ์ž๋™ ์ƒ์„ฑ ๋ฐ ์ „์†กํ•  ๋ธ”๋กœ๊ทธ ์ˆ˜(๊ณ„์ •๋‹น ์ผ์ผ ํฌ์ŠคํŒ… ์—…๋กœ๋“œ ์ œํ•œ 60๊ฑด๊นŒ์ง€ )")
num_titles = gr.Slider(minimum=1, maximum=60, value=2, step=1, label="ํฌ์ŠคํŒ… ๊ฑด")
start_btn = gr.Button("์‹œ์ž‘")
result_output = gr.Textbox(label="์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ", lines=20)
start_btn.click(
fn=process_all_titles,
inputs=[category, style, topic, num_titles],
outputs=[result_output]
)
category.change(fn=update_prompts_and_description, inputs=[category, style], outputs=[style_description])
style.change(fn=update_prompts_and_description, inputs=[category, style], outputs=[style_description])
demo.launch()