Update app.py
Browse files
app.py
CHANGED
@@ -626,58 +626,46 @@ def convert_markdown_images(content):
|
|
626 |
return content
|
627 |
|
628 |
|
629 |
-
def process_all_titles(category, style, topic, num_titles):
|
630 |
title_suggestions, _ = suggest_title(category, style, topic, "", "", "")
|
631 |
titles = title_suggestions.split('\n')
|
632 |
|
633 |
-
# ๋น ๋ฌธ์์ด์ด๋ '###' ๋ฑ์ ๋ถํ์ํ ๋ฌธ์์ด ์ ๊ฑฐ
|
634 |
titles = [title.strip() for title in titles if title.strip() and not title.strip().startswith('###')]
|
635 |
-
|
636 |
-
# "๋ธ๋ก๊ทธ"์ "์ ๋ชฉ"์ด๋ผ๋ ๋จ์ด๊ฐ ํฌํจ๋ ์ ๋ชฉ์ ์ ๊ฑฐ
|
637 |
titles = [title for title in titles if "๋ธ๋ก๊ทธ" not in title and "์ ๋ชฉ" not in title]
|
638 |
|
639 |
results = []
|
640 |
-
for title in titles[:num_titles]:
|
|
|
641 |
try:
|
642 |
-
|
643 |
-
|
644 |
-
# ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง URL ๊ฐ์ ธ์ค๊ธฐ
|
645 |
image_url_1 = get_image_url(topic)
|
646 |
-
|
647 |
-
# ๋ ๋ฒ์งธ ์ด๋ฏธ์ง URL ๊ฐ์ ธ์ค๊ธฐ
|
648 |
image_url_2 = get_image_url(topic)
|
649 |
|
650 |
-
# ๋ธ๋ก๊ทธ ๋ด์ฉ ์์ฑ
|
651 |
_, _, _, _, _, blog_content, _ = fetch_references_and_generate_all_steps(category, style, topic, title)
|
652 |
|
653 |
if blog_content.startswith("API ํธ์ถ ์คํจ"):
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
# ๋ ๋ฒ์งธ ์ด๋ฏธ์ง URL์ ๋ธ๋ก๊ทธ ๋ด์ฉ ๋ ๋ถ๋ถ์ ์ถ๊ฐ
|
662 |
-
if image_url_2:
|
663 |
-
img_tag_2 = f'<img src="{image_url_2}" alt="{topic} 2" style="max-width:100%; height:auto;">'
|
664 |
-
blog_content = f'{blog_content}\n\n{img_tag_2}'
|
665 |
-
|
666 |
|
|
|
|
|
667 |
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
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")
|
672 |
except Exception as e:
|
673 |
logger.error("์ ๋ชฉ '%s' ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: %s", title, str(e))
|
674 |
-
|
|
|
|
|
675 |
|
676 |
-
time.sleep(5)
|
677 |
|
678 |
-
|
|
|
679 |
|
680 |
-
import html
|
681 |
|
682 |
def send_to_blogger(blog_title, blog_content):
|
683 |
if not WEBHOOK_URL:
|
@@ -723,8 +711,8 @@ with gr.Blocks() as demo:
|
|
723 |
gr.Markdown("### 3๋จ๊ณ : ๋ธ๋ก๊ทธ ์ฃผ์ , ๋๋ ํค์๋๋ฅผ ์์ธํ ์
๋ ฅํ์ธ์")
|
724 |
topic = gr.Textbox(label="๋ธ๋ก๊ทธ ์ฃผ์ ", placeholder="์์: 8์ ๊ตญ๋ด ์ฌํ์ง ์ถ์ฒ")
|
725 |
|
726 |
-
gr.Markdown("### 4๋จ๊ณ : ์๋ ์์ฑ ๋ฐ ์ ์กํ ๋ธ๋ก๊ทธ
|
727 |
-
num_titles = gr.Slider(minimum=1, maximum=
|
728 |
|
729 |
start_btn = gr.Button("์์")
|
730 |
result_output = gr.Textbox(label="์ฒ๋ฆฌ ๊ฒฐ๊ณผ", lines=20)
|
|
|
626 |
return content
|
627 |
|
628 |
|
629 |
+
def process_all_titles(category, style, topic, num_titles, progress=gr.Progress()):
|
630 |
title_suggestions, _ = suggest_title(category, style, topic, "", "", "")
|
631 |
titles = title_suggestions.split('\n')
|
632 |
|
|
|
633 |
titles = [title.strip() for title in titles if title.strip() and not title.strip().startswith('###')]
|
|
|
|
|
634 |
titles = [title for title in titles if "๋ธ๋ก๊ทธ" not in title and "์ ๋ชฉ" not in title]
|
635 |
|
636 |
results = []
|
637 |
+
for i, title in enumerate(titles[:num_titles], 1):
|
638 |
+
progress(i / num_titles, desc=f"์ฒ๋ฆฌ ์ค: {i}/{num_titles}")
|
639 |
try:
|
|
|
|
|
|
|
640 |
image_url_1 = get_image_url(topic)
|
|
|
|
|
641 |
image_url_2 = get_image_url(topic)
|
642 |
|
|
|
643 |
_, _, _, _, _, blog_content, _ = fetch_references_and_generate_all_steps(category, style, topic, title)
|
644 |
|
645 |
if blog_content.startswith("API ํธ์ถ ์คํจ"):
|
646 |
+
result = f"์ ๋ชฉ: {title}\n์์ฑ ์คํจ: {blog_content}\n\n"
|
647 |
+
else:
|
648 |
+
if image_url_1:
|
649 |
+
blog_content = f'<img src="{image_url_1}" alt="{topic} 1" style="max-width:100%; height:auto;">\n\n{blog_content}'
|
650 |
+
if image_url_2:
|
651 |
+
blog_content = f'{blog_content}\n\n<img src="{image_url_2}" alt="{topic} 2" style="max-width:100%; height:auto;">'
|
|
|
|
|
|
|
|
|
|
|
|
|
652 |
|
653 |
+
send_result = send_to_blogger(title, blog_content)
|
654 |
+
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"
|
655 |
|
656 |
+
results.append(result)
|
657 |
+
yield f"์งํ ์ํฉ: {i}/{num_titles}\n\n" + "\n".join(results)
|
|
|
|
|
658 |
except Exception as e:
|
659 |
logger.error("์ ๋ชฉ '%s' ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: %s", title, str(e))
|
660 |
+
result = f"์ ๋ชฉ: {title}\n์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}\n\n"
|
661 |
+
results.append(result)
|
662 |
+
yield f"์งํ ์ํฉ: {i}/{num_titles}\n\n" + "\n".join(results)
|
663 |
|
664 |
+
time.sleep(5)
|
665 |
|
666 |
+
yield f"์๋ฃ: {num_titles}/{num_titles}\n\n" + "\n".join(results)
|
667 |
+
|
668 |
|
|
|
669 |
|
670 |
def send_to_blogger(blog_title, blog_content):
|
671 |
if not WEBHOOK_URL:
|
|
|
711 |
gr.Markdown("### 3๋จ๊ณ : ๋ธ๋ก๊ทธ ์ฃผ์ , ๋๋ ํค์๋๋ฅผ ์์ธํ ์
๋ ฅํ์ธ์")
|
712 |
topic = gr.Textbox(label="๋ธ๋ก๊ทธ ์ฃผ์ ", placeholder="์์: 8์ ๊ตญ๋ด ์ฌํ์ง ์ถ์ฒ")
|
713 |
|
714 |
+
gr.Markdown("### 4๋จ๊ณ : ์๋ ์์ฑ ๋ฐ ์ ์กํ ๋ธ๋ก๊ทธ ์๋ฅผ ์ ํํ์ธ์")
|
715 |
+
num_titles = gr.Slider(minimum=1, maximum=100, value=2, step=1, label="ํฌ์คํ
๊ฑด")
|
716 |
|
717 |
start_btn = gr.Button("์์")
|
718 |
result_output = gr.Textbox(label="์ฒ๋ฆฌ ๊ฒฐ๊ณผ", lines=20)
|