Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,8 @@ import re
|
|
11 |
logging.basicConfig(filename='youtube_script_extractor.log', level=logging.DEBUG,
|
12 |
format='%(asctime)s - %(levelname)s - %(message)s')
|
13 |
|
|
|
|
|
14 |
def parse_api_response(response):
|
15 |
try:
|
16 |
if isinstance(response, str):
|
@@ -68,8 +70,6 @@ def get_youtube_script(url):
|
|
68 |
logging.exception(error_msg)
|
69 |
return "", "", []
|
70 |
|
71 |
-
openai.api_key = os.getenv("OPENAI_API_KEY")
|
72 |
-
|
73 |
def call_api(prompt, max_tokens, temperature, top_p):
|
74 |
try:
|
75 |
response = openai.ChatCompletion.create(
|
@@ -155,6 +155,8 @@ with gr.Blocks() as demo:
|
|
155 |
return title, script, sections, new_cache
|
156 |
|
157 |
def display_script(title, script):
|
|
|
|
|
158 |
formatted_script = "\n".join(split_sentences(script))
|
159 |
script_html = f"""<h2 style='font-size:24px;'>{title}</h2>
|
160 |
<details>
|
@@ -164,6 +166,8 @@ with gr.Blocks() as demo:
|
|
164 |
return script_html
|
165 |
|
166 |
def display_timeline(sections):
|
|
|
|
|
167 |
timeline_summary = generate_timeline_summary(sections)
|
168 |
timeline_html = f"""
|
169 |
<h3>νμλΌμΈ μμ½:</h3>
|
@@ -174,6 +178,8 @@ with gr.Blocks() as demo:
|
|
174 |
return timeline_html
|
175 |
|
176 |
def generate_summary(script):
|
|
|
|
|
177 |
summary = summarize_text(script)
|
178 |
summary_html = f"""
|
179 |
<h3>μ 체 μμ½:</h3>
|
@@ -187,21 +193,13 @@ with gr.Blocks() as demo:
|
|
187 |
title, script, sections, new_cache = extract_and_cache(url, cache)
|
188 |
script_html = display_script(title, script)
|
189 |
timeline_html = display_timeline(sections)
|
190 |
-
|
191 |
-
|
192 |
-
def update_summary(cache):
|
193 |
-
if not cache["script"]:
|
194 |
-
return "μ€ν¬λ¦½νΈκ° μμ΅λλ€. λ¨Όμ YouTube URLμ μ
λ ₯νκ³ λΆμμ μ€νν΄μ£ΌμΈμ."
|
195 |
-
return generate_summary(cache["script"])
|
196 |
|
197 |
analyze_button.click(
|
198 |
analyze,
|
199 |
inputs=[youtube_url_input, cached_data],
|
200 |
-
outputs=[script_output, timeline_output, cached_data]
|
201 |
-
).then(
|
202 |
-
update_summary,
|
203 |
-
inputs=[cached_data],
|
204 |
-
outputs=summary_output
|
205 |
)
|
206 |
|
207 |
demo.launch(share=True)
|
|
|
11 |
logging.basicConfig(filename='youtube_script_extractor.log', level=logging.DEBUG,
|
12 |
format='%(asctime)s - %(levelname)s - %(message)s')
|
13 |
|
14 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
15 |
+
|
16 |
def parse_api_response(response):
|
17 |
try:
|
18 |
if isinstance(response, str):
|
|
|
70 |
logging.exception(error_msg)
|
71 |
return "", "", []
|
72 |
|
|
|
|
|
73 |
def call_api(prompt, max_tokens, temperature, top_p):
|
74 |
try:
|
75 |
response = openai.ChatCompletion.create(
|
|
|
155 |
return title, script, sections, new_cache
|
156 |
|
157 |
def display_script(title, script):
|
158 |
+
if not script:
|
159 |
+
return "<p>μ€ν¬λ¦½νΈλ₯Ό μΆμΆνμ§ λͺ»νμ΅λλ€. URLμ νμΈνκ³ λ€μ μλν΄ μ£ΌμΈμ.</p>"
|
160 |
formatted_script = "\n".join(split_sentences(script))
|
161 |
script_html = f"""<h2 style='font-size:24px;'>{title}</h2>
|
162 |
<details>
|
|
|
166 |
return script_html
|
167 |
|
168 |
def display_timeline(sections):
|
169 |
+
if not sections:
|
170 |
+
return "<p>νμλΌμΈμ μμ±νμ§ λͺ»νμ΅λλ€. μ€ν¬λ¦½νΈ μΆμΆμ μ€ν¨νμ μ μμ΅λλ€.</p>"
|
171 |
timeline_summary = generate_timeline_summary(sections)
|
172 |
timeline_html = f"""
|
173 |
<h3>νμλΌμΈ μμ½:</h3>
|
|
|
178 |
return timeline_html
|
179 |
|
180 |
def generate_summary(script):
|
181 |
+
if not script:
|
182 |
+
return "<p>μ 체 μμ½μ μμ±νμ§ λͺ»νμ΅λλ€. μ€ν¬λ¦½νΈ μΆμΆμ μ€ν¨νμ μ μμ΅λλ€.</p>"
|
183 |
summary = summarize_text(script)
|
184 |
summary_html = f"""
|
185 |
<h3>μ 체 μμ½:</h3>
|
|
|
193 |
title, script, sections, new_cache = extract_and_cache(url, cache)
|
194 |
script_html = display_script(title, script)
|
195 |
timeline_html = display_timeline(sections)
|
196 |
+
summary_html = generate_summary(script)
|
197 |
+
return script_html, timeline_html, summary_html, new_cache
|
|
|
|
|
|
|
|
|
198 |
|
199 |
analyze_button.click(
|
200 |
analyze,
|
201 |
inputs=[youtube_url_input, cached_data],
|
202 |
+
outputs=[script_output, timeline_output, summary_output, cached_data]
|
|
|
|
|
|
|
|
|
203 |
)
|
204 |
|
205 |
demo.launch(share=True)
|