Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -179,15 +179,16 @@ def toggle_education_other(choice):
|
|
| 179 |
return gr.update(visible=is_other, interactive=is_other, value="")
|
| 180 |
|
| 181 |
def check_info_complete(age, gender, education, education_other, ai_experience):
|
| 182 |
-
if age and gender and education and ai_experience:
|
| 183 |
if education == "其他(请注明)" and not education_other.strip():
|
| 184 |
return gr.update(interactive=False)
|
| 185 |
return gr.update(interactive=True)
|
| 186 |
return gr.update(interactive=False)
|
| 187 |
|
| 188 |
-
def show_sample_page_and_init(age, gender, education, education_other, ai_experience, user_data):
|
| 189 |
final_edu = education_other if education == "其他(请注明)" else education
|
| 190 |
user_data.update({
|
|
|
|
| 191 |
"age": age,
|
| 192 |
"gender": gender,
|
| 193 |
"education": final_edu,
|
|
@@ -351,7 +352,7 @@ def submit_question_and_advance(q_idx, d_idx, selections, final_choice, all_resu
|
|
| 351 |
|
| 352 |
def save_all_results_to_file(all_results, user_data, count_data=None):
|
| 353 |
repo_id = "intersteller2887/Turing-test-dataset"
|
| 354 |
-
username = user_data.get("
|
| 355 |
timestamp = pd.Timestamp.now().strftime('%Y%m%d_%H%M%S')
|
| 356 |
submission_filename = f"submissions_{username}_{timestamp}.json"
|
| 357 |
|
|
@@ -450,6 +451,9 @@ with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {max-width: 960px
|
|
| 450 |
|
| 451 |
with info_page:
|
| 452 |
gr.Markdown("## 请提供一些基本信息")
|
|
|
|
|
|
|
|
|
|
| 453 |
age_input = gr.Radio(["18岁以下", "18-25岁", "26-35岁", "36-50岁", "50岁以上"], label="年龄")
|
| 454 |
gender_input = gr.Radio(["男", "女", "其他"], label="性别")
|
| 455 |
education_input = gr.Radio(["高中及以下", "本科", "硕士", "博士", "其他(请注明)"], label="学历")
|
|
@@ -543,7 +547,8 @@ with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {max-width: 960px
|
|
| 543 |
for comp in [age_input, gender_input, education_input, education_other_input, ai_experience_input]:
|
| 544 |
comp.change(
|
| 545 |
fn=check_info_complete,
|
| 546 |
-
inputs=[age_input, gender_input, education_input, education_other_input, ai_experience_input],
|
|
|
|
| 547 |
outputs=submit_info_btn
|
| 548 |
)
|
| 549 |
|
|
|
|
| 179 |
return gr.update(visible=is_other, interactive=is_other, value="")
|
| 180 |
|
| 181 |
def check_info_complete(age, gender, education, education_other, ai_experience):
|
| 182 |
+
if username.strip() and age and gender and education and ai_experience:
|
| 183 |
if education == "其他(请注明)" and not education_other.strip():
|
| 184 |
return gr.update(interactive=False)
|
| 185 |
return gr.update(interactive=True)
|
| 186 |
return gr.update(interactive=False)
|
| 187 |
|
| 188 |
+
def show_sample_page_and_init(username, age, gender, education, education_other, ai_experience, user_data):
|
| 189 |
final_edu = education_other if education == "其他(请注明)" else education
|
| 190 |
user_data.update({
|
| 191 |
+
"username": username.strip(),
|
| 192 |
"age": age,
|
| 193 |
"gender": gender,
|
| 194 |
"education": final_edu,
|
|
|
|
| 352 |
|
| 353 |
def save_all_results_to_file(all_results, user_data, count_data=None):
|
| 354 |
repo_id = "intersteller2887/Turing-test-dataset"
|
| 355 |
+
username = user_data.get("username", "user")
|
| 356 |
timestamp = pd.Timestamp.now().strftime('%Y%m%d_%H%M%S')
|
| 357 |
submission_filename = f"submissions_{username}_{timestamp}.json"
|
| 358 |
|
|
|
|
| 451 |
|
| 452 |
with info_page:
|
| 453 |
gr.Markdown("## 请提供一些基本信息")
|
| 454 |
+
|
| 455 |
+
username_input = gr.Textbox(label="用户名"0, placeholder="请输入你的昵称")
|
| 456 |
+
|
| 457 |
age_input = gr.Radio(["18岁以下", "18-25岁", "26-35岁", "36-50岁", "50岁以上"], label="年龄")
|
| 458 |
gender_input = gr.Radio(["男", "女", "其他"], label="性别")
|
| 459 |
education_input = gr.Radio(["高中及以下", "本科", "硕士", "博士", "其他(请注明)"], label="学历")
|
|
|
|
| 547 |
for comp in [age_input, gender_input, education_input, education_other_input, ai_experience_input]:
|
| 548 |
comp.change(
|
| 549 |
fn=check_info_complete,
|
| 550 |
+
# inputs=[age_input, gender_input, education_input, education_other_input, ai_experience_input],
|
| 551 |
+
inputs=[username_input, age_input, gender_input, education_input, education_other_input, ai_experience_input],
|
| 552 |
outputs=submit_info_btn
|
| 553 |
)
|
| 554 |
|