|
import os |
|
import gradio as gr |
|
|
|
|
|
def load_hidden_modules(): |
|
"""ํ๊ฒฝ๋ณ์์์ ๋ชจ๋ ์ฝ๋๋ค์ ๊ฐ์ ธ์์ ์คํ (์์กด์ฑ ์์ ๊ณ ๋ ค)""" |
|
|
|
|
|
youtube_transcript_code = os.environ.get("YOUTUBE_TRANSCRIPT_MODULE_CODE", "") |
|
if youtube_transcript_code: |
|
|
|
cleaned_code = youtube_transcript_code.replace("from youtube_transcript_module import", "# from youtube_transcript_module import") |
|
exec(cleaned_code, globals()) |
|
|
|
|
|
analyze_module_code = os.environ.get("ANALYZE_MODULE_CODE", "") |
|
if analyze_module_code: |
|
|
|
cleaned_code = analyze_module_code.replace("from youtube_transcript_module import YouTubeTranscriptClient", "# from youtube_transcript_module import YouTubeTranscriptClient") |
|
cleaned_code = cleaned_code.replace("def get_youtube_script(", "def get_youtube_script_analyze(") |
|
cleaned_code = cleaned_code.replace("get_youtube_script(url)", "get_youtube_script_analyze(url)") |
|
exec(cleaned_code, globals()) |
|
|
|
|
|
module_configs = [ |
|
("GENERAL_BLOG_MODULE_CODE", "general", "general_process_youtube_url"), |
|
("HEALTH_BLOG_MODULE_CODE", "health", "health_process_youtube_url"), |
|
("TRAVEL_BLOG_MODULE_CODE", "travel", "travel_process_youtube_url"), |
|
("PRODUCT_REVIEW_MODULE_CODE", "product", "product_process_youtube_url") |
|
] |
|
|
|
for env_key, prefix, func_name in module_configs: |
|
module_code = os.environ.get(env_key, "") |
|
if module_code: |
|
|
|
cleaned_code = module_code.replace("from youtube_transcript_module import YouTubeTranscriptClient", "# from youtube_transcript_module import YouTubeTranscriptClient") |
|
cleaned_code = cleaned_code.replace("def get_youtube_script(", f"def get_youtube_script_{prefix}(") |
|
cleaned_code = cleaned_code.replace("get_youtube_script(url)", f"get_youtube_script_{prefix}(url)") |
|
cleaned_code = cleaned_code.replace("def process_youtube_url(", f"def {func_name}(") |
|
exec(cleaned_code, globals()) |
|
|
|
|
|
load_hidden_modules() |
|
|
|
|
|
def analyze_video(url): |
|
"""๋ถ์ API ์๋ํฌ์ธํธ - ๊ธฐ์กด ํ์ ์ ์ง""" |
|
results = analyze(url) |
|
|
|
|
|
last_result = None |
|
for result in results: |
|
last_result = result |
|
|
|
|
|
return [last_result[0], last_result[1], last_result[2]] |
|
|
|
def process_youtube_url(url, style): |
|
"""์ผ๋ฐ ๋ธ๋ก๊ทธ API ์๋ํฌ์ธํธ - ๊ธฐ์กด ํ์ ์ ์ง""" |
|
|
|
process_func = globals().get('general_process_youtube_url') |
|
if not process_func: |
|
return ["", "์ผ๋ฐ ๋ธ๋ก๊ทธ ๋ชจ๋์ ์ฐพ์ ์ ์์ต๋๋ค."] |
|
|
|
results = process_func(url, style) |
|
|
|
|
|
last_result = None |
|
for result in results: |
|
last_result = result |
|
|
|
|
|
return [last_result[0], last_result[1]] |
|
|
|
def process_youtube_url_v1_2(url, style): |
|
"""์ํ๊ฑด๊ฐ ๋ธ๋ก๊ทธ API ์๋ํฌ์ธํธ - ๊ธฐ์กด ํ์ ์ ์ง""" |
|
|
|
process_func = globals().get('health_process_youtube_url') |
|
if not process_func: |
|
return ["", "์ํ๊ฑด๊ฐ ๋ธ๋ก๊ทธ ๋ชจ๋์ ์ฐพ์ ์ ์์ต๋๋ค."] |
|
|
|
results = process_func(url, style) |
|
|
|
|
|
last_result = None |
|
for result in results: |
|
last_result = result |
|
|
|
|
|
return [last_result[0], last_result[1]] |
|
|
|
def process_youtube_url_v2(url, style): |
|
"""์ฌํ ๋ธ๋ก๊ทธ API ์๋ํฌ์ธํธ - ๊ธฐ์กด ํ์ ์ ์ง""" |
|
|
|
process_func = globals().get('travel_process_youtube_url') |
|
if not process_func: |
|
return ["", "์ฌํ ๋ธ๋ก๊ทธ ๋ชจ๋์ ์ฐพ์ ์ ์์ต๋๋ค."] |
|
|
|
results = process_func(url, style) |
|
|
|
|
|
last_result = None |
|
for result in results: |
|
last_result = result |
|
|
|
|
|
return [last_result[0], last_result[1]] |
|
|
|
def process_youtube_url_v3(url, style): |
|
"""์ํํ๊ธฐ ๋ธ๋ก๊ทธ API ์๋ํฌ์ธํธ - ๊ธฐ์กด ํ์ ์ ์ง""" |
|
|
|
process_func = globals().get('product_process_youtube_url') |
|
if not process_func: |
|
return ["", "์ํํ๊ธฐ ๋ธ๋ก๊ทธ ๋ชจ๋์ ์ฐพ์ ์ ์์ต๋๋ค."] |
|
|
|
results = process_func(url, style) |
|
|
|
|
|
last_result = None |
|
for result in results: |
|
last_result = result |
|
|
|
|
|
return [last_result[0], last_result[1]] |
|
|
|
|
|
with gr.Blocks(css=""" |
|
.thumbnail-container { |
|
display: flex; |
|
justify-content: center; |
|
margin-bottom: 15px; |
|
border-radius: 8px; |
|
overflow: hidden; |
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); |
|
} |
|
.thumbnail-container img { |
|
max-width: 100%; |
|
height: auto; |
|
object-fit: cover; |
|
} |
|
.script-box { |
|
border: 1px solid #e0e0e0; |
|
padding: 15px; |
|
border-radius: 8px; |
|
background-color: #f9f9f9; |
|
margin-bottom: 15px; |
|
} |
|
.output-title { |
|
font-size: 18px; |
|
font-weight: bold; |
|
margin-bottom: 10px; |
|
color: #333; |
|
} |
|
details summary { |
|
cursor: pointer; |
|
font-weight: bold; |
|
padding: 8px 0; |
|
color: #2196F3; |
|
} |
|
li { |
|
margin-bottom: 5px; |
|
} |
|
.error-box { |
|
border: 1px solid #ff4444; |
|
padding: 15px; |
|
border-radius: 8px; |
|
background-color: #ffeeee; |
|
margin-bottom: 15px; |
|
color: #cc0000; |
|
} |
|
""") as demo: |
|
with gr.Tabs(): |
|
|
|
with gr.TabItem("์ ํ๋ธ ์์ฝ"): |
|
gr.Markdown("### YouTube URL ์
๋ ฅ") |
|
with gr.Row(): |
|
url_input = gr.Textbox(label="YouTube URL ์
๋ ฅ", placeholder="https://www.youtube.com/watch?v=example") |
|
|
|
|
|
script_output = gr.HTML(label="์๋ฌธ ์คํฌ๋ฆฝํธ") |
|
summary_output = gr.HTML(label="์์ฝ") |
|
thumbnail_output = gr.Image(label="์ธ๋ค์ผ", show_label=True) |
|
|
|
|
|
analyze_button = gr.Button("๋ถ์ ์คํ") |
|
analyze_button.click(analyze_video, inputs=[url_input], outputs=[script_output, summary_output, thumbnail_output]) |
|
|
|
|
|
with gr.TabItem("์ผ๋ฐ ๋ธ๋ก๊ทธ"): |
|
gr.Markdown("### YouTube URL๊ณผ ํฌ์คํ
์คํ์ผ ์
๋ ฅ") |
|
with gr.Row(): |
|
youtube_url_input = gr.Textbox(label="YouTube URL ์
๋ ฅ", placeholder="https://www.youtube.com/watch?v=example") |
|
style_input = gr.Radio(["์น๊ทผํ", "์ผ๋ฐ์ ์ธ", "์ ๋ฌธ์ ์ธ"], label="ํฌ์คํ
์คํ์ผ", value="์น๊ทผํ") |
|
|
|
|
|
script_output = gr.HTML(label="์๋ฌธ ์คํฌ๋ฆฝํธ") |
|
blog_output = gr.HTML(label="์์ฑ๋ ๋ธ๋ก๊ทธ ๊ธ") |
|
|
|
|
|
generate_blog_button = gr.Button("๋ธ๋ก๊ทธ ๊ธ ์์ฑ") |
|
generate_blog_button.click(process_youtube_url, inputs=[youtube_url_input, style_input], outputs=[script_output, blog_output]) |
|
|
|
|
|
with gr.TabItem("์ํ๊ฑด๊ฐ ๋ธ๋ก๊ทธ"): |
|
gr.Markdown("### YouTube URL๊ณผ ํฌ์คํ
์คํ์ผ ์
๋ ฅ") |
|
with gr.Row(): |
|
youtube_url_input_v1_2 = gr.Textbox(label="YouTube URL ์
๋ ฅ", placeholder="https://www.youtube.com/watch?v=example") |
|
style_input_v1_2 = gr.Radio(["์น๊ทผํ", "์ผ๋ฐ์ ์ธ", "์ ๋ฌธ์ ์ธ"], label="ํฌ์คํ
์คํ์ผ", value="์น๊ทผํ") |
|
|
|
|
|
script_output_v1_2 = gr.HTML(label="์๋ฌธ ์คํฌ๋ฆฝํธ") |
|
blog_output_v1_2 = gr.HTML(label="์์ฑ๋ ๋ธ๋ก๊ทธ ๊ธ") |
|
|
|
|
|
generate_blog_button_v1_2 = gr.Button("๋ธ๋ก๊ทธ ๊ธ ์์ฑ") |
|
generate_blog_button_v1_2.click(process_youtube_url_v1_2, inputs=[youtube_url_input_v1_2, style_input_v1_2], outputs=[script_output_v1_2, blog_output_v1_2]) |
|
|
|
|
|
with gr.TabItem("์ฌํ ๋ธ๋ก๊ทธ"): |
|
gr.Markdown("### YouTube URL๊ณผ ํฌ์คํ
์คํ์ผ ์
๋ ฅ") |
|
with gr.Row(): |
|
youtube_url_input_v2 = gr.Textbox(label="YouTube URL ์
๋ ฅ", placeholder="https://www.youtube.com/watch?v=example") |
|
style_input_v2 = gr.Radio(["์น๊ทผํ", "์ผ๋ฐ์ ์ธ", "์ ๋ฌธ์ ์ธ"], label="ํฌ์คํ
์คํ์ผ", value="์น๊ทผํ") |
|
|
|
|
|
script_output_v2 = gr.HTML(label="์๋ฌธ ์คํฌ๋ฆฝํธ") |
|
blog_output_v2 = gr.HTML(label="์์ฑ๋ ๋ธ๋ก๊ทธ ๊ธ") |
|
|
|
|
|
generate_blog_button_v2 = gr.Button("๋ธ๋ก๊ทธ ๊ธ ์์ฑ") |
|
generate_blog_button_v2.click(process_youtube_url_v2, inputs=[youtube_url_input_v2, style_input_v2], outputs=[script_output_v2, blog_output_v2]) |
|
|
|
|
|
with gr.TabItem("์ํํ๊ธฐ ๋ธ๋ก๊ทธ"): |
|
gr.Markdown("### YouTube URL๊ณผ ํฌ์คํ
์คํ์ผ ์
๋ ฅ") |
|
with gr.Row(): |
|
youtube_url_input_v3 = gr.Textbox(label="YouTube URL ์
๋ ฅ", placeholder="https://www.youtube.com/watch?v=example") |
|
style_input_v3 = gr.Radio(["์น๊ทผํ", "์ผ๋ฐ์ ์ธ", "์ ๋ฌธ์ ์ธ"], label="ํฌ์คํ
์คํ์ผ", value="์น๊ทผํ") |
|
|
|
|
|
script_output_v3 = gr.HTML(label="์๋ฌธ ์คํฌ๋ฆฝํธ") |
|
blog_output_v3 = gr.HTML(label="์์ฑ๋ ๋ธ๋ก๊ทธ ๊ธ") |
|
|
|
|
|
generate_blog_button_v3 = gr.Button("๋ธ๋ก๊ทธ ๊ธ ์์ฑ") |
|
generate_blog_button_v3.click(process_youtube_url_v3, inputs=[youtube_url_input_v3, style_input_v3], outputs=[script_output_v3, blog_output_v3]) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch() |