Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
|
3 |
import gradio as gr
|
4 |
import requests
|
5 |
from bs4 import BeautifulSoup
|
@@ -15,6 +13,8 @@ from transformers import pipeline
|
|
15 |
import torch
|
16 |
from diffusers import StableDiffusionXLPipeline
|
17 |
import uuid
|
|
|
|
|
18 |
|
19 |
def setup_session():
|
20 |
try:
|
@@ -109,15 +109,23 @@ def create_client(model_name):
|
|
109 |
|
110 |
client = create_client("CohereForAI/c4ai-command-r-plus")
|
111 |
|
112 |
-
def call_api(content, system_message, max_tokens, temperature, top_p):
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
def analyze_info(category, style, topic, references1, references2, references3):
|
123 |
return f"์ ํํ ์นดํ
๊ณ ๋ฆฌ: {category}\n์ ํํ ํฌ์คํ
์คํ์ผ: {style}\n๋ธ๋ก๊ทธ ์ฃผ์ : {topic}\n์ฐธ๊ณ ๊ธ1: {references1}\n์ฐธ๊ณ ๊ธ2: {references2}\n์ฐธ๊ณ ๊ธ3: {references3}"
|
@@ -129,10 +137,42 @@ def suggest_title(category, style, topic, references1, references2, references3)
|
|
129 |
max_tokens = 5000
|
130 |
temperature = 0.8
|
131 |
top_p = 0.95
|
132 |
-
combined_prompt = f"{category_prompt}\n\n{style_prompt}"
|
133 |
modified_text, input_tokens, output_tokens, total_tokens = call_api(full_content, combined_prompt, max_tokens, temperature, top_p)
|
|
|
|
|
|
|
|
|
|
|
134 |
token_usage_message = f"[์
๋ ฅ ํ ํฐ์: {input_tokens}]\n[์ถ๋ ฅ ํ ํฐ์: {output_tokens}]\n[์ด ํ ํฐ์: {total_tokens}]"
|
135 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
def generate_outline(category, style, topic, references1, references2, references3, title):
|
138 |
full_content = analyze_info(category, style, topic, references1, references2, references3)
|
@@ -490,7 +530,7 @@ def format_filename(text):
|
|
490 |
def save_content_to_pdf(blog_post):
|
491 |
return save_to_pdf(blog_post)
|
492 |
|
493 |
-
title = "๋ธ๋ก๊ทธ ํฌ์คํ
|
494 |
|
495 |
def update_prompts_and_description(category, style):
|
496 |
title_prompt = get_title_prompt(category)
|
@@ -500,153 +540,76 @@ def update_prompts_and_description(category, style):
|
|
500 |
style_description = get_style_description(style)
|
501 |
return style_description
|
502 |
|
503 |
-
# ์ด๋ฏธ์ง ์์ฑ์ ์ํ ์ค์
|
504 |
-
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
505 |
-
|
506 |
-
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
507 |
|
508 |
-
|
509 |
-
|
510 |
-
torch_dtype=torch.float16,
|
511 |
-
use_safetensors=True,
|
512 |
-
add_watermarker=False,
|
513 |
-
variant="fp16"
|
514 |
-
).to(device)
|
515 |
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
enhanced_prompt = f"hyper-realistic 8K image of {translated}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic"
|
523 |
-
|
524 |
-
# ๊ณ ์ ๋ ์ค์ ๊ฐ
|
525 |
-
negative_prompt = "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly, (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, disgusting, amputation"
|
526 |
-
width = 1024
|
527 |
-
height = 1024
|
528 |
-
guidance_scale = 10
|
529 |
-
num_inference_steps = 150
|
530 |
-
seed = random.randint(0, 2**32 - 1)
|
531 |
-
generator = torch.Generator("cuda").manual_seed(seed)
|
532 |
-
|
533 |
-
# ์ด๋ฏธ์ง ์์ฑ
|
534 |
-
image = pipe(
|
535 |
-
prompt=enhanced_prompt,
|
536 |
-
negative_prompt=negative_prompt,
|
537 |
-
width=width,
|
538 |
-
height=height,
|
539 |
-
guidance_scale=guidance_scale,
|
540 |
-
num_inference_steps=num_inference_steps,
|
541 |
-
generator=generator
|
542 |
-
).images[0]
|
543 |
|
544 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
545 |
|
546 |
-
def generate_images(blog_post):
|
547 |
-
images = []
|
548 |
-
lines = blog_post.split('\n')
|
549 |
-
title = lines[0].strip()
|
550 |
-
|
551 |
-
# 1. ์ ๋ชฉ์ ๋ํ ์์ฝ์ผ๋ก ๊ฐ์ ๋ชฉ์ ์ด๋ฏธ์ง ์์ฑ
|
552 |
-
title_prompt = f"Conceptual overview image representing '{title}'. Visual summary, infographic style, key concepts illustrated"
|
553 |
-
images.append(generate_image(title_prompt))
|
554 |
-
|
555 |
-
# ๋์
๋ถ์ ๋ณธ๋ฌธ, ๊ฒฐ๋ก ์ฐพ๊ธฐ
|
556 |
-
intro_index = next((i for i, line in enumerate(lines) if '[๋์
๋ถ]' in line), -1)
|
557 |
-
body_index = next((i for i, line in enumerate(lines) if '[๋ณธ๋ก 1]' in line), -1)
|
558 |
-
conclusion_index = next((i for i, line in enumerate(lines) if '[๊ฒฐ๋ก ]' in line), -1)
|
559 |
-
|
560 |
-
# 2. ๋์
๋ถ์ ๋ํ ์์ฝ์ผ๋ก ํฅ๋ฏธ ์ ๋ฐ ๋ชฉ์ ์ด๋ฏธ์ง ์์ฑ
|
561 |
-
intro_text = ' '.join(lines[intro_index+1:body_index]) if intro_index != -1 and body_index != -1 else title
|
562 |
-
intro_summary = f"Engaging and intriguing image to spark interest: {intro_text[:100]}... Eye-catching, thought-provoking, visually appealing"
|
563 |
-
images.append(generate_image(intro_summary))
|
564 |
-
|
565 |
-
# 3. ๋ณธ๋ฌธ ๋ด์ฉ ์์ฝ์ผ๋ก ์ด๋ฏธ์ง ์์ฑ
|
566 |
-
body_text = ' '.join(lines[body_index+1:conclusion_index]) if body_index != -1 and conclusion_index != -1 else title
|
567 |
-
body_summary = f"Detailed illustration of main content: {body_text[:100]}... Informative, clear visualization, key points highlighted"
|
568 |
-
images.append(generate_image(body_summary))
|
569 |
-
|
570 |
-
# 4. ๊ฒฐ๋ก ๋ด์ฉ ์์ฝ์ผ๋ก ๋
์์๊ฒ ์ ๊ณต๋๋ ๊ฐ์น์ ์ด์ต์ ์ด๋ฏธ์ง๋ก ์์ฑ
|
571 |
-
conclusion_text = ' '.join(lines[conclusion_index+1:]) if conclusion_index != -1 else title
|
572 |
-
value_summary = f"Image symbolizing the value and benefits for readers: {conclusion_text[:100]}... Positive outcomes, achievements, growth visualization"
|
573 |
-
images.append(generate_image(value_summary))
|
574 |
-
|
575 |
-
# 5. ๊ฒฐ๋ก ๋ด์ฉ ์์ฝ์ผ๋ก ์์ง์ ์ด๋ฏธ์ง๋ก ์์ฑ
|
576 |
-
symbolic_summary = f"Symbolic representation of the conclusion: {conclusion_text[:100]}... Abstract, metaphorical, thought-provoking imagery"
|
577 |
-
images.append(generate_image(symbolic_summary))
|
578 |
-
|
579 |
-
return images # ํญ์ 5๊ฐ์ ์ด๋ฏธ์ง๋ฅผ ๋ฐํ
|
580 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
581 |
with gr.Blocks() as demo:
|
582 |
gr.Markdown(f"# {title}")
|
583 |
|
584 |
gr.Markdown("### 1๋จ๊ณ : ํฌ์คํ
์นดํ
๊ณ ๋ฆฌ๋ฅผ ์ง์ ํด์ฃผ์ธ์")
|
585 |
category = gr.Radio(choices=["์ผ๋ฐ", "๊ฑด๊ฐ์ ๋ณด"], label="ํฌ์คํ
์นดํ
๊ณ ๋ฆฌ", value="์ผ๋ฐ")
|
586 |
|
587 |
-
gr.Markdown("
|
588 |
-
|
589 |
-
gr.Markdown("### 2๋จ๊ณ: ํฌ์คํ
์คํ์ผ์ ์ ํํด์ฃผ์ธ์", elem_id="step-title")
|
590 |
style = gr.Radio(choices=["์น๊ทผํ", "์ผ๋ฐ", "์ ๋ฌธ์ ์ธ"], label="ํฌ์คํ
์คํ์ผ", value="์น๊ทผํ")
|
591 |
style_description = gr.Markdown(f"_{get_style_description('์น๊ทผํ')}_", elem_id="style-description")
|
592 |
|
593 |
-
gr.Markdown("---\n\n")
|
594 |
-
|
595 |
-
# 2๋จ๊ณ
|
596 |
gr.Markdown("### 3๋จ๊ณ : ๋ธ๋ก๊ทธ ์ฃผ์ , ๋๋ ํค์๋๋ฅผ ์์ธํ ์
๋ ฅํ์ธ์")
|
597 |
-
topic = gr.Textbox(label="๋ธ๋ก๊ทธ ์ฃผ์
|
598 |
|
599 |
-
|
600 |
-
|
601 |
-
references2 = gr.Textbox(label="์ฐธ๊ณ ๊ธ 2", placeholder="์ฐธ๊ณ ํ ๋ธ๋ก๊ทธ ํฌ์คํ
๊ธ์ ๋ณต์ฌํ์ฌ ๋ถ์ฌ๋ฃ์ผ์ธ์", lines=10, visible=False)
|
602 |
-
references3 = gr.Textbox(label="์ฐธ๊ณ ๊ธ 3", placeholder="์ฐธ๊ณ ํ ๋ธ๋ก๊ทธ ํฌ์คํ
๊ธ์ ๋ณต์ฌํ์ฌ ๋ถ์ฌ๋ฃ์ผ์ธ์", lines=10, visible=False)
|
603 |
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
title_token_output = gr.Markdown(label="์ฌ์ฉ๋ ํ ํฐ ์")
|
609 |
-
|
610 |
-
# ์ ๋ชฉ ์ถ์ฒ ๋ฒํผ
|
611 |
-
title_btn = gr.Button("์ ๋ชฉ ์ถ์ฒํ๊ธฐ")
|
612 |
-
title_btn.click(fn=suggest_title, inputs=[category, style, topic, references1, references2, references3], outputs=[title_suggestions, title_token_output])
|
613 |
-
|
614 |
-
blog_title = gr.Textbox(label="๋ธ๋ก๊ทธ ์ ๋ชฉ", placeholder="๋ธ๋ก๊ทธ ์ ๋ชฉ์ ์
๋ ฅํด์ฃผ์ธ์")
|
615 |
-
|
616 |
-
# ๋ธ๋ก๊ทธ ๊ธ ์์ฑ
|
617 |
-
gr.Markdown("### 5๋จ๊ณ : ๋ธ๋ก๊ทธ ๊ธ ์์ฑํ๊ธฐ")
|
618 |
-
gr.HTML("<span style='color: grey;'>[๋ธ๋ก๊ทธ ๊ธ ์์ฑํ๊ธฐ ๋ฒํผ์ ํด๋ฆญํ๋ฉด ์์๋ผ์ธ ์์ฑ ๋ฐ ๋ธ๋ก๊ทธ ๊ธ ์์ฑ์ด ์๋์ผ๋ก ์งํ๋ฉ๋๋ค.]</span>")
|
619 |
-
|
620 |
-
outline_result = gr.Textbox(label="์์๋ผ์ธ ๊ฒฐ๊ณผ", lines=15, visible=False)
|
621 |
-
outline_token_output = gr.Markdown(label="์ฌ์ฉ๋ ํ ํฐ ์", visible=False)
|
622 |
-
output = gr.Textbox(label="์์ฑ๋ ๋ธ๋ก๊ทธ ๊ธ", lines=30)
|
623 |
-
token_output = gr.Markdown(label="์ฌ์ฉ๋ ํ ํฐ ์")
|
624 |
-
|
625 |
-
generate_post_btn = gr.Button("๋ธ๋ก๊ทธ ๊ธ ์์ฑํ๊ธฐ")
|
626 |
-
generate_post_btn.click(
|
627 |
-
fn=fetch_references_and_generate_all_steps,
|
628 |
-
inputs=[category, style, topic, blog_title],
|
629 |
-
outputs=[references1, references2, references3, outline_result, outline_token_output, output, token_output],
|
630 |
-
api_name="generate_post"
|
631 |
)
|
632 |
-
|
633 |
-
|
634 |
-
# ์ด๋ฏธ์ง ์์ฑ ๋ฒํผ ๋ฐ ์ถ๋ ฅ ์ถ๊ฐ
|
635 |
-
generate_images_btn = gr.Button("์ด๋ฏธ์ง ์์ฑํ๊ธฐ")
|
636 |
-
image_outputs = [gr.Image(label=f"์์ฑ๋ ์ด๋ฏธ์ง {i+1}") for i in range(5)]
|
637 |
-
|
638 |
-
generate_images_btn.click(
|
639 |
-
fn=generate_images,
|
640 |
-
inputs=[output],
|
641 |
-
outputs=image_outputs
|
642 |
-
)
|
643 |
-
|
644 |
-
save_pdf_btn = gr.Button("PDF๋ก ์ ์ฅํ๊ธฐ")
|
645 |
-
pdf_output = gr.File(label="์์ฑ๋ PDF ํ์ผ")
|
646 |
-
|
647 |
-
save_pdf_btn.click(fn=save_content_to_pdf, inputs=[output], outputs=[pdf_output])
|
648 |
|
649 |
category.change(fn=update_prompts_and_description, inputs=[category, style], outputs=[style_description])
|
650 |
-
style.change(fn=update_prompts_and_description, inputs=[category, style], outputs=[style_description])
|
651 |
|
652 |
demo.launch()
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
from bs4 import BeautifulSoup
|
|
|
13 |
import torch
|
14 |
from diffusers import StableDiffusionXLPipeline
|
15 |
import uuid
|
16 |
+
import json
|
17 |
+
from huggingface_hub.utils._errors import HfHubHTTPError
|
18 |
|
19 |
def setup_session():
|
20 |
try:
|
|
|
109 |
|
110 |
client = create_client("CohereForAI/c4ai-command-r-plus")
|
111 |
|
112 |
+
def call_api(content, system_message, max_tokens, temperature, top_p, max_retries=3):
|
113 |
+
for attempt in range(max_retries):
|
114 |
+
try:
|
115 |
+
messages = [{"role": "system", "content": system_message}, {"role": "user", "content": content}]
|
116 |
+
random_seed = random.randint(0, 1000000)
|
117 |
+
response = client.chat_completion(messages=messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p, seed=random_seed)
|
118 |
+
modified_text = response.choices[0].message.content
|
119 |
+
input_tokens = response.usage.prompt_tokens
|
120 |
+
output_tokens = response.usage.completion_tokens
|
121 |
+
total_tokens = response.usage.total_tokens
|
122 |
+
return modified_text, input_tokens, output_tokens, total_tokens
|
123 |
+
except HfHubHTTPError as e:
|
124 |
+
if attempt < max_retries - 1:
|
125 |
+
time.sleep(5) # 5์ด ๋๊ธฐ ํ ์ฌ์๋
|
126 |
+
else:
|
127 |
+
return f"API ํธ์ถ ์คํจ: {str(e)}", 0, 0, 0
|
128 |
+
|
129 |
|
130 |
def analyze_info(category, style, topic, references1, references2, references3):
|
131 |
return f"์ ํํ ์นดํ
๊ณ ๋ฆฌ: {category}\n์ ํํ ํฌ์คํ
์คํ์ผ: {style}\n๋ธ๋ก๊ทธ ์ฃผ์ : {topic}\n์ฐธ๊ณ ๊ธ1: {references1}\n์ฐธ๊ณ ๊ธ2: {references2}\n์ฐธ๊ณ ๊ธ3: {references3}"
|
|
|
137 |
max_tokens = 5000
|
138 |
temperature = 0.8
|
139 |
top_p = 0.95
|
140 |
+
combined_prompt = f"{category_prompt}\n\n{style_prompt}\n\n์ถ๊ฐ ์ง์์ฌํญ: ์ ๋๋ก ์ ๋ชฉ ์์ ๋ฒํธ๋ฅผ ๋ถ์ด์ง ๋ง์ธ์."
|
141 |
modified_text, input_tokens, output_tokens, total_tokens = call_api(full_content, combined_prompt, max_tokens, temperature, top_p)
|
142 |
+
|
143 |
+
# ๋ฒํธ์ ์ (.)์ ์ ๊ฑฐํ๊ณ ๊ฐ ์ค์ ์ ๋ฆฌํฉ๋๋ค.
|
144 |
+
titles = [line.strip() for line in modified_text.split('\n') if line.strip()]
|
145 |
+
titles = [re.sub(r'^\d+\.\s*', '', title) for title in titles]
|
146 |
+
|
147 |
token_usage_message = f"[์
๋ ฅ ํ ํฐ์: {input_tokens}]\n[์ถ๋ ฅ ํ ํฐ์: {output_tokens}]\n[์ด ํ ํฐ์: {total_tokens}]"
|
148 |
+
return "\n".join(titles), token_usage_message
|
149 |
+
|
150 |
+
def process_all_titles(category, style, topic):
|
151 |
+
# ์ ๋ชฉ ์ถ์ฒ
|
152 |
+
title_suggestions, _ = suggest_title(category, style, topic, "", "", "")
|
153 |
+
titles = title_suggestions.split('\n')
|
154 |
+
|
155 |
+
results = []
|
156 |
+
for title in titles[:10]: # ์ฒ์ 10๊ฐ์ ์ ๋ชฉ๋ง ์ฌ์ฉ
|
157 |
+
try:
|
158 |
+
# ๋ธ๋ก๊ทธ ๊ธ ์์ฑ
|
159 |
+
_, _, _, _, _, blog_content, _ = fetch_references_and_generate_all_steps(category, style, topic, title)
|
160 |
+
|
161 |
+
if blog_content.startswith("API ํธ์ถ ์คํจ"):
|
162 |
+
results.append(f"์ ๋ชฉ: {title}\n์์ฑ ์คํจ: {blog_content}\n\n")
|
163 |
+
continue
|
164 |
+
|
165 |
+
# ํฌ์คํ
์ ์ก
|
166 |
+
send_result = send_to_blogger(title, blog_content)
|
167 |
+
|
168 |
+
results.append(f"์ ๋ชฉ: {title}\n์ ์ก ๊ฒฐ๊ณผ: {send_result}\n\n")
|
169 |
+
except Exception as e:
|
170 |
+
results.append(f"์ ๋ชฉ: {title}\n์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}\n\n")
|
171 |
+
|
172 |
+
time.sleep(5) # API ํธ์ถ ์ฌ์ด์ 5์ด ๋๊ธฐ
|
173 |
+
|
174 |
+
return "\n".join(results)
|
175 |
+
|
176 |
|
177 |
def generate_outline(category, style, topic, references1, references2, references3, title):
|
178 |
full_content = analyze_info(category, style, topic, references1, references2, references3)
|
|
|
530 |
def save_content_to_pdf(blog_post):
|
531 |
return save_to_pdf(blog_post)
|
532 |
|
533 |
+
title = "๋ธ๋ก๊ทธ ํฌ์คํ
์๋์์ฑ ๋ฐ ์ ์ก(์ฃผ์ ๋ง ์
๋ ฅ์ ์ถ์ฒ ์ ๋ชฉ 10๊ฑด ๊ฐ๊ฐ ์์ฑ/์ ์ก)"
|
534 |
|
535 |
def update_prompts_and_description(category, style):
|
536 |
title_prompt = get_title_prompt(category)
|
|
|
540 |
style_description = get_style_description(style)
|
541 |
return style_description
|
542 |
|
|
|
|
|
|
|
|
|
543 |
|
544 |
+
WEBHOOK_URL = os.getenv("WEBHOOK_URL")
|
545 |
+
BLOGGER_ID = os.getenv("BLOGGER_ID")
|
|
|
|
|
|
|
|
|
|
|
546 |
|
547 |
+
def send_to_blogger(blog_title, blog_content):
|
548 |
+
payload = {
|
549 |
+
"id": BLOGGER_ID,
|
550 |
+
"title": blog_title,
|
551 |
+
"content": blog_content
|
552 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
553 |
|
554 |
+
try:
|
555 |
+
response = requests.post(WEBHOOK_URL, json=payload)
|
556 |
+
if response.status_code == 200:
|
557 |
+
return "ํฌ์คํ
์ด ์ฑ๊ณต์ ์ผ๋ก ์ ์ก๋์์ต๋๋ค."
|
558 |
+
else:
|
559 |
+
return f"ํฌ์คํ
์ ์ก ์คํจ. ์ํ ์ฝ๋: {response.status_code}"
|
560 |
+
except Exception as e:
|
561 |
+
return f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
562 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
563 |
|
564 |
+
def process_all_titles(category, style, topic):
|
565 |
+
# ์ ๋ชฉ ์ถ์ฒ
|
566 |
+
title_suggestions, _ = suggest_title(category, style, topic, "", "", "")
|
567 |
+
titles = title_suggestions.split('\n')
|
568 |
+
|
569 |
+
results = []
|
570 |
+
for title in titles[:10]: # ์ฒ์ 10๊ฐ์ ์ ๋ชฉ๋ง ์ฌ์ฉ
|
571 |
+
try:
|
572 |
+
# ๋ธ๋ก๊ทธ ๊ธ ์์ฑ
|
573 |
+
_, _, _, _, _, blog_content, _ = fetch_references_and_generate_all_steps(category, style, topic, title)
|
574 |
+
|
575 |
+
if blog_content.startswith("API ํธ์ถ ์คํจ"):
|
576 |
+
results.append(f"์ ๋ชฉ: {title}\n์์ฑ ์คํจ: {blog_content}\n\n")
|
577 |
+
continue
|
578 |
+
|
579 |
+
# ํฌ์คํ
์ ๏ฟฝ๏ฟฝ๏ฟฝ
|
580 |
+
send_result = send_to_blogger(title, blog_content)
|
581 |
+
|
582 |
+
results.append(f"์ ๋ชฉ: {title}\n์ ์ก ๊ฒฐ๊ณผ: {send_result}\n\n")
|
583 |
+
except Exception as e:
|
584 |
+
results.append(f"์ ๋ชฉ: {title}\n์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}\n\n")
|
585 |
+
|
586 |
+
time.sleep(5) # API ํธ์ถ ์ฌ์ด์ 5์ด ๋๊ธฐ
|
587 |
+
|
588 |
+
return "\n".join(results)
|
589 |
+
|
590 |
with gr.Blocks() as demo:
|
591 |
gr.Markdown(f"# {title}")
|
592 |
|
593 |
gr.Markdown("### 1๋จ๊ณ : ํฌ์คํ
์นดํ
๊ณ ๋ฆฌ๋ฅผ ์ง์ ํด์ฃผ์ธ์")
|
594 |
category = gr.Radio(choices=["์ผ๋ฐ", "๊ฑด๊ฐ์ ๋ณด"], label="ํฌ์คํ
์นดํ
๊ณ ๋ฆฌ", value="์ผ๋ฐ")
|
595 |
|
596 |
+
gr.Markdown("### 2๋จ๊ณ: ํฌ์คํ
์คํ์ผ์ ์ ํํด์ฃผ์ธ์")
|
|
|
|
|
597 |
style = gr.Radio(choices=["์น๊ทผํ", "์ผ๋ฐ", "์ ๋ฌธ์ ์ธ"], label="ํฌ์คํ
์คํ์ผ", value="์น๊ทผํ")
|
598 |
style_description = gr.Markdown(f"_{get_style_description('์น๊ทผํ')}_", elem_id="style-description")
|
599 |
|
|
|
|
|
|
|
600 |
gr.Markdown("### 3๋จ๊ณ : ๋ธ๋ก๊ทธ ์ฃผ์ , ๋๋ ํค์๋๋ฅผ ์์ธํ ์
๋ ฅํ์ธ์")
|
601 |
+
topic = gr.Textbox(label="๋ธ๋ก๊ทธ ์ฃผ์ ", placeholder="์์: 8์ ๊ตญ๋ด ์ฌํ์ง ์ถ์ฒ")
|
602 |
|
603 |
+
start_btn = gr.Button("์์")
|
604 |
+
result_output = gr.Textbox(label="์ฒ๋ฆฌ ๊ฒฐ๊ณผ", lines=20)
|
|
|
|
|
605 |
|
606 |
+
start_btn.click(
|
607 |
+
fn=process_all_titles,
|
608 |
+
inputs=[category, style, topic],
|
609 |
+
outputs=[result_output]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
610 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
611 |
|
612 |
category.change(fn=update_prompts_and_description, inputs=[category, style], outputs=[style_description])
|
613 |
+
style.change(fn=update_prompts_and_description, inputs=[category, style], outputs=[style_description])
|
614 |
|
615 |
demo.launch()
|