Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,6 +28,32 @@ def get_youtube_script(url):
|
|
| 28 |
api_name="/predict"
|
| 29 |
)
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
if not isinstance(result, str):
|
| 32 |
result = str(result)
|
| 33 |
|
|
@@ -35,10 +61,10 @@ def get_youtube_script(url):
|
|
| 35 |
raise ValueError("์ถ์ถ๋ ์คํฌ๋ฆฝํธ๊ฐ ์์ต๋๋ค.")
|
| 36 |
|
| 37 |
title = "์ ๋ชฉ ์์"
|
| 38 |
-
description = "์ค๋ช
์์"
|
| 39 |
transcription_text = result
|
| 40 |
|
| 41 |
-
|
|
|
|
| 42 |
except Exception as e:
|
| 43 |
raise ValueError(f"์คํฌ๋ฆฝํธ ์ถ์ถ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
| 44 |
|
|
@@ -181,6 +207,7 @@ def get_blog_prompt():
|
|
| 181 |
10. ์ฐธ๊ณ ๊ธ์์ '๋งํฌ๋ฅผ ํ์ธํด์ฃผ์ธ์'์ ๊ฐ์ ๋งํฌ ์ด๋์ ๋ฌธ๊ตฌ๋ ์ ์ธ
|
| 182 |
11. ์ฐธ๊ณ ๊ธ์ ์๋ ์์ฑ์, ํ์, ์ ํ๋ฒ, ๊ธฐ์(Writer, speaker, YouTuber, reporter)์ ์ด๋ฆ, ์ ์นญ, ๋๋ค์(Name, Nkickname)์ ๋ฐ๋์ ์ ์ธ
|
| 183 |
12. '์
์ฒด๋ก ๋ถํฐ ์ ๊ณต ๋ฐ์์ ์์ฑ', '์ฟ ํก ํํธ๋์ค'๋ฑ์ ํํ์ ๋ฐ๋์ ์ ์ธํ๋ผ.
|
|
|
|
| 184 |
[์ฌํ ๋ธ๋ก๊ทธ ๊ธ ์์ฑ ํ์ ๊ท์น]
|
| 185 |
1. ๋ธ๋ก๊ทธ ์์ฑ์๊ฐ ์ง์ ๊ฒฝํํ๊ณ ๋๋ ๋ด์ฉ๋ง ์์ฑํ์ธ์.
|
| 186 |
2. ์ค๊ฐ์ ๊ธฐ๋ฐํ ์์ํ ๋ฌ์ฌ ๋ฐ ์ค์ฉ ์ ๋ณด ํฌํจ
|
|
@@ -410,15 +437,14 @@ def save_pdf(blog_post):
|
|
| 410 |
filename = save_to_pdf(content, title)
|
| 411 |
return filename
|
| 412 |
|
| 413 |
-
# ๋ฉ์ธ ํจ์
|
| 414 |
def process_youtube_url(url, style):
|
| 415 |
max_retries = 2
|
| 416 |
retry_count = 0
|
| 417 |
|
| 418 |
while retry_count <= max_retries:
|
| 419 |
try:
|
| 420 |
-
# YouTube ์คํฌ๋ฆฝํธ ์ถ์ถ
|
| 421 |
-
title,
|
| 422 |
|
| 423 |
# ์คํฌ๋ฆฝํธ ๊ฒ์ฆ
|
| 424 |
if not script or not script.strip():
|
|
@@ -429,8 +455,8 @@ def process_youtube_url(url, style):
|
|
| 429 |
# ์คํฌ๋ฆฝํธ ๋ด์ฉ๋ง ๋จผ์ ๋ฐํ
|
| 430 |
yield script_content, "๋ธ๋ก๊ทธ ๊ธ์ ์์ฑํ๋ ์ค์
๋๋ค..."
|
| 431 |
|
| 432 |
-
# ๋ธ๋ก๊ทธ ๊ธ ์์ฑ
|
| 433 |
-
blog_post = generate_blog_post(script, title,
|
| 434 |
|
| 435 |
# ์์ฑ๋ ๋ธ๋ก๊ทธ ๊ธ ๋ฐํ
|
| 436 |
yield script_content, blog_post
|
|
@@ -445,8 +471,6 @@ def process_youtube_url(url, style):
|
|
| 445 |
yield f"์๋ง์ ์ฐพ์ ์ ์์ต๋๋ค. ์์์ ์๋ง์ด ์๊ฑฐ๋ ์๋ง์ ๊ฐ์ ธ์ค๋ ๋ฐ ์คํจํ์ต๋๋ค. ์ค๋ฅ: {str(e)}", ""
|
| 446 |
return
|
| 447 |
|
| 448 |
-
yield "์ต๋ ์ฌ์๋ ํ์๋ฅผ ์ด๊ณผํ์ต๋๋ค. ์๋ง์ ๊ฐ์ ธ์ค์ง ๋ชปํ์ต๋๋ค.", ""
|
| 449 |
-
|
| 450 |
# Gradio ์ธํฐํ์ด์ค
|
| 451 |
with gr.Blocks() as demo:
|
| 452 |
gr.Markdown("## ์ ํ๋ธ -> ๋ธ๋ก๊ทธ - ์ฌํ")
|
|
|
|
| 28 |
api_name="/predict"
|
| 29 |
)
|
| 30 |
|
| 31 |
+
# ๊ฒฐ๊ณผ๊ฐ JSON ํ์์ด๋ผ๋ฉด ํ์ฑํ์ฌ title๊ณผ transcriptionAsText๋ง ์ถ์ถ
|
| 32 |
+
if isinstance(result, dict) or (isinstance(result, str) and result.strip().startswith('{')):
|
| 33 |
+
if isinstance(result, str):
|
| 34 |
+
import json
|
| 35 |
+
try:
|
| 36 |
+
result = json.loads(result)
|
| 37 |
+
except:
|
| 38 |
+
pass
|
| 39 |
+
|
| 40 |
+
# JSON ๊ตฌ์กฐ์์ ๋ฐ์ดํฐ ์ถ์ถ
|
| 41 |
+
if isinstance(result, dict):
|
| 42 |
+
if 'data' in result and isinstance(result['data'], list) and len(result['data']) > 0:
|
| 43 |
+
data = result['data'][0]
|
| 44 |
+
title = data.get('title', "์ ๋ชฉ ์์")
|
| 45 |
+
transcription_text = data.get('transcriptionAsText', "")
|
| 46 |
+
|
| 47 |
+
# description์ ๋ฐํํ์ง ์์
|
| 48 |
+
return title, transcription_text
|
| 49 |
+
elif 'title' in result and 'transcriptionAsText' in result:
|
| 50 |
+
title = result.get('title', "์ ๋ชฉ ์์")
|
| 51 |
+
transcription_text = result.get('transcriptionAsText', "")
|
| 52 |
+
|
| 53 |
+
# description์ ๋ฐํํ์ง ์์
|
| 54 |
+
return title, transcription_text
|
| 55 |
+
|
| 56 |
+
# JSON์ด ์๋ ๊ฒฝ์ฐ ๊ฐ๋จํ๊ฒ ์ฒ๋ฆฌ
|
| 57 |
if not isinstance(result, str):
|
| 58 |
result = str(result)
|
| 59 |
|
|
|
|
| 61 |
raise ValueError("์ถ์ถ๋ ์คํฌ๋ฆฝํธ๊ฐ ์์ต๋๋ค.")
|
| 62 |
|
| 63 |
title = "์ ๋ชฉ ์์"
|
|
|
|
| 64 |
transcription_text = result
|
| 65 |
|
| 66 |
+
# description์ ๋ฐํํ์ง ์์
|
| 67 |
+
return title, transcription_text
|
| 68 |
except Exception as e:
|
| 69 |
raise ValueError(f"์คํฌ๋ฆฝํธ ์ถ์ถ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
| 70 |
|
|
|
|
| 207 |
10. ์ฐธ๊ณ ๊ธ์์ '๋งํฌ๋ฅผ ํ์ธํด์ฃผ์ธ์'์ ๊ฐ์ ๋งํฌ ์ด๋์ ๋ฌธ๊ตฌ๋ ์ ์ธ
|
| 208 |
11. ์ฐธ๊ณ ๊ธ์ ์๋ ์์ฑ์, ํ์, ์ ํ๋ฒ, ๊ธฐ์(Writer, speaker, YouTuber, reporter)์ ์ด๋ฆ, ์ ์นญ, ๋๋ค์(Name, Nkickname)์ ๋ฐ๋์ ์ ์ธ
|
| 209 |
12. '์
์ฒด๋ก ๋ถํฐ ์ ๊ณต ๋ฐ์์ ์์ฑ', '์ฟ ํก ํํธ๋์ค'๋ฑ์ ํํ์ ๋ฐ๋์ ์ ์ธํ๋ผ.
|
| 210 |
+
|
| 211 |
[์ฌํ ๋ธ๋ก๊ทธ ๊ธ ์์ฑ ํ์ ๊ท์น]
|
| 212 |
1. ๋ธ๋ก๊ทธ ์์ฑ์๊ฐ ์ง์ ๊ฒฝํํ๊ณ ๋๋ ๋ด์ฉ๋ง ์์ฑํ์ธ์.
|
| 213 |
2. ์ค๊ฐ์ ๊ธฐ๋ฐํ ์์ํ ๋ฌ์ฌ ๋ฐ ์ค์ฉ ์ ๋ณด ํฌํจ
|
|
|
|
| 437 |
filename = save_to_pdf(content, title)
|
| 438 |
return filename
|
| 439 |
|
|
|
|
| 440 |
def process_youtube_url(url, style):
|
| 441 |
max_retries = 2
|
| 442 |
retry_count = 0
|
| 443 |
|
| 444 |
while retry_count <= max_retries:
|
| 445 |
try:
|
| 446 |
+
# YouTube ์คํฌ๋ฆฝํธ ์ถ์ถ (์ด์ title๊ณผ script๋ง ๋ฐํ)
|
| 447 |
+
title, script = get_youtube_script(url)
|
| 448 |
|
| 449 |
# ์คํฌ๋ฆฝํธ ๊ฒ์ฆ
|
| 450 |
if not script or not script.strip():
|
|
|
|
| 455 |
# ์คํฌ๋ฆฝํธ ๋ด์ฉ๋ง ๋จผ์ ๋ฐํ
|
| 456 |
yield script_content, "๋ธ๋ก๊ทธ ๊ธ์ ์์ฑํ๋ ์ค์
๋๋ค..."
|
| 457 |
|
| 458 |
+
# ๋ธ๋ก๊ทธ ๊ธ ์์ฑ (description์ ๋น ๋ฌธ์์ด๋ก ์ค์ )
|
| 459 |
+
blog_post = generate_blog_post(script, title, "", style)
|
| 460 |
|
| 461 |
# ์์ฑ๋ ๋ธ๋ก๊ทธ ๊ธ ๋ฐํ
|
| 462 |
yield script_content, blog_post
|
|
|
|
| 471 |
yield f"์๋ง์ ์ฐพ์ ์ ์์ต๋๋ค. ์์์ ์๋ง์ด ์๊ฑฐ๋ ์๋ง์ ๊ฐ์ ธ์ค๋ ๋ฐ ์คํจํ์ต๋๋ค. ์ค๋ฅ: {str(e)}", ""
|
| 472 |
return
|
| 473 |
|
|
|
|
|
|
|
| 474 |
# Gradio ์ธํฐํ์ด์ค
|
| 475 |
with gr.Blocks() as demo:
|
| 476 |
gr.Markdown("## ์ ํ๋ธ -> ๋ธ๋ก๊ทธ - ์ฌํ")
|