Update app.py
Browse files
app.py
CHANGED
@@ -16,6 +16,7 @@ import uuid
|
|
16 |
import json
|
17 |
from huggingface_hub.utils._errors import HfHubHTTPError
|
18 |
from gradio_client import Client
|
|
|
19 |
|
20 |
def setup_session():
|
21 |
try:
|
@@ -589,8 +590,7 @@ def process_all_titles(category, style, topic):
|
|
589 |
return "\n".join(results)
|
590 |
|
591 |
|
592 |
-
#
|
593 |
-
image_client = Client("http://hugpu.ai:7899/")
|
594 |
|
595 |
def generate_image(prompt):
|
596 |
try:
|
@@ -598,9 +598,15 @@ def generate_image(prompt):
|
|
598 |
prompt,
|
599 |
api_name="/generate"
|
600 |
)
|
601 |
-
# API ์๋ต์์ ์ด๋ฏธ์ง
|
602 |
-
|
603 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
604 |
return image_url
|
605 |
except Exception as e:
|
606 |
print(f"์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
@@ -622,15 +628,18 @@ def process_all_titles(category, style, topic, num_titles):
|
|
622 |
|
623 |
# ์ด๋ฏธ์ง ์์ฑ
|
624 |
image_url = generate_image(title)
|
625 |
-
|
626 |
if image_url:
|
627 |
# ์ด๋ฏธ์ง URL์ ๋ธ๋ก๊ทธ ๋ด์ฉ ๋์ ์ถ๊ฐ
|
628 |
-
blog_content += f"\n\n[์์ฑ๋ ์ด๋ฏธ์ง]({image_url})"
|
|
|
|
|
629 |
|
630 |
# ํฌ์คํ
์ ์ก
|
631 |
send_result = send_to_blogger(title, blog_content)
|
632 |
-
|
633 |
results.append(f"์ ๋ชฉ: {title}\n์ ์ก ๊ฒฐ๊ณผ: {send_result}\n์์ฑ๋ ์ด๋ฏธ์ง URL: {image_url}\n\n")
|
|
|
634 |
except Exception as e:
|
635 |
results.append(f"์ ๋ชฉ: {title}\n์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}\n\n")
|
636 |
|
|
|
16 |
import json
|
17 |
from huggingface_hub.utils._errors import HfHubHTTPError
|
18 |
from gradio_client import Client
|
19 |
+
from urllib.parse import urljoin
|
20 |
|
21 |
def setup_session():
|
22 |
try:
|
|
|
590 |
return "\n".join(results)
|
591 |
|
592 |
|
593 |
+
BASE_URL = "http://hugpu.ai:7899" # ์ค์ ์๋ฒ ์ฃผ์๋ก ๋ณ๊ฒฝํ์ธ์
|
|
|
594 |
|
595 |
def generate_image(prompt):
|
596 |
try:
|
|
|
598 |
prompt,
|
599 |
api_name="/generate"
|
600 |
)
|
601 |
+
# API ์๋ต์์ ์ด๋ฏธ์ง ๊ฒฝ๋ก๋ฅผ ์ถ์ถํฉ๋๋ค.
|
602 |
+
image_path = result[0] if isinstance(result, list) else result
|
603 |
+
|
604 |
+
# ๋ก์ปฌ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์น URL๋ก ๋ณํ
|
605 |
+
if image_path.startswith('/'):
|
606 |
+
image_url = urljoin(BASE_URL, image_path)
|
607 |
+
else:
|
608 |
+
image_url = image_path
|
609 |
+
|
610 |
return image_url
|
611 |
except Exception as e:
|
612 |
print(f"์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
|
|
628 |
|
629 |
# ์ด๋ฏธ์ง ์์ฑ
|
630 |
image_url = generate_image(title)
|
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์์ฑ๋ ์ด๋ฏธ์ง URL: {image_url}\n\n")
|
642 |
+
|
643 |
except Exception as e:
|
644 |
results.append(f"์ ๋ชฉ: {title}\n์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}\n\n")
|
645 |
|