Update app.py
Browse files
app.py
CHANGED
@@ -586,7 +586,58 @@ def process_all_titles(category, style, topic):
|
|
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 |
|
@@ -600,13 +651,17 @@ with gr.Blocks() as demo:
|
|
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])
|
|
|
586 |
time.sleep(5) # API ํธ์ถ ์ฌ์ด์ 5์ด ๋๊ธฐ
|
587 |
|
588 |
return "\n".join(results)
|
589 |
+
|
590 |
+
|
591 |
+
# ๋ฒ์ญ ๋ชจ๋ธ ์ค์
|
592 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
593 |
+
|
594 |
+
# ์ด๋ฏธ์ง ์์ฑ ๋ชจ๋ธ ์ค์
|
595 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
596 |
+
pipe = StableDiffusionXLPipeline.from_pretrained("stabilityai/stable-diffusion-3-medium", torch_dtype=torch.float16)
|
597 |
+
pipe = pipe.to(device)
|
598 |
+
|
599 |
+
def translate_title(title):
|
600 |
+
translated = translator(title, max_length=128)[0]['translation_text']
|
601 |
+
return translated
|
602 |
+
|
603 |
+
def generate_image(prompt):
|
604 |
+
image = pipe(prompt).images[0]
|
605 |
+
image_path = f"generated_image_{uuid.uuid4()}.png"
|
606 |
+
image.save(image_path)
|
607 |
+
return image_path
|
608 |
+
|
609 |
+
def process_all_titles(category, style, topic, num_titles):
|
610 |
+
title_suggestions, _ = suggest_title(category, style, topic, "", "", "")
|
611 |
+
titles = title_suggestions.split('\n')
|
612 |
+
|
613 |
+
results = []
|
614 |
+
for title in titles[:num_titles]:
|
615 |
+
try:
|
616 |
+
_, _, _, _, _, blog_content, _ = fetch_references_and_generate_all_steps(category, style, topic, title)
|
617 |
+
|
618 |
+
if blog_content.startswith("API ํธ์ถ ์คํจ"):
|
619 |
+
results.append(f"์ ๋ชฉ: {title}\n์์ฑ ์คํจ: {blog_content}\n\n")
|
620 |
+
continue
|
621 |
+
|
622 |
+
# ์ ๋ชฉ ๋ฒ์ญ ๋ฐ ์ด๋ฏธ์ง ์์ฑ
|
623 |
+
translated_title = translate_title(title)
|
624 |
+
image_path = generate_image(translated_title)
|
625 |
+
|
626 |
+
# ์ด๋ฏธ์ง ๋งํฌ๋ฅผ ๋ธ๋ก๊ทธ ๋ด์ฉ ๋์ ์ถ๊ฐ
|
627 |
+
blog_content += f"\n\n[์์ฑ๋ ์ด๋ฏธ์ง]({image_path})"
|
628 |
+
|
629 |
+
# ํฌ์คํ
์ ์ก
|
630 |
+
send_result = send_to_blogger(title, blog_content)
|
631 |
+
|
632 |
+
results.append(f"์ ๋ชฉ: {title}\n์ ์ก ๊ฒฐ๊ณผ: {send_result}\n์์ฑ๋ ์ด๋ฏธ์ง: {image_path}\n\n")
|
633 |
+
except Exception as e:
|
634 |
+
results.append(f"์ ๋ชฉ: {title}\n์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}\n\n")
|
635 |
|
636 |
+
time.sleep(5) # API ํธ์ถ ์ฌ์ด์ 5์ด ๋๊ธฐ
|
637 |
+
|
638 |
+
return "\n".join(results)
|
639 |
+
|
640 |
+
|
641 |
with gr.Blocks() as demo:
|
642 |
gr.Markdown(f"# {title}")
|
643 |
|
|
|
651 |
gr.Markdown("### 3๋จ๊ณ : ๋ธ๋ก๊ทธ ์ฃผ์ , ๋๋ ํค์๋๋ฅผ ์์ธํ ์
๋ ฅํ์ธ์")
|
652 |
topic = gr.Textbox(label="๋ธ๋ก๊ทธ ์ฃผ์ ", placeholder="์์: 8์ ๊ตญ๋ด ์ฌํ์ง ์ถ์ฒ")
|
653 |
|
654 |
+
gr.Markdown("### 4๋จ๊ณ : ์์ฑํ ์ ๋ชฉ ์๋ฅผ ์ ํํ์ธ์")
|
655 |
+
num_titles = gr.Slider(minimum=1, maximum=100, value=2, step=1, label="์์ฑํ ์ ๋ชฉ ์")
|
656 |
+
|
657 |
start_btn = gr.Button("์์")
|
658 |
result_output = gr.Textbox(label="์ฒ๋ฆฌ ๊ฒฐ๊ณผ", lines=20)
|
659 |
+
generated_image = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง")
|
660 |
|
661 |
start_btn.click(
|
662 |
fn=process_all_titles,
|
663 |
+
inputs=[category, style, topic, num_titles],
|
664 |
+
outputs=[result_output, generated_image]
|
665 |
)
|
666 |
|
667 |
category.change(fn=update_prompts_and_description, inputs=[category, style], outputs=[style_description])
|