Spaces:
Sleeping
Sleeping
def get_LLM_content(video_id, kind):
Browse files
app.py
CHANGED
|
@@ -1410,6 +1410,21 @@ def get_key_moments_html(key_moments):
|
|
| 1410 |
return key_moments_html
|
| 1411 |
|
| 1412 |
# ---- LLM CRUD ----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1413 |
def enable_edit_mode():
|
| 1414 |
return gr.update(interactive=True)
|
| 1415 |
|
|
@@ -2334,8 +2349,9 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 2334 |
with gr.Tab("逐字稿本文"):
|
| 2335 |
with gr.Row() as transcript_admmin:
|
| 2336 |
transcript_kind = gr.Textbox(value="transcript", show_label=False)
|
|
|
|
| 2337 |
transcript_edit_button = gr.Button("編輯", size="sm", variant="primary")
|
| 2338 |
-
transcript_update_button = gr.Button("
|
| 2339 |
transcript_delete_button = gr.Button("刪除", size="sm", variant="primary")
|
| 2340 |
transcript_create_button = gr.Button("建立", size="sm", variant="primary")
|
| 2341 |
with gr.Row():
|
|
@@ -2343,8 +2359,9 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 2343 |
with gr.Tab("關鍵時刻本文"):
|
| 2344 |
with gr.Row() as key_moments_admin:
|
| 2345 |
key_moments_kind = gr.Textbox(value="key_moments", show_label=False)
|
|
|
|
| 2346 |
key_moments_edit_button = gr.Button("編輯", size="sm", variant="primary")
|
| 2347 |
-
key_moments_update_button = gr.Button("
|
| 2348 |
key_moments_delete_button = gr.Button("刪除", size="sm", variant="primary")
|
| 2349 |
key_moments_create_button = gr.Button("建立", size="sm", variant="primary")
|
| 2350 |
with gr.Row():
|
|
@@ -2352,8 +2369,9 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 2352 |
with gr.Tab("問題本文"):
|
| 2353 |
with gr.Row() as question_list_admin:
|
| 2354 |
questions_kind = gr.Textbox(value="questions", show_label=False)
|
|
|
|
| 2355 |
questions_edit_button = gr.Button("編輯", size="sm", variant="primary")
|
| 2356 |
-
questions_update_button = gr.Button("
|
| 2357 |
questions_delete_button = gr.Button("刪除", size="sm", variant="primary")
|
| 2358 |
questions_create_button = gr.Button("建立", size="sm", variant="primary")
|
| 2359 |
with gr.Row():
|
|
@@ -2553,6 +2571,11 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 2553 |
)
|
| 2554 |
|
| 2555 |
# transcript event
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2556 |
transcript_create_button.click(
|
| 2557 |
create_LLM_content,
|
| 2558 |
inputs=[video_id, df_string_output, transcript_kind],
|
|
@@ -2575,6 +2598,11 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 2575 |
)
|
| 2576 |
|
| 2577 |
# key_moments event
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2578 |
key_moments_create_button.click(
|
| 2579 |
create_LLM_content,
|
| 2580 |
inputs=[video_id, df_string_output, key_moments_kind],
|
|
@@ -2597,6 +2625,11 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
| 2597 |
)
|
| 2598 |
|
| 2599 |
# question_list event
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2600 |
questions_create_button.click(
|
| 2601 |
create_LLM_content,
|
| 2602 |
inputs=[video_id, df_string_output, questions_kind],
|
|
|
|
| 1410 |
return key_moments_html
|
| 1411 |
|
| 1412 |
# ---- LLM CRUD ----
|
| 1413 |
+
def get_LLM_content(video_id, kind):
|
| 1414 |
+
print(f"===get_{kind}===")
|
| 1415 |
+
gcs_client = GCS_CLIENT
|
| 1416 |
+
bucket_name = 'video_ai_assistant'
|
| 1417 |
+
file_name = f'{video_id}_{kind}.json'
|
| 1418 |
+
blob_name = f"{video_id}/{file_name}"
|
| 1419 |
+
# 检查 file 是否存在
|
| 1420 |
+
is_file_exists = GCS_SERVICE.check_file_exists(bucket_name, blob_name)
|
| 1421 |
+
if is_file_exists:
|
| 1422 |
+
content = download_blob_to_string(gcs_client, bucket_name, blob_name)
|
| 1423 |
+
content_json = json.loads(content)
|
| 1424 |
+
else:
|
| 1425 |
+
content_json = {}
|
| 1426 |
+
return content_json
|
| 1427 |
+
|
| 1428 |
def enable_edit_mode():
|
| 1429 |
return gr.update(interactive=True)
|
| 1430 |
|
|
|
|
| 2349 |
with gr.Tab("逐字稿本文"):
|
| 2350 |
with gr.Row() as transcript_admmin:
|
| 2351 |
transcript_kind = gr.Textbox(value="transcript", show_label=False)
|
| 2352 |
+
transcript_get_button = gr.Button("取得", size="sm", variant="primary")
|
| 2353 |
transcript_edit_button = gr.Button("編輯", size="sm", variant="primary")
|
| 2354 |
+
transcript_update_button = gr.Button("刷新", size="sm", variant="primary")
|
| 2355 |
transcript_delete_button = gr.Button("刪除", size="sm", variant="primary")
|
| 2356 |
transcript_create_button = gr.Button("建立", size="sm", variant="primary")
|
| 2357 |
with gr.Row():
|
|
|
|
| 2359 |
with gr.Tab("關鍵時刻本文"):
|
| 2360 |
with gr.Row() as key_moments_admin:
|
| 2361 |
key_moments_kind = gr.Textbox(value="key_moments", show_label=False)
|
| 2362 |
+
key_moments_get_button = gr.Button("取得", size="sm", variant="primary")
|
| 2363 |
key_moments_edit_button = gr.Button("編輯", size="sm", variant="primary")
|
| 2364 |
+
key_moments_update_button = gr.Button("刷新", size="sm", variant="primary")
|
| 2365 |
key_moments_delete_button = gr.Button("刪除", size="sm", variant="primary")
|
| 2366 |
key_moments_create_button = gr.Button("建立", size="sm", variant="primary")
|
| 2367 |
with gr.Row():
|
|
|
|
| 2369 |
with gr.Tab("問題本文"):
|
| 2370 |
with gr.Row() as question_list_admin:
|
| 2371 |
questions_kind = gr.Textbox(value="questions", show_label=False)
|
| 2372 |
+
questions_get_button = gr.Button("取得", size="sm", variant="primary")
|
| 2373 |
questions_edit_button = gr.Button("編輯", size="sm", variant="primary")
|
| 2374 |
+
questions_update_button = gr.Button("刷新", size="sm", variant="primary")
|
| 2375 |
questions_delete_button = gr.Button("刪除", size="sm", variant="primary")
|
| 2376 |
questions_create_button = gr.Button("建立", size="sm", variant="primary")
|
| 2377 |
with gr.Row():
|
|
|
|
| 2571 |
)
|
| 2572 |
|
| 2573 |
# transcript event
|
| 2574 |
+
transcript_get_button.click(
|
| 2575 |
+
get_LLM_content,
|
| 2576 |
+
inputs=[video_id, transcript_kind],
|
| 2577 |
+
outputs=[df_string_output]
|
| 2578 |
+
)
|
| 2579 |
transcript_create_button.click(
|
| 2580 |
create_LLM_content,
|
| 2581 |
inputs=[video_id, df_string_output, transcript_kind],
|
|
|
|
| 2598 |
)
|
| 2599 |
|
| 2600 |
# key_moments event
|
| 2601 |
+
key_moments_get_button.click(
|
| 2602 |
+
get_LLM_content,
|
| 2603 |
+
inputs=[video_id, key_moments_kind],
|
| 2604 |
+
outputs=[key_moments]
|
| 2605 |
+
)
|
| 2606 |
key_moments_create_button.click(
|
| 2607 |
create_LLM_content,
|
| 2608 |
inputs=[video_id, df_string_output, key_moments_kind],
|
|
|
|
| 2625 |
)
|
| 2626 |
|
| 2627 |
# question_list event
|
| 2628 |
+
questions_get_button.click(
|
| 2629 |
+
get_LLM_content,
|
| 2630 |
+
inputs=[video_id, questions_kind],
|
| 2631 |
+
outputs=[questions_json]
|
| 2632 |
+
)
|
| 2633 |
questions_create_button.click(
|
| 2634 |
create_LLM_content,
|
| 2635 |
inputs=[video_id, df_string_output, questions_kind],
|