Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,37 +37,16 @@ def get_youtube_script(url):
|
|
| 37 |
data = parsed_result["data"][0]
|
| 38 |
title = data.get("title", "์ ๋ชฉ ์์")
|
| 39 |
transcription_text = data.get("transcriptionAsText", "")
|
| 40 |
-
sections = data.get("sections", [])
|
| 41 |
|
| 42 |
if not transcription_text:
|
| 43 |
raise ValueError("์ถ์ถ๋ ์คํฌ๋ฆฝํธ๊ฐ ์์ต๋๋ค.")
|
| 44 |
|
| 45 |
logging.info("์คํฌ๋ฆฝํธ ์ถ์ถ ์๋ฃ")
|
| 46 |
-
return title, transcription_text
|
| 47 |
except Exception as e:
|
| 48 |
logging.exception("์คํฌ๋ฆฝํธ ์ถ์ถ ์ค ์ค๋ฅ ๋ฐ์")
|
| 49 |
raise
|
| 50 |
|
| 51 |
-
def format_time(seconds):
|
| 52 |
-
minutes, seconds = divmod(seconds, 60)
|
| 53 |
-
hours, minutes = divmod(minutes, 60)
|
| 54 |
-
return f"{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}"
|
| 55 |
-
|
| 56 |
-
def generate_timeline_summary(sections):
|
| 57 |
-
timeline_items = []
|
| 58 |
-
for section in sections:
|
| 59 |
-
start_time = format_time(section['start_time'])
|
| 60 |
-
text = section['text']
|
| 61 |
-
timeline_items.append(f"<p><strong>{start_time}</strong>: {text}</p>")
|
| 62 |
-
|
| 63 |
-
timeline_html = "\n".join(timeline_items)
|
| 64 |
-
return f"""
|
| 65 |
-
<h3>ํ์๋ผ์ธ ์์ฝ:</h3>
|
| 66 |
-
<div style="white-space: pre-wrap; max-height: 400px; overflow-y: auto; border: 1px solid #ccc; padding: 10px;">
|
| 67 |
-
{timeline_html}
|
| 68 |
-
</div>
|
| 69 |
-
"""
|
| 70 |
-
|
| 71 |
def call_api(prompt, max_tokens, temperature, top_p):
|
| 72 |
try:
|
| 73 |
response = openai.ChatCompletion.create(
|
|
@@ -111,22 +90,21 @@ def analyze(url, cache):
|
|
| 111 |
try:
|
| 112 |
if url == cache["url"]:
|
| 113 |
logging.info(f"์บ์๋ ๋ฐ์ดํฐ ์ฌ์ฉ: URL = {url}")
|
| 114 |
-
title, script
|
| 115 |
else:
|
| 116 |
logging.info(f"์๋ก์ด ๋ฐ์ดํฐ ์ถ์ถ ์์: URL = {url}")
|
| 117 |
-
title, script
|
| 118 |
-
cache = {"url": url, "title": title, "script": script
|
| 119 |
|
| 120 |
script_html = display_script(title, script)
|
| 121 |
-
timeline_html = generate_timeline_summary(sections)
|
| 122 |
summary_html = summarize_text(script)
|
| 123 |
|
| 124 |
logging.info("๋ถ์ ์๋ฃ")
|
| 125 |
-
return script_html,
|
| 126 |
except Exception as e:
|
| 127 |
error_msg = f"์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 128 |
logging.exception(error_msg)
|
| 129 |
-
return error_msg, "",
|
| 130 |
|
| 131 |
# Gradio ์ธํฐํ์ด์ค
|
| 132 |
with gr.Blocks() as demo:
|
|
@@ -134,14 +112,13 @@ with gr.Blocks() as demo:
|
|
| 134 |
youtube_url_input = gr.Textbox(label="YouTube URL ์
๋ ฅ")
|
| 135 |
analyze_button = gr.Button("๋ถ์ํ๊ธฐ")
|
| 136 |
script_output = gr.HTML(label="์คํฌ๋ฆฝํธ")
|
| 137 |
-
timeline_output = gr.HTML(label="ํ์๋ผ์ธ ์์ฝ")
|
| 138 |
summary_output = gr.HTML(label="์ ์ฒด ์์ฝ")
|
| 139 |
-
cached_data = gr.State({"url": "", "title": "", "script": ""
|
| 140 |
|
| 141 |
analyze_button.click(
|
| 142 |
analyze,
|
| 143 |
inputs=[youtube_url_input, cached_data],
|
| 144 |
-
outputs=[script_output,
|
| 145 |
)
|
| 146 |
|
| 147 |
if __name__ == "__main__":
|
|
|
|
| 37 |
data = parsed_result["data"][0]
|
| 38 |
title = data.get("title", "์ ๋ชฉ ์์")
|
| 39 |
transcription_text = data.get("transcriptionAsText", "")
|
|
|
|
| 40 |
|
| 41 |
if not transcription_text:
|
| 42 |
raise ValueError("์ถ์ถ๋ ์คํฌ๋ฆฝํธ๊ฐ ์์ต๋๋ค.")
|
| 43 |
|
| 44 |
logging.info("์คํฌ๋ฆฝํธ ์ถ์ถ ์๋ฃ")
|
| 45 |
+
return title, transcription_text
|
| 46 |
except Exception as e:
|
| 47 |
logging.exception("์คํฌ๋ฆฝํธ ์ถ์ถ ์ค ์ค๋ฅ ๋ฐ์")
|
| 48 |
raise
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
def call_api(prompt, max_tokens, temperature, top_p):
|
| 51 |
try:
|
| 52 |
response = openai.ChatCompletion.create(
|
|
|
|
| 90 |
try:
|
| 91 |
if url == cache["url"]:
|
| 92 |
logging.info(f"์บ์๋ ๋ฐ์ดํฐ ์ฌ์ฉ: URL = {url}")
|
| 93 |
+
title, script = cache["title"], cache["script"]
|
| 94 |
else:
|
| 95 |
logging.info(f"์๋ก์ด ๋ฐ์ดํฐ ์ถ์ถ ์์: URL = {url}")
|
| 96 |
+
title, script = get_youtube_script(url)
|
| 97 |
+
cache = {"url": url, "title": title, "script": script}
|
| 98 |
|
| 99 |
script_html = display_script(title, script)
|
|
|
|
| 100 |
summary_html = summarize_text(script)
|
| 101 |
|
| 102 |
logging.info("๋ถ์ ์๋ฃ")
|
| 103 |
+
return script_html, summary_html, cache
|
| 104 |
except Exception as e:
|
| 105 |
error_msg = f"์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 106 |
logging.exception(error_msg)
|
| 107 |
+
return error_msg, "", cache
|
| 108 |
|
| 109 |
# Gradio ์ธํฐํ์ด์ค
|
| 110 |
with gr.Blocks() as demo:
|
|
|
|
| 112 |
youtube_url_input = gr.Textbox(label="YouTube URL ์
๋ ฅ")
|
| 113 |
analyze_button = gr.Button("๋ถ์ํ๊ธฐ")
|
| 114 |
script_output = gr.HTML(label="์คํฌ๋ฆฝํธ")
|
|
|
|
| 115 |
summary_output = gr.HTML(label="์ ์ฒด ์์ฝ")
|
| 116 |
+
cached_data = gr.State({"url": "", "title": "", "script": ""})
|
| 117 |
|
| 118 |
analyze_button.click(
|
| 119 |
analyze,
|
| 120 |
inputs=[youtube_url_input, cached_data],
|
| 121 |
+
outputs=[script_output, summary_output, cached_data]
|
| 122 |
)
|
| 123 |
|
| 124 |
if __name__ == "__main__":
|