Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import config
|
| 3 |
from ui_components import create_ui
|
| 4 |
from annotation import load_annotations
|
| 5 |
-
from task_manager import get_current_task, get_current_task_with_annotations, get_total_tasks
|
| 6 |
|
| 7 |
css = """
|
| 8 |
.center { text-align: center; }
|
|
@@ -28,12 +28,11 @@ def set_user_info(request: gr.Request):
|
|
| 28 |
"""设置用户信息到 State 并加载用户特定的标注"""
|
| 29 |
username = request.username if hasattr(request, 'username') else "unknown"
|
| 30 |
annotation_results = load_annotations(username)
|
| 31 |
-
current_task = 0 # 每个用户都从任务0开始
|
| 32 |
print(f"加载用户 {username} 的标注结果:{annotation_results}")
|
| 33 |
|
| 34 |
# 获取当前任务信息,并考虑已有的标注结果
|
| 35 |
inst, text, audioA_update, audioB_update, prev_disabled, next_disabled, task_num = get_current_task_with_annotations(
|
| 36 |
-
|
| 37 |
|
| 38 |
# 获取总任务数
|
| 39 |
total_tasks = get_total_tasks()
|
|
@@ -44,7 +43,6 @@ def set_user_info(request: gr.Request):
|
|
| 44 |
# 返回所有需要初始化的组件值
|
| 45 |
return (
|
| 46 |
username,
|
| 47 |
-
current_task, # 新增:返回用户的 current_task
|
| 48 |
annotation_results,
|
| 49 |
inst, # instruction
|
| 50 |
text, # text_box
|
|
@@ -60,17 +58,15 @@ if __name__ == "__main__":
|
|
| 60 |
print("启动应用...")
|
| 61 |
with gr.Blocks(css=css) as demo:
|
| 62 |
username = gr.State(value="unknown")
|
| 63 |
-
current_task = gr.State(value=0) # 新增:每个用户的 current_task 状态
|
| 64 |
annotation_results = gr.State(value={})
|
| 65 |
-
ui_components = create_ui(get_current_task(
|
| 66 |
|
| 67 |
-
# 修改 demo.load,
|
| 68 |
demo.load(
|
| 69 |
set_user_info,
|
| 70 |
inputs=None,
|
| 71 |
outputs=[
|
| 72 |
username,
|
| 73 |
-
current_task, # 新增输出
|
| 74 |
annotation_results,
|
| 75 |
ui_components["instruction"],
|
| 76 |
ui_components["text_box"],
|
|
@@ -82,33 +78,33 @@ if __name__ == "__main__":
|
|
| 82 |
]
|
| 83 |
)
|
| 84 |
|
| 85 |
-
#
|
| 86 |
ui_components["btn_A"].click(
|
| 87 |
-
select_audio,
|
| 88 |
-
inputs=[gr.State("A"), ui_components["audioA"], ui_components["audioB"],
|
| 89 |
outputs=[ui_components["audioA"], ui_components["audioB"], annotation_results]
|
| 90 |
)
|
| 91 |
|
| 92 |
ui_components["btn_B"].click(
|
| 93 |
-
select_audio,
|
| 94 |
-
inputs=[gr.State("B"), ui_components["audioA"], ui_components["audioB"],
|
| 95 |
outputs=[ui_components["audioA"], ui_components["audioB"], annotation_results]
|
| 96 |
)
|
| 97 |
|
| 98 |
ui_components["btn_prev"].click(
|
| 99 |
-
change_task,
|
| 100 |
-
inputs=[gr.State("prev"),
|
| 101 |
outputs=[ui_components["instruction"], ui_components["text_box"], ui_components["audioA"],
|
| 102 |
ui_components["audioB"], ui_components["btn_prev"], ui_components["btn_next"],
|
| 103 |
-
ui_components["task_number"],
|
| 104 |
)
|
| 105 |
|
| 106 |
ui_components["btn_next"].click(
|
| 107 |
-
change_task,
|
| 108 |
-
inputs=[gr.State("next"),
|
| 109 |
outputs=[ui_components["instruction"], ui_components["text_box"], ui_components["audioA"],
|
| 110 |
ui_components["audioB"], ui_components["btn_prev"], ui_components["btn_next"],
|
| 111 |
-
ui_components["task_number"],
|
| 112 |
)
|
| 113 |
|
| 114 |
-
demo.launch(auth=config.ANNOTATOR, share=True,
|
|
|
|
| 2 |
import config
|
| 3 |
from ui_components import create_ui
|
| 4 |
from annotation import load_annotations
|
| 5 |
+
from task_manager import get_current_task, get_current_task_with_annotations, get_total_tasks
|
| 6 |
|
| 7 |
css = """
|
| 8 |
.center { text-align: center; }
|
|
|
|
| 28 |
"""设置用户信息到 State 并加载用户特定的标注"""
|
| 29 |
username = request.username if hasattr(request, 'username') else "unknown"
|
| 30 |
annotation_results = load_annotations(username)
|
|
|
|
| 31 |
print(f"加载用户 {username} 的标注结果:{annotation_results}")
|
| 32 |
|
| 33 |
# 获取当前任务信息,并考虑已有的标注结果
|
| 34 |
inst, text, audioA_update, audioB_update, prev_disabled, next_disabled, task_num = get_current_task_with_annotations(
|
| 35 |
+
annotation_results)
|
| 36 |
|
| 37 |
# 获取总任务数
|
| 38 |
total_tasks = get_total_tasks()
|
|
|
|
| 43 |
# 返回所有需要初始化的组件值
|
| 44 |
return (
|
| 45 |
username,
|
|
|
|
| 46 |
annotation_results,
|
| 47 |
inst, # instruction
|
| 48 |
text, # text_box
|
|
|
|
| 58 |
print("启动应用...")
|
| 59 |
with gr.Blocks(css=css) as demo:
|
| 60 |
username = gr.State(value="unknown")
|
|
|
|
| 61 |
annotation_results = gr.State(value={})
|
| 62 |
+
ui_components = create_ui(get_current_task(), username, annotation_results)
|
| 63 |
|
| 64 |
+
# 修改 demo.load,移除 user_display,保留 task_number
|
| 65 |
demo.load(
|
| 66 |
set_user_info,
|
| 67 |
inputs=None,
|
| 68 |
outputs=[
|
| 69 |
username,
|
|
|
|
| 70 |
annotation_results,
|
| 71 |
ui_components["instruction"],
|
| 72 |
ui_components["text_box"],
|
|
|
|
| 78 |
]
|
| 79 |
)
|
| 80 |
|
| 81 |
+
# 其余按钮绑定保持不变
|
| 82 |
ui_components["btn_A"].click(
|
| 83 |
+
ui_components["select_audio"],
|
| 84 |
+
inputs=[gr.State("A"), ui_components["audioA"], ui_components["audioB"], annotation_results, username],
|
| 85 |
outputs=[ui_components["audioA"], ui_components["audioB"], annotation_results]
|
| 86 |
)
|
| 87 |
|
| 88 |
ui_components["btn_B"].click(
|
| 89 |
+
ui_components["select_audio"],
|
| 90 |
+
inputs=[gr.State("B"), ui_components["audioA"], ui_components["audioB"], annotation_results, username],
|
| 91 |
outputs=[ui_components["audioA"], ui_components["audioB"], annotation_results]
|
| 92 |
)
|
| 93 |
|
| 94 |
ui_components["btn_prev"].click(
|
| 95 |
+
ui_components["change_task"],
|
| 96 |
+
inputs=[gr.State("prev"), annotation_results, username], # 添加 username 参数
|
| 97 |
outputs=[ui_components["instruction"], ui_components["text_box"], ui_components["audioA"],
|
| 98 |
ui_components["audioB"], ui_components["btn_prev"], ui_components["btn_next"],
|
| 99 |
+
ui_components["task_number"], annotation_results] # 保持 task_number
|
| 100 |
)
|
| 101 |
|
| 102 |
ui_components["btn_next"].click(
|
| 103 |
+
ui_components["change_task"],
|
| 104 |
+
inputs=[gr.State("next"), annotation_results, username], # 添加 username 参数
|
| 105 |
outputs=[ui_components["instruction"], ui_components["text_box"], ui_components["audioA"],
|
| 106 |
ui_components["audioB"], ui_components["btn_prev"], ui_components["btn_next"],
|
| 107 |
+
ui_components["task_number"], annotation_results] # 保持 task_number
|
| 108 |
)
|
| 109 |
|
| 110 |
+
demo.launch(auth=config.ANNOTATOR, share=True,ssr_mode=False)
|