Spaces:
Running
Running
screenshot_paths
Browse files
app.py
CHANGED
@@ -75,25 +75,24 @@ def process_youtube_link(link):
|
|
75 |
df_summarise = generate_df_summarise(transcript)
|
76 |
|
77 |
formatted_transcript = []
|
|
|
78 |
for entry in transcript:
|
79 |
start_time = format_seconds_to_time(entry['start'])
|
80 |
end_time = format_seconds_to_time(entry['start'] + entry['duration'])
|
81 |
embed_url = get_embedded_youtube_link(video_id, entry['start'])
|
82 |
# 截圖
|
83 |
screenshot_path = screenshot_youtube_video(video_id, entry['start'])
|
84 |
-
image_path = os.path.join(os.path.dirname(__file__), screenshot_path),
|
85 |
line = {
|
86 |
"start_time": start_time,
|
87 |
"end_time": end_time,
|
88 |
"text": entry['text'],
|
89 |
"embed_url": embed_url,
|
90 |
"time_sec": entry['start'],
|
91 |
-
"
|
92 |
}
|
93 |
formatted_transcript.append(line)
|
|
|
94 |
|
95 |
-
|
96 |
-
|
97 |
html_content = format_transcript_to_html(formatted_transcript)
|
98 |
print("=====html_content=====")
|
99 |
print(html_content)
|
@@ -104,7 +103,8 @@ def process_youtube_link(link):
|
|
104 |
questions[1] if len(questions) > 1 else "", \
|
105 |
questions[2] if len(questions) > 2 else "", \
|
106 |
df_summarise, \
|
107 |
-
html_content
|
|
|
108 |
|
109 |
def format_transcript_to_html(formatted_transcript):
|
110 |
html_content = ""
|
@@ -290,6 +290,9 @@ with gr.Blocks() as demo:
|
|
290 |
with gr.Column():
|
291 |
with gr.Tab("YouTube Transcript and Video"):
|
292 |
transcript_html = gr.HTML(label="YouTube Transcript and Video")
|
|
|
|
|
|
|
293 |
with gr.Tab("資料本文"):
|
294 |
df_string_output = gr.Textbox()
|
295 |
with gr.Tab("資料摘要"):
|
@@ -317,7 +320,7 @@ with gr.Blocks() as demo:
|
|
317 |
file_upload.change(process_file, inputs=file_upload, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
|
318 |
|
319 |
# 当输入 YouTube 链接时触发
|
320 |
-
youtube_link.change(process_youtube_link, inputs=youtube_link, outputs=[btn_1, btn_2, btn_3, df_summarise, transcript_html])
|
321 |
|
322 |
# 当输入网页链接时触发
|
323 |
web_link.change(process_web_link, inputs=web_link, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
|
|
|
75 |
df_summarise = generate_df_summarise(transcript)
|
76 |
|
77 |
formatted_transcript = []
|
78 |
+
screenshot_paths = []
|
79 |
for entry in transcript:
|
80 |
start_time = format_seconds_to_time(entry['start'])
|
81 |
end_time = format_seconds_to_time(entry['start'] + entry['duration'])
|
82 |
embed_url = get_embedded_youtube_link(video_id, entry['start'])
|
83 |
# 截圖
|
84 |
screenshot_path = screenshot_youtube_video(video_id, entry['start'])
|
|
|
85 |
line = {
|
86 |
"start_time": start_time,
|
87 |
"end_time": end_time,
|
88 |
"text": entry['text'],
|
89 |
"embed_url": embed_url,
|
90 |
"time_sec": entry['start'],
|
91 |
+
"screenshot_path": screenshot_path
|
92 |
}
|
93 |
formatted_transcript.append(line)
|
94 |
+
screenshot_paths.append(screenshot_path)
|
95 |
|
|
|
|
|
96 |
html_content = format_transcript_to_html(formatted_transcript)
|
97 |
print("=====html_content=====")
|
98 |
print(html_content)
|
|
|
103 |
questions[1] if len(questions) > 1 else "", \
|
104 |
questions[2] if len(questions) > 2 else "", \
|
105 |
df_summarise, \
|
106 |
+
html_content, \
|
107 |
+
screenshot_paths,
|
108 |
|
109 |
def format_transcript_to_html(formatted_transcript):
|
110 |
html_content = ""
|
|
|
290 |
with gr.Column():
|
291 |
with gr.Tab("YouTube Transcript and Video"):
|
292 |
transcript_html = gr.HTML(label="YouTube Transcript and Video")
|
293 |
+
with gr.Tab("images"):
|
294 |
+
gallery = gr.Gallery(label="截图")
|
295 |
+
|
296 |
with gr.Tab("資料本文"):
|
297 |
df_string_output = gr.Textbox()
|
298 |
with gr.Tab("資料摘要"):
|
|
|
320 |
file_upload.change(process_file, inputs=file_upload, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
|
321 |
|
322 |
# 当输入 YouTube 链接时触发
|
323 |
+
youtube_link.change(process_youtube_link, inputs=youtube_link, outputs=[btn_1, btn_2, btn_3, df_summarise, transcript_html, gallery])
|
324 |
|
325 |
# 当输入网页链接时触发
|
326 |
web_link.change(process_web_link, inputs=web_link, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
|