rishiraj commited on
Commit
0272f61
Β·
verified Β·
1 Parent(s): 012f7b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -53
app.py CHANGED
@@ -41,43 +41,40 @@ def get_class_stats(class_id):
41
  }
42
 
43
  def create_student_interface(class_id):
44
- student_id = gr.State(generate_student_id())
45
-
46
- with gr.Row():
47
- with gr.Column(scale=2):
48
- color_buttons = [
49
- gr.Button("🟒 I'm following along", variant="primary"),
50
- gr.Button("🟑 I need clarification", variant="secondary"),
51
- gr.Button("πŸ”΄ I'm lost, please stop", variant="stop")
52
- ]
53
- with gr.Column(scale=1):
54
- status = gr.Textbox(label="Current Status", interactive=False)
55
-
56
- question_input = gr.Textbox(label="Ask a question")
57
- submit_button = gr.Button("Submit Question")
58
- question_status = gr.Textbox(label="Question Status", interactive=False)
 
 
 
 
59
 
60
- for button, color in zip(color_buttons, ["green", "yellow", "red"]):
61
- button.click(
62
- update_student_state,
63
- inputs=[student_id, gr.State(class_id), gr.State(color)],
64
- outputs=status
 
 
 
 
 
 
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 gr.Interface(
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
- stats_html = gr.HTML()
104
- refresh_button = gr.Button("Refresh Stats")
 
 
 
 
105
 
106
- refresh_button.click(render_stats, inputs=[], outputs=[stats_html])
107
 
108
- return gr.Interface(
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
- student_interface = create_student_interface(class_id)
119
- teacher_interface = create_teacher_interface(class_id)
 
 
 
 
 
 
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__":