Spaces:
Running
Running
if not video_id:
Browse files
app.py
CHANGED
@@ -571,25 +571,28 @@ def generate_questions(df_string):
|
|
571 |
return questions
|
572 |
|
573 |
def get_questions(video_id, df_string):
|
574 |
-
|
575 |
-
print("===get_questions===")
|
576 |
-
service = init_drive_service()
|
577 |
-
parent_folder_id = '1GgI4YVs0KckwStVQkLa1NZ8IpaEMurkL'
|
578 |
-
folder_id = create_folder_if_not_exists(service, video_id, parent_folder_id)
|
579 |
-
file_name = f'{video_id}_questions.json'
|
580 |
-
|
581 |
-
# 检查檔案是否存在
|
582 |
-
exists, file_id = check_file_exists(service, folder_id, file_name)
|
583 |
-
if not exists:
|
584 |
questions = generate_questions(df_string)
|
585 |
-
questions_text = json.dumps(questions, ensure_ascii=False, indent=2)
|
586 |
-
upload_content_directly(service, file_name, folder_id, questions_text)
|
587 |
-
print("questions已上傳到Google Drive")
|
588 |
else:
|
589 |
-
#
|
590 |
-
print("
|
591 |
-
|
592 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
593 |
|
594 |
q1 = questions[0] if len(questions) > 0 else ""
|
595 |
q2 = questions[1] if len(questions) > 1 else ""
|
@@ -750,7 +753,7 @@ with gr.Blocks() as demo:
|
|
750 |
btn_2.click(respond, inputs=[btn_2, df_string_output, chatbot], outputs=[msg, chatbot])
|
751 |
btn_3.click(respond, inputs=[btn_3, df_string_output, chatbot], outputs=[msg, chatbot])
|
752 |
|
753 |
-
btn_create_question.click(get_questions, inputs = [
|
754 |
|
755 |
# file_upload.change(process_file, inputs=file_upload, outputs=df_string_output)
|
756 |
file_upload.change(process_file, inputs=file_upload, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
|
|
|
571 |
return questions
|
572 |
|
573 |
def get_questions(video_id, df_string):
|
574 |
+
if not video_id:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
575 |
questions = generate_questions(df_string)
|
|
|
|
|
|
|
576 |
else:
|
577 |
+
# 去 g drive 確認是有有 video_id_questions.json
|
578 |
+
print("===get_questions===")
|
579 |
+
service = init_drive_service()
|
580 |
+
parent_folder_id = '1GgI4YVs0KckwStVQkLa1NZ8IpaEMurkL'
|
581 |
+
folder_id = create_folder_if_not_exists(service, video_id, parent_folder_id)
|
582 |
+
file_name = f'{video_id}_questions.json'
|
583 |
+
|
584 |
+
# 检查檔案是否存在
|
585 |
+
exists, file_id = check_file_exists(service, folder_id, file_name)
|
586 |
+
if not exists:
|
587 |
+
questions = generate_questions(df_string)
|
588 |
+
questions_text = json.dumps(questions, ensure_ascii=False, indent=2)
|
589 |
+
upload_content_directly(service, file_name, folder_id, questions_text)
|
590 |
+
print("questions已上傳到Google Drive")
|
591 |
+
else:
|
592 |
+
# 逐字稿已存在,下载逐字稿内容
|
593 |
+
print("questions已存在于Google Drive中")
|
594 |
+
questions_text = download_file_as_string(service, file_id)
|
595 |
+
questions = json.loads(questions_text)
|
596 |
|
597 |
q1 = questions[0] if len(questions) > 0 else ""
|
598 |
q2 = questions[1] if len(questions) > 1 else ""
|
|
|
753 |
btn_2.click(respond, inputs=[btn_2, df_string_output, chatbot], outputs=[msg, chatbot])
|
754 |
btn_3.click(respond, inputs=[btn_3, df_string_output, chatbot], outputs=[msg, chatbot])
|
755 |
|
756 |
+
btn_create_question.click(get_questions, inputs = ["", df_string_output], outputs = [btn_1, btn_2, btn_3])
|
757 |
|
758 |
# file_upload.change(process_file, inputs=file_upload, outputs=df_string_output)
|
759 |
file_upload.change(process_file, inputs=file_upload, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
|