Update app.py
Browse files
app.py
CHANGED
@@ -41,43 +41,40 @@ def get_class_stats(class_id):
|
|
41 |
}
|
42 |
|
43 |
def create_student_interface(class_id):
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
)
|
66 |
-
|
67 |
-
submit_button.click(
|
68 |
-
submit_question,
|
69 |
-
inputs=[student_id, gr.State(class_id), question_input],
|
70 |
-
outputs=question_status
|
71 |
-
)
|
72 |
|
73 |
-
return
|
74 |
-
fn=lambda: None,
|
75 |
-
inputs=[],
|
76 |
-
outputs=[],
|
77 |
-
title=f"Student Interface - Class {class_id}",
|
78 |
-
description="Use the buttons to indicate your understanding and ask questions.",
|
79 |
-
theme="default"
|
80 |
-
)
|
81 |
|
82 |
def create_teacher_interface(class_id):
|
83 |
def render_stats():
|
@@ -100,30 +97,27 @@ def create_teacher_interface(class_id):
|
|
100 |
|
101 |
return f"{color_chart}<br>{stats_text}<br>{questions_text}"
|
102 |
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
105 |
|
106 |
-
|
107 |
|
108 |
-
return
|
109 |
-
fn=lambda: None,
|
110 |
-
inputs=[],
|
111 |
-
outputs=[],
|
112 |
-
title=f"Teacher Interface - Class {class_id}",
|
113 |
-
description="Monitor student understanding and view questions.",
|
114 |
-
theme="default"
|
115 |
-
)
|
116 |
|
117 |
def launch_app(class_id):
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
-
app = gr.TabbedInterface(
|
122 |
-
[student_interface, teacher_interface],
|
123 |
-
["Student", "Teacher"],
|
124 |
-
title=f"Fastcups - Class {class_id}",
|
125 |
-
theme=gr.themes.Soft()
|
126 |
-
)
|
127 |
app.launch()
|
128 |
|
129 |
if __name__ == "__main__":
|
|
|
41 |
}
|
42 |
|
43 |
def create_student_interface(class_id):
|
44 |
+
with gr.Blocks() as student_interface:
|
45 |
+
student_id = gr.State(generate_student_id())
|
46 |
+
|
47 |
+
gr.Markdown(f"## Student Interface - Class {class_id}")
|
48 |
+
gr.Markdown("Use the buttons to indicate your understanding and ask questions.")
|
49 |
+
|
50 |
+
with gr.Row():
|
51 |
+
with gr.Column(scale=2):
|
52 |
+
color_buttons = [
|
53 |
+
gr.Button("π’ I'm following along", variant="primary"),
|
54 |
+
gr.Button("π‘ I need clarification", variant="secondary"),
|
55 |
+
gr.Button("π΄ I'm lost, please stop", variant="stop")
|
56 |
+
]
|
57 |
+
with gr.Column(scale=1):
|
58 |
+
status = gr.Textbox(label="Current Status", interactive=False)
|
59 |
+
|
60 |
+
question_input = gr.Textbox(label="Ask a question")
|
61 |
+
submit_button = gr.Button("Submit Question")
|
62 |
+
question_status = gr.Textbox(label="Question Status", interactive=False)
|
63 |
|
64 |
+
for button, color in zip(color_buttons, ["green", "yellow", "red"]):
|
65 |
+
button.click(
|
66 |
+
update_student_state,
|
67 |
+
inputs=[student_id, gr.State(class_id), gr.State(color)],
|
68 |
+
outputs=status
|
69 |
+
)
|
70 |
+
|
71 |
+
submit_button.click(
|
72 |
+
submit_question,
|
73 |
+
inputs=[student_id, gr.State(class_id), question_input],
|
74 |
+
outputs=question_status
|
75 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
+
return student_interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
def create_teacher_interface(class_id):
|
80 |
def render_stats():
|
|
|
97 |
|
98 |
return f"{color_chart}<br>{stats_text}<br>{questions_text}"
|
99 |
|
100 |
+
with gr.Blocks() as teacher_interface:
|
101 |
+
gr.Markdown(f"## Teacher Interface - Class {class_id}")
|
102 |
+
gr.Markdown("Monitor student understanding and view questions.")
|
103 |
+
|
104 |
+
stats_html = gr.HTML()
|
105 |
+
refresh_button = gr.Button("Refresh Stats")
|
106 |
|
107 |
+
refresh_button.click(render_stats, inputs=[], outputs=[stats_html])
|
108 |
|
109 |
+
return teacher_interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
def launch_app(class_id):
|
112 |
+
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
113 |
+
gr.Markdown(f"# Fastcups - Class {class_id}")
|
114 |
+
|
115 |
+
with gr.Tabs():
|
116 |
+
with gr.TabItem("Student"):
|
117 |
+
create_student_interface(class_id)
|
118 |
+
with gr.TabItem("Teacher"):
|
119 |
+
create_teacher_interface(class_id)
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
app.launch()
|
122 |
|
123 |
if __name__ == "__main__":
|