File size: 35,579 Bytes
89931e7
7ebe30e
2bb1715
 
 
 
 
 
 
 
7ebe30e
c8b9002
9460aab
 
 
 
e46db4b
ccda3a0
85045b8
3fbc510
 
 
 
 
 
 
 
19424c2
3fbc510
19424c2
 
 
efa7bb4
19424c2
 
 
 
 
 
7ebe30e
2bb1715
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7ebe30e
2bb1715
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17b1367
2bb1715
e46db4b
 
 
 
19424c2
 
 
 
e46db4b
 
 
 
 
 
 
 
 
 
 
 
 
2bb1715
19424c2
 
 
 
 
 
 
 
 
c8b9002
 
2bb1715
8b72279
c8b9002
8b72279
 
 
 
 
2a768e3
c8b9002
e46db4b
 
 
 
 
2a768e3
 
 
2bb1715
e46db4b
2a768e3
 
e46db4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2bb1715
19424c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c8b9002
19424c2
8b72279
 
c8b9002
19424c2
2bb1715
 
 
19424c2
c8b9002
19424c2
8b72279
 
c8b9002
19424c2
2bb1715
 
 
 
8b72279
19424c2
2bb1715
8b72279
2bb1715
8b72279
2bb1715
 
 
19424c2
 
 
 
 
 
 
 
2bb1715
 
 
 
43b41a3
 
 
 
 
 
 
 
 
 
 
2bb1715
 
 
 
43b41a3
 
 
 
 
 
 
 
 
 
 
2bb1715
 
 
 
 
 
43b41a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2bb1715
 
 
 
43b41a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2bb1715
 
 
 
 
 
43b41a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2bb1715
 
 
 
43b41a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2bb1715
 
c8b9002
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
002f297
c8b9002
 
 
 
 
95fa926
002f297
c8b9002
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8b77bcb
2bb1715
c8b9002
2bb1715
 
 
c8b9002
 
adbe0a9
2bb1715
9460aab
e46db4b
 
9460aab
efa7bb4
cc7b568
 
 
 
c8a284f
 
cc7b568
 
 
 
 
c30c215
cc7b568
 
 
 
 
 
 
 
1856dd1
cc7b568
 
ccda3a0
cc7b568
 
 
 
 
 
 
1856dd1
 
 
 
cc7b568
1856dd1
cc7b568
85045b8
cc7b568
c8a284f
ccda3a0
3fbc510
ccda3a0
22f5ca4
1856dd1
 
ee0bc84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89931e7
8c1642e
22f5ca4
 
89931e7
 
2a768e3
22f5ca4
 
8c1642e
 
22f5ca4
4703255
 
1d000f2
22f5ca4
 
 
8c1642e
 
 
 
 
 
ea001e6
8c1642e
 
ea001e6
8c1642e
 
22f5ca4
ee0bc84
8c1642e
 
 
e46db4b
8c1642e
22f5ca4
8c1642e
 
4703255
ea001e6
4703255
 
 
 
ea001e6
 
 
4703255
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e58c03d
 
 
 
 
 
 
 
 
2bb1715
 
 
 
 
e46db4b
c8b9002
 
 
 
e46db4b
2bb1715
8c1642e
8b77bcb
22f5ca4
e46db4b
 
2bb1715
e46db4b
 
22f5ca4
ccda3a0
7ebe30e
bd4e371
 
e46db4b
bd4e371
9460aab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
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 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__)

import tiktoken

def count_tokens(text):
    encoding = tiktoken.get_encoding("cl100k_base")
    return len(encoding.encode(text))

def truncate_text(text, max_tokens):
    encoding = tiktoken.get_encoding("cl100k_base")
    encoded = encoding.encode(text)
    if len(encoded) > max_tokens:
        return encoding.decode(encoded[:max_tokens])
    return text

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-08-2024")

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}]
            total_tokens = count_tokens(system_message) + count_tokens(content) + max_tokens
            if total_tokens > 32000:
                max_tokens = 32000 - count_tokens(system_message) - count_tokens(content) - 100  # ์•ˆ์ „ ๋งˆ์ง„
            
            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 fetch_references(topic, max_tokens=3000):
    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 = truncate_text(f"์ œ๋ชฉ: {selected_results[0]['์ œ๋ชฉ']}\n๋‚ด์šฉ: {crawl_blog_content(selected_results[0]['๋งํฌ'], session)}", max_tokens)
    references2_content = truncate_text(f"์ œ๋ชฉ: {selected_results[1]['์ œ๋ชฉ']}\n๋‚ด์šฉ: {crawl_blog_content(selected_results[1]['๋งํฌ'], session)}", max_tokens)
    references3_content = truncate_text(f"์ œ๋ชฉ: {selected_results[2]['์ œ๋ชฉ']}\n๋‚ด์šฉ: {crawl_blog_content(selected_results[2]['๋งํฌ'], session)}", max_tokens)
    
    return "์ฐธ๊ณ ๊ธ€ ์ƒ์„ฑ ์™„๋ฃŒ", references1_content, references2_content, references3_content



def generate_outline(category, style, topic, references1, references2, references3, title, max_tokens=2000):
    full_content = analyze_info(category, style, topic, references1, references2, references3)
    content = truncate_text(f"{full_content}\nTitle: {title}", max_tokens)
    category_prompt = get_outline_prompt(category)
    style_prompt = get_style_prompt(style)
    combined_prompt = f"{category_prompt}\n\n{style_prompt}"
    modified_text, input_tokens, output_tokens, total_tokens = call_api(content, combined_prompt, 6000, 0.8, 0.95)
    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, max_tokens=4000):
    full_content = analyze_info(category, style, topic, references1, references2, references3)
    content = truncate_text(f"{full_content}\nTitle: {title}\nOutline: {outline}", max_tokens)
    category_prompt = get_blog_post_prompt(category)
    style_prompt = get_style_prompt(style)
    combined_prompt = f"{category_prompt}\n\n{style_prompt}"
    modified_text, input_tokens, output_tokens, total_tokens = call_api(content, combined_prompt, 8000, 0.8, 0.95)
    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_and_generate_all_steps(category, style, topic, blog_title):
    _, references1_content, references2_content, references3_content = fetch_references(topic)
    
    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 = "๋ธ”๋กœ๊ฑฐ(๊ตฌ๊ธ€) ์ž๋™ ํฌ์ŠคํŒ…-์ž๋™-One ID-๋ณต์ˆ˜ ํฌ์ŠคํŒ… ์ƒ์„ฑ/ ํฌ์ŠคํŒ… ๊ฒŒ์žฌ(์˜ˆ) ๋งํฌ ํด๋ฆญ: https://carecures.blogspot.com \n"

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, progress=gr.Progress()):
    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 i, title in enumerate(titles[:num_titles], 1):
        progress(i / num_titles, desc=f"์ฒ˜๋ฆฌ ์ค‘: {i}/{num_titles}")
        try:
            image_url_1 = get_image_url(topic)
            image_url_2 = get_image_url(topic)
            
            _, _, _, _, _, blog_content, _ = fetch_references_and_generate_all_steps(category, style, topic, title)
            
            if blog_content.startswith("API ํ˜ธ์ถœ ์‹คํŒจ"):
                result = f"์ œ๋ชฉ: {title}\n์ƒ์„ฑ ์‹คํŒจ: {blog_content}\n\n"
            else:
                if image_url_1:
                    blog_content = f'<img src="{image_url_1}" alt="{topic} 1" style="max-width:100%; height:auto;">\n\n{blog_content}'
                if image_url_2:
                    blog_content = f'{blog_content}\n\n<img src="{image_url_2}" alt="{topic} 2" style="max-width:100%; height:auto;">'

                send_result = send_to_blogger(title, blog_content)
                result = 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"
            
            results.append(result)
            yield f"์ง„ํ–‰ ์ƒํ™ฉ: {i}/{num_titles}\n\n" + "\n".join(results)
        except Exception as e:
            logger.error("์ œ๋ชฉ '%s' ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: %s", title, str(e))
            result = f"์ œ๋ชฉ: {title}\n์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}\n\n"
            results.append(result)
            yield f"์ง„ํ–‰ ์ƒํ™ฉ: {i}/{num_titles}\n\n" + "\n".join(results)
        
        time.sleep(5)
    
    yield f"์™„๋ฃŒ: {num_titles}/{num_titles}\n\n" + "\n".join(results)



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)}"

css = """
footer {
    visibility: hidden;
}
"""


with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) 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๋‹จ๊ณ„ : ์ž๋™ ์ƒ์„ฑ ๋ฐ ์ „์†กํ•  ๋ธ”๋กœ๊ทธ ์ˆ˜๋ฅผ ์„ ํƒํ•˜์„ธ์š”")
    num_titles = gr.Slider(minimum=1, maximum=2, 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()