Spaces:
Running
Running
if True:
Browse filesquestions_answers = generate_questions_answers(df_string)
app.py
CHANGED
@@ -582,8 +582,6 @@ def process_youtube_link(password, link):
|
|
582 |
|
583 |
# 基于逐字稿生成其他所需的输出
|
584 |
source = "gcs"
|
585 |
-
questions = get_questions(video_id, formatted_simple_transcript, source)
|
586 |
-
questions_json = json.dumps(questions, ensure_ascii=False, indent=2)
|
587 |
questions_answers = get_questions_answers(video_id, formatted_simple_transcript, source)
|
588 |
questions_answers_json = json.dumps(questions_answers, ensure_ascii=False, indent=2)
|
589 |
summary_json = get_video_id_summary(video_id, formatted_simple_transcript, source)
|
@@ -610,10 +608,6 @@ def process_youtube_link(password, link):
|
|
610 |
|
611 |
# 确保返回与 UI 组件预期匹配的输出
|
612 |
return video_id, \
|
613 |
-
questions_json, \
|
614 |
-
questions[0] if len(questions) > 0 else "", \
|
615 |
-
questions[1] if len(questions) > 1 else "", \
|
616 |
-
questions[2] if len(questions) > 2 else "", \
|
617 |
questions_answers_json, \
|
618 |
original_transcript, \
|
619 |
summary_text, \
|
@@ -1105,19 +1099,19 @@ def get_questions_answers(video_id, df_string, source="gcs"):
|
|
1105 |
blob_name = f"{video_id}/{file_name}"
|
1106 |
# 检查檔案是否存在
|
1107 |
is_questions_answers_exists = GCS_SERVICE.check_file_exists(bucket_name, blob_name)
|
1108 |
-
if not is_questions_answers_exists:
|
|
|
1109 |
questions_answers = generate_questions_answers(df_string)
|
1110 |
-
|
1111 |
-
questions_answers_text = json.dumps(questions_answers_json, ensure_ascii=False, indent=2)
|
1112 |
upload_file_to_gcs_with_json_string(gcs_client, bucket_name, blob_name, questions_answers_text)
|
1113 |
print("questions_answers已上傳到GCS")
|
1114 |
else:
|
1115 |
# questions_answers已存在,下载内容
|
1116 |
print("questions_answers已存在于GCS中")
|
1117 |
questions_answers_text = download_blob_to_string(gcs_client, bucket_name, blob_name)
|
1118 |
-
|
1119 |
|
1120 |
-
return
|
1121 |
|
1122 |
def generate_questions_answers(df_string):
|
1123 |
# 使用 OpenAI 生成基于上传数据的问题
|
@@ -2385,7 +2379,7 @@ def init_params(text, request: gr.Request):
|
|
2385 |
password_text, youtube_link, \
|
2386 |
chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor
|
2387 |
|
2388 |
-
def update_state(content_subject, content_grade, trascript, key_moments,
|
2389 |
# inputs=[content_subject, content_grade, df_string_output],
|
2390 |
# outputs=[content_subject_state, content_grade_state, trascript_state]
|
2391 |
content_subject_state = content_subject
|
@@ -2395,15 +2389,21 @@ def update_state(content_subject, content_grade, trascript, key_moments, questio
|
|
2395 |
trascript_state = formatted_simple_transcript
|
2396 |
key_moments_state = key_moments
|
2397 |
|
2398 |
-
# streaming_chat_thread_id_state = create_thread_id()
|
2399 |
streaming_chat_thread_id_state = ""
|
2400 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
2401 |
ai_chatbot_question_1 = question_1
|
2402 |
ai_chatbot_question_2 = question_2
|
2403 |
ai_chatbot_question_3 = question_3
|
2404 |
|
2405 |
return content_subject_state, content_grade_state, trascript_state, key_moments_state, \
|
2406 |
streaming_chat_thread_id_state, \
|
|
|
2407 |
ai_chatbot_question_1, ai_chatbot_question_2, ai_chatbot_question_3
|
2408 |
|
2409 |
|
@@ -2885,10 +2885,6 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2885 |
process_youtube_link_inputs = [password, youtube_link]
|
2886 |
process_youtube_link_outputs = [
|
2887 |
video_id,
|
2888 |
-
questions_json,
|
2889 |
-
btn_1,
|
2890 |
-
btn_2,
|
2891 |
-
btn_3,
|
2892 |
questions_answers_json,
|
2893 |
df_string_output,
|
2894 |
summary_text,
|
@@ -2911,9 +2907,7 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2911 |
content_grade,
|
2912 |
df_string_output,
|
2913 |
key_moments,
|
2914 |
-
|
2915 |
-
btn_2,
|
2916 |
-
btn_3,
|
2917 |
]
|
2918 |
update_state_outputs = [
|
2919 |
content_subject_state,
|
@@ -2921,6 +2915,9 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2921 |
trascript_state,
|
2922 |
key_moments_state,
|
2923 |
streaming_chat_thread_id_state,
|
|
|
|
|
|
|
2924 |
ai_chatbot_question_1,
|
2925 |
ai_chatbot_question_2,
|
2926 |
ai_chatbot_question_3
|
|
|
582 |
|
583 |
# 基于逐字稿生成其他所需的输出
|
584 |
source = "gcs"
|
|
|
|
|
585 |
questions_answers = get_questions_answers(video_id, formatted_simple_transcript, source)
|
586 |
questions_answers_json = json.dumps(questions_answers, ensure_ascii=False, indent=2)
|
587 |
summary_json = get_video_id_summary(video_id, formatted_simple_transcript, source)
|
|
|
608 |
|
609 |
# 确保返回与 UI 组件预期匹配的输出
|
610 |
return video_id, \
|
|
|
|
|
|
|
|
|
611 |
questions_answers_json, \
|
612 |
original_transcript, \
|
613 |
summary_text, \
|
|
|
1099 |
blob_name = f"{video_id}/{file_name}"
|
1100 |
# 检查檔案是否存在
|
1101 |
is_questions_answers_exists = GCS_SERVICE.check_file_exists(bucket_name, blob_name)
|
1102 |
+
# if not is_questions_answers_exists:
|
1103 |
+
if True:
|
1104 |
questions_answers = generate_questions_answers(df_string)
|
1105 |
+
questions_answers_text = json.dumps(questions_answers, ensure_ascii=False, indent=2)
|
|
|
1106 |
upload_file_to_gcs_with_json_string(gcs_client, bucket_name, blob_name, questions_answers_text)
|
1107 |
print("questions_answers已上傳到GCS")
|
1108 |
else:
|
1109 |
# questions_answers已存在,下载内容
|
1110 |
print("questions_answers已存在于GCS中")
|
1111 |
questions_answers_text = download_blob_to_string(gcs_client, bucket_name, blob_name)
|
1112 |
+
questions_answers = json.loads(questions_answers_text)
|
1113 |
|
1114 |
+
return questions_answers
|
1115 |
|
1116 |
def generate_questions_answers(df_string):
|
1117 |
# 使用 OpenAI 生成基于上传数据的问题
|
|
|
2379 |
password_text, youtube_link, \
|
2380 |
chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor
|
2381 |
|
2382 |
+
def update_state(content_subject, content_grade, trascript, key_moments, questions_answers):
|
2383 |
# inputs=[content_subject, content_grade, df_string_output],
|
2384 |
# outputs=[content_subject_state, content_grade_state, trascript_state]
|
2385 |
content_subject_state = content_subject
|
|
|
2389 |
trascript_state = formatted_simple_transcript
|
2390 |
key_moments_state = key_moments
|
2391 |
|
|
|
2392 |
streaming_chat_thread_id_state = ""
|
2393 |
+
questions_answers_json = json.loads(questions_answers)
|
2394 |
+
question_1 = questions_answers_json[0]["question"]
|
2395 |
+
question_2 = questions_answers_json[1]["question"]
|
2396 |
+
question_3 = questions_answers_json[2]["question"]
|
2397 |
+
btn_1 = question_1
|
2398 |
+
btn_2 = question_2
|
2399 |
+
btn_3 = question_3
|
2400 |
ai_chatbot_question_1 = question_1
|
2401 |
ai_chatbot_question_2 = question_2
|
2402 |
ai_chatbot_question_3 = question_3
|
2403 |
|
2404 |
return content_subject_state, content_grade_state, trascript_state, key_moments_state, \
|
2405 |
streaming_chat_thread_id_state, \
|
2406 |
+
btn_1, btn_2, btn_3, \
|
2407 |
ai_chatbot_question_1, ai_chatbot_question_2, ai_chatbot_question_3
|
2408 |
|
2409 |
|
|
|
2885 |
process_youtube_link_inputs = [password, youtube_link]
|
2886 |
process_youtube_link_outputs = [
|
2887 |
video_id,
|
|
|
|
|
|
|
|
|
2888 |
questions_answers_json,
|
2889 |
df_string_output,
|
2890 |
summary_text,
|
|
|
2907 |
content_grade,
|
2908 |
df_string_output,
|
2909 |
key_moments,
|
2910 |
+
questions_answers_json,
|
|
|
|
|
2911 |
]
|
2912 |
update_state_outputs = [
|
2913 |
content_subject_state,
|
|
|
2915 |
trascript_state,
|
2916 |
key_moments_state,
|
2917 |
streaming_chat_thread_id_state,
|
2918 |
+
btn_1,
|
2919 |
+
btn_2,
|
2920 |
+
btn_3,
|
2921 |
ai_chatbot_question_1,
|
2922 |
ai_chatbot_question_2,
|
2923 |
ai_chatbot_question_3
|