fantaxy commited on
Commit
8c1642e
ยท
verified ยท
1 Parent(s): d45a028

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -33
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
- results.append(f"์ œ๋ชฉ: {title}\n์ƒ์„ฑ ์‹คํŒจ: {blog_content}\n\n")
655
- continue
656
-
657
- if image_url_1:
658
- img_tag_1 = f'<img src="{image_url_1}" alt="{topic} 1" style="max-width:100%; height:auto;">'
659
- blog_content = f'{img_tag_1}\n\n{blog_content}'
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
- send_result = send_to_blogger(title, blog_content)
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
- results.append(f"์ œ๋ชฉ: {title}\n์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}\n\n")
 
 
675
 
676
- time.sleep(5) # API ํ˜ธ์ถœ ์‚ฌ์ด์— 5์ดˆ ๋Œ€๊ธฐ
677
 
678
- return "\n".join(results)
 
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๋‹จ๊ณ„ : ์ž๋™ ์ƒ์„ฑ ๋ฐ ์ „์†กํ•  ๋ธ”๋กœ๊ทธ ์ˆ˜(๊ณ„์ •๋‹น ์ผ์ผ ํฌ์ŠคํŒ… ์—…๋กœ๋“œ ์ œํ•œ 60๊ฑด๊นŒ์ง€ )")
727
- num_titles = gr.Slider(minimum=1, maximum=60, value=2, step=1, label="ํฌ์ŠคํŒ… ๊ฑด")
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)