Update app.py
Browse files
app.py
CHANGED
@@ -592,24 +592,27 @@ def process_all_titles(category, style, topic):
|
|
592 |
|
593 |
BASE_URL = "http://hugpu.ai:7899" # ์ค์ ์๋ฒ ์ฃผ์๋ก ๋ณ๊ฒฝํ์ธ์
|
594 |
|
595 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
596 |
try:
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
)
|
601 |
-
# API ์๋ต์์ ์ด๋ฏธ์ง ๊ฒฝ๋ก๋ฅผ ์ถ์ถํฉ๋๋ค.
|
602 |
-
image_path = result[0] if isinstance(result, list) else result
|
603 |
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
else:
|
608 |
-
|
609 |
-
|
610 |
-
return image_url
|
611 |
except Exception as e:
|
612 |
-
print(f"์ด๋ฏธ์ง
|
613 |
return None
|
614 |
|
615 |
# process_all_titles ํจ์ ์์
|
@@ -626,20 +629,19 @@ def process_all_titles(category, style, topic, num_titles):
|
|
626 |
results.append(f"์ ๋ชฉ: {title}\n์์ฑ ์คํจ: {blog_content}\n\n")
|
627 |
continue
|
628 |
|
629 |
-
# ์ด๋ฏธ์ง
|
630 |
-
image_url =
|
631 |
-
|
632 |
if image_url:
|
633 |
# ์ด๋ฏธ์ง URL์ ๋ธ๋ก๊ทธ ๋ด์ฉ ๋์ ์ถ๊ฐ
|
634 |
-
blog_content += f"\n\n![
|
635 |
else:
|
636 |
-
blog_content += "\n\n
|
637 |
|
638 |
# ํฌ์คํ
์ ์ก
|
639 |
send_result = send_to_blogger(title, blog_content)
|
640 |
-
|
641 |
-
results.append(f"์ ๋ชฉ: {title}\n์ ์ก ๊ฒฐ๊ณผ: {send_result}\n
|
642 |
-
|
643 |
except Exception as e:
|
644 |
results.append(f"์ ๋ชฉ: {title}\n์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}\n\n")
|
645 |
|
@@ -647,6 +649,7 @@ def process_all_titles(category, style, topic, num_titles):
|
|
647 |
|
648 |
return "\n".join(results)
|
649 |
|
|
|
650 |
with gr.Blocks() as demo:
|
651 |
gr.Markdown(f"# {title}")
|
652 |
|
|
|
592 |
|
593 |
BASE_URL = "http://hugpu.ai:7899" # ์ค์ ์๋ฒ ์ฃผ์๋ก ๋ณ๊ฒฝํ์ธ์
|
594 |
|
595 |
+
# Pexels API ํด๋ผ์ด์ธํธ ์ค์
|
596 |
+
PEXELS_API_KEY = "5woz23MGx1QrSY0WHFb0BRi29JvbXPu97Hg0xnklYgHUI8G0w23FKH62"
|
597 |
+
pexels_api = API(PEXELS_API_KEY)
|
598 |
+
|
599 |
+
def get_image_url(topic):
|
600 |
+
# ์ฃผ์ ์์ ํต์ฌ ํค์๋ ์ถ์ถ (์ฌ๊ธฐ์๋ ๊ฐ๋จํ ์ฒ์ ๋ ๋จ์ด๋ฅผ ์ฌ์ฉ)
|
601 |
+
keywords = ' '.join(topic.split()[:2])
|
602 |
+
|
603 |
try:
|
604 |
+
# Pexels API๋ฅผ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง ๊ฒ์
|
605 |
+
pexels_api.search(keywords, page=1, results_per_page=1)
|
606 |
+
photos = pexels_api.get_entries()
|
|
|
|
|
|
|
607 |
|
608 |
+
if photos:
|
609 |
+
# ๊ณ ํด์๋ ์ด๋ฏธ์ง URL ๋ฐํ
|
610 |
+
return photos[0].original
|
611 |
else:
|
612 |
+
print(f"'{keywords}' ๊ด๋ จ ์ด๋ฏธ์ง๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.")
|
613 |
+
return None
|
|
|
614 |
except Exception as e:
|
615 |
+
print(f"์ด๋ฏธ์ง ๊ฒ์ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
616 |
return None
|
617 |
|
618 |
# process_all_titles ํจ์ ์์
|
|
|
629 |
results.append(f"์ ๋ชฉ: {title}\n์์ฑ ์คํจ: {blog_content}\n\n")
|
630 |
continue
|
631 |
|
632 |
+
# Pexels API๋ฅผ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง URL ๊ฐ์ ธ์ค๊ธฐ
|
633 |
+
image_url = get_image_url(topic)
|
634 |
+
|
635 |
if image_url:
|
636 |
# ์ด๋ฏธ์ง URL์ ๋ธ๋ก๊ทธ ๋ด์ฉ ๋์ ์ถ๊ฐ
|
637 |
+
blog_content += f"\n\n"
|
638 |
else:
|
639 |
+
blog_content += "\n\n๊ด๋ จ ์ด๋ฏธ์ง๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
|
640 |
|
641 |
# ํฌ์คํ
์ ์ก
|
642 |
send_result = send_to_blogger(title, blog_content)
|
643 |
+
|
644 |
+
results.append(f"์ ๋ชฉ: {title}\n์ ์ก ๊ฒฐ๊ณผ: {send_result}\n์ฌ์ฉ๋ ์ด๋ฏธ์ง URL: {image_url}\n\n")
|
|
|
645 |
except Exception as e:
|
646 |
results.append(f"์ ๋ชฉ: {title}\n์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}\n\n")
|
647 |
|
|
|
649 |
|
650 |
return "\n".join(results)
|
651 |
|
652 |
+
|
653 |
with gr.Blocks() as demo:
|
654 |
gr.Markdown(f"# {title}")
|
655 |
|