weiwei1392 commited on
Commit
e1efbcb
·
1 Parent(s): 12a8e81

优化交互界面

Browse files
Files changed (1) hide show
  1. app.py +24 -19
app.py CHANGED
@@ -72,7 +72,9 @@ def update_material_and_skill(_publisher, _semester, _unit, _material_type):
72
  _skills = list(set(df['能指']))
73
  _skills.sort()
74
 
75
- return gr.inputs.Dropdown.update(choices=_materials), gr.inputs.Dropdown.update(choices=_skills)
 
 
76
 
77
 
78
  def update_question_class(_material_type, _skill):
@@ -81,7 +83,9 @@ def update_question_class(_material_type, _skill):
81
  _question_class = list(set(df['一级题型']))
82
  _question_class.sort()
83
 
84
- return gr.inputs.Dropdown.update(choices=_question_class)
 
 
85
 
86
 
87
  def update_question_type(_material_type, _skill, _question_class):
@@ -95,10 +99,12 @@ def update_question_type(_material_type, _skill, _question_class):
95
 
96
 
97
  def update_question_example(_question_type):
98
- df = qt[qt['二级题型'] == _question_type]
99
- _question_example = df['样例'].to_list()[0]
 
100
 
101
- return _question_example
 
102
 
103
 
104
  def generate_questions(_model_mode, _material, _question_type, _question_num, _chatbot):
@@ -145,30 +151,29 @@ with gr.Blocks(css=block_css) as demo:
145
  publishers = list(set(kg['教材']))
146
  publishers.sort()
147
  publisher = gr.inputs.Dropdown(label="版本", choices=publishers)
148
-
149
  semester = gr.inputs.Dropdown(label="学期", choices=[])
150
- publisher.change(update_semesters, inputs=[publisher], outputs=[semester])
151
-
152
  unit = gr.inputs.Dropdown(label="单元", choices=[])
153
- semester.change(update_units, inputs=[publisher, semester], outputs=[unit])
154
-
155
  material_type = gr.Radio(['词汇', '短语', '句子', '语法'], label="出题材料类型")
156
-
157
  material = gr.CheckboxGroup([], label="出题材料")
158
- skill = gr.Radio([], label="考察能力")
159
- material_type.change(update_material_and_skill, inputs=[publisher, semester, unit, material_type],
160
- outputs=[material, skill])
161
 
 
162
  question_class = gr.Radio([], label="题类")
163
- skill.change(update_question_class, inputs=[material_type, skill], outputs=[question_class])
 
 
 
 
164
 
165
- question_type = gr.inputs.Dropdown(label="题型", choices=[])
 
166
  question_class.change(update_question_type, inputs=[material_type, skill, question_class],
167
  outputs=[question_type])
168
 
169
- question_example = gr.Textbox('', label='题例')
170
  question_type.change(update_question_example, inputs=[question_type], outputs=[question_example])
171
 
 
 
 
172
  # option_num = gr.Slider(0, 5, value=3, step=1, label="选项数量", interactive=True)
173
  question_num = gr.Slider(0, 5, value=1, step=1, label="题量", interactive=True)
174
 
@@ -524,6 +529,6 @@ with gr.Blocks(css=block_css) as demo:
524
  # outputs=[chatbot])
525
 
526
 
527
- # demo.queue(concurrency_count=5).launch(server_name='0.0.0.0', server_port=7858, share=True)
528
 
529
- demo.queue(concurrency_count=5).launch()
 
72
  _skills = list(set(df['能指']))
73
  _skills.sort()
74
 
75
+ return gr.inputs.Radio.update(choices=_materials, value=None), gr.inputs.Radio.update(choices=_skills, value=None),\
76
+ gr.inputs.Radio.update(choices=[], value=None), gr.inputs.Radio.update(choices=[], value=None), \
77
+ gr.inputs.Textbox.update(value='')
78
 
79
 
80
  def update_question_class(_material_type, _skill):
 
83
  _question_class = list(set(df['一级题型']))
84
  _question_class.sort()
85
 
86
+ return gr.inputs.Dropdown.update(choices=_question_class, value=None), \
87
+ gr.inputs.Dropdown.update(choices=[], value=None), \
88
+ gr.inputs.Textbox.update(value=''),
89
 
90
 
91
  def update_question_type(_material_type, _skill, _question_class):
 
99
 
100
 
101
  def update_question_example(_question_type):
102
+ if _question_type:
103
+ df = qt[qt['二级题型'] == _question_type]
104
+ return df['样例'].to_list()[0]
105
 
106
+ else:
107
+ return ''
108
 
109
 
110
  def generate_questions(_model_mode, _material, _question_type, _question_num, _chatbot):
 
151
  publishers = list(set(kg['教材']))
152
  publishers.sort()
153
  publisher = gr.inputs.Dropdown(label="版本", choices=publishers)
 
154
  semester = gr.inputs.Dropdown(label="学期", choices=[])
 
 
155
  unit = gr.inputs.Dropdown(label="单元", choices=[])
 
 
156
  material_type = gr.Radio(['词汇', '短语', '句子', '语法'], label="出题材料类型")
 
157
  material = gr.CheckboxGroup([], label="出题材料")
 
 
 
158
 
159
+ skill = gr.Radio([], label="考察能力")
160
  question_class = gr.Radio([], label="题类")
161
+ question_type = gr.Radio(label="题型", choices=[])
162
+ question_example = gr.Textbox('', label='题例')
163
+
164
+ publisher.change(update_semesters, inputs=[publisher], outputs=[semester])
165
+ semester.change(update_units, inputs=[publisher, semester], outputs=[unit])
166
 
167
+ skill.change(update_question_class, inputs=[material_type, skill],
168
+ outputs=[question_class, question_type, question_example])
169
  question_class.change(update_question_type, inputs=[material_type, skill, question_class],
170
  outputs=[question_type])
171
 
 
172
  question_type.change(update_question_example, inputs=[question_type], outputs=[question_example])
173
 
174
+ material_type.change(update_material_and_skill, inputs=[publisher, semester, unit, material_type],
175
+ outputs=[material, skill, question_class, question_type, question_example])
176
+
177
  # option_num = gr.Slider(0, 5, value=3, step=1, label="选项数量", interactive=True)
178
  question_num = gr.Slider(0, 5, value=1, step=1, label="题量", interactive=True)
179
 
 
529
  # outputs=[chatbot])
530
 
531
 
532
+ demo.queue(concurrency_count=5).launch(server_name='0.0.0.0', server_port=7858, share=True)
533
 
534
+ # demo.queue(concurrency_count=5).launch()