fantaxy commited on
Commit
85045b8
ยท
verified ยท
1 Parent(s): 0badce0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
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
- # ์ด๋ฏธ์ง€ ์ƒ์„ฑ API ํด๋ผ์ด์–ธํŠธ ์„ค์ •
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 ์‘๋‹ต์—์„œ ์ด๋ฏธ์ง€ URL์„ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค.
602
- # ์‹ค์ œ ์‘๋‹ต ๊ตฌ์กฐ์— ๋”ฐ๋ผ ์ด ๋ถ€๋ถ„์„ ์กฐ์ •ํ•ด์•ผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
603
- image_url = result[0] if isinstance(result, list) else result
 
 
 
 
 
 
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![์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€]({image_url})"
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