Update app.py
Browse files
app.py
CHANGED
|
@@ -169,25 +169,34 @@ with gr.Blocks(title="AI Python Tutor", theme=theme, fill_height=True) as demo:
|
|
| 169 |
inputs=msg
|
| 170 |
)
|
| 171 |
|
| 172 |
-
# Right Column: Resources Dashboard (
|
| 173 |
-
# We assign 'right_col' so we can toggle its visibility
|
| 174 |
with gr.Column(scale=2) as right_col:
|
| 175 |
gr.Markdown("### π Learning Dashboard")
|
| 176 |
|
| 177 |
# Tabbed interface for cleaner look
|
| 178 |
with gr.Tabs():
|
| 179 |
with gr.TabItem("πΊ Videos"):
|
| 180 |
-
|
| 181 |
|
| 182 |
with gr.TabItem("π Reading"):
|
| 183 |
-
|
| 184 |
|
| 185 |
with gr.TabItem("π§ Quiz"):
|
| 186 |
-
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
# --- Interaction Logic ---
|
| 193 |
async def respond(user_message, history):
|
|
@@ -198,7 +207,9 @@ with gr.Blocks(title="AI Python Tutor", theme=theme, fill_height=True) as demo:
|
|
| 198 |
# Placeholder for AI
|
| 199 |
history.append({"role": "assistant", "content": "Thinking..."})
|
| 200 |
|
| 201 |
-
|
|
|
|
|
|
|
| 202 |
|
| 203 |
# Run Agent
|
| 204 |
chat_text, video_text, article_text, quiz_text = await run_tutor_dashboard(user_message)
|
|
@@ -206,36 +217,47 @@ with gr.Blocks(title="AI Python Tutor", theme=theme, fill_height=True) as demo:
|
|
| 206 |
# Update AI response
|
| 207 |
history[-1]["content"] = chat_text
|
| 208 |
|
| 209 |
-
|
|
|
|
| 210 |
|
| 211 |
# --- Focus Mode Logic ---
|
| 212 |
is_fullscreen = gr.State(False)
|
| 213 |
|
| 214 |
def toggle_fullscreen(current_state):
|
| 215 |
new_state = not current_state
|
| 216 |
-
# If new_state is True (Fullscreen)
|
| 217 |
-
# If False (Normal),
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
| 219 |
btn_text = "β© Exit Focus" if new_state else "βΆ Focus Mode"
|
| 220 |
-
|
|
|
|
| 221 |
|
| 222 |
fullscreen_btn.click(
|
| 223 |
toggle_fullscreen,
|
| 224 |
inputs=[is_fullscreen],
|
| 225 |
-
outputs=[is_fullscreen, right_col, fullscreen_btn]
|
| 226 |
)
|
| 227 |
|
| 228 |
-
# Actions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
submit_btn.click(
|
| 230 |
respond,
|
| 231 |
[msg, chatbot],
|
| 232 |
-
|
| 233 |
)
|
| 234 |
|
| 235 |
msg.submit(
|
| 236 |
respond,
|
| 237 |
[msg, chatbot],
|
| 238 |
-
|
| 239 |
)
|
| 240 |
|
| 241 |
# --- Launch ---
|
|
|
|
| 169 |
inputs=msg
|
| 170 |
)
|
| 171 |
|
| 172 |
+
# Right Column: Resources Dashboard (Side View - Visible by default)
|
|
|
|
| 173 |
with gr.Column(scale=2) as right_col:
|
| 174 |
gr.Markdown("### π Learning Dashboard")
|
| 175 |
|
| 176 |
# Tabbed interface for cleaner look
|
| 177 |
with gr.Tabs():
|
| 178 |
with gr.TabItem("πΊ Videos"):
|
| 179 |
+
video_box_side = gr.Markdown(value="### Recommended Videos\n*Ask a topic to see video suggestions!*")
|
| 180 |
|
| 181 |
with gr.TabItem("π Reading"):
|
| 182 |
+
article_box_side = gr.Markdown(value="### Articles & Docs\n*Ask a topic to see reading materials!*")
|
| 183 |
|
| 184 |
with gr.TabItem("π§ Quiz"):
|
| 185 |
+
quiz_box_side = gr.Markdown(value="### Knowledge Check\n*Ask a topic to unlock the quiz!*")
|
| 186 |
|
| 187 |
+
# Bottom Row: Resources Dashboard (Bottom View - Hidden by default)
|
| 188 |
+
with gr.Row(visible=False) as bottom_dashboard:
|
| 189 |
+
with gr.Column():
|
| 190 |
+
gr.Markdown("### π Learning Dashboard")
|
| 191 |
+
with gr.Tabs():
|
| 192 |
+
with gr.TabItem("πΊ Videos"):
|
| 193 |
+
video_box_bottom = gr.Markdown(value="### Recommended Videos\n*Ask a topic to see video suggestions!*")
|
| 194 |
+
|
| 195 |
+
with gr.TabItem("π Reading"):
|
| 196 |
+
article_box_bottom = gr.Markdown(value="### Articles & Docs\n*Ask a topic to see reading materials!*")
|
| 197 |
+
|
| 198 |
+
with gr.TabItem("π§ Quiz"):
|
| 199 |
+
quiz_box_bottom = gr.Markdown(value="### Knowledge Check\n*Ask a topic to unlock the quiz!*")
|
| 200 |
|
| 201 |
# --- Interaction Logic ---
|
| 202 |
async def respond(user_message, history):
|
|
|
|
| 207 |
# Placeholder for AI
|
| 208 |
history.append({"role": "assistant", "content": "Thinking..."})
|
| 209 |
|
| 210 |
+
# Yield placeholders to ALL output boxes (Side AND Bottom)
|
| 211 |
+
# Structure: history, msg, 3x Side Boxes, 3x Bottom Boxes
|
| 212 |
+
yield history, "", "", "", "", "", "", ""
|
| 213 |
|
| 214 |
# Run Agent
|
| 215 |
chat_text, video_text, article_text, quiz_text = await run_tutor_dashboard(user_message)
|
|
|
|
| 217 |
# Update AI response
|
| 218 |
history[-1]["content"] = chat_text
|
| 219 |
|
| 220 |
+
# Yield final content to ALL output boxes
|
| 221 |
+
yield history, "", video_text, article_text, quiz_text, video_text, article_text, quiz_text
|
| 222 |
|
| 223 |
# --- Focus Mode Logic ---
|
| 224 |
is_fullscreen = gr.State(False)
|
| 225 |
|
| 226 |
def toggle_fullscreen(current_state):
|
| 227 |
new_state = not current_state
|
| 228 |
+
# If new_state is True (Fullscreen): Hide side col, Show bottom row
|
| 229 |
+
# If False (Normal): Show side col, Hide bottom row
|
| 230 |
+
|
| 231 |
+
side_visible = not new_state
|
| 232 |
+
bottom_visible = new_state
|
| 233 |
+
|
| 234 |
btn_text = "β© Exit Focus" if new_state else "βΆ Focus Mode"
|
| 235 |
+
|
| 236 |
+
return new_state, gr.Column(visible=side_visible), gr.Row(visible=bottom_visible), btn_text
|
| 237 |
|
| 238 |
fullscreen_btn.click(
|
| 239 |
toggle_fullscreen,
|
| 240 |
inputs=[is_fullscreen],
|
| 241 |
+
outputs=[is_fullscreen, right_col, bottom_dashboard, fullscreen_btn]
|
| 242 |
)
|
| 243 |
|
| 244 |
+
# Actions - We must map outputs to BOTH side and bottom components
|
| 245 |
+
outputs_list = [
|
| 246 |
+
chatbot, msg,
|
| 247 |
+
video_box_side, article_box_side, quiz_box_side,
|
| 248 |
+
video_box_bottom, article_box_bottom, quiz_box_bottom
|
| 249 |
+
]
|
| 250 |
+
|
| 251 |
submit_btn.click(
|
| 252 |
respond,
|
| 253 |
[msg, chatbot],
|
| 254 |
+
outputs_list
|
| 255 |
)
|
| 256 |
|
| 257 |
msg.submit(
|
| 258 |
respond,
|
| 259 |
[msg, chatbot],
|
| 260 |
+
outputs_list
|
| 261 |
)
|
| 262 |
|
| 263 |
# --- Launch ---
|