Chia Woon Yap
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -283,92 +283,90 @@ def tutor_ai_chatbot():
|
|
| 283 |
gr.Markdown("# 📚 AI Tutor - We.(POC)")
|
| 284 |
gr.Markdown("An interactive Personal AI Tutor chatbot to help with your learning needs.")
|
| 285 |
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
with gr.Row():
|
| 305 |
-
with gr.Column(scale=1):
|
| 306 |
-
audio_input = gr.Audio(type="numpy", label="Record or Upload Audio")
|
| 307 |
-
|
| 308 |
-
# Clear chat history button
|
| 309 |
-
clear_btn = gr.Button("Clear Chat")
|
| 310 |
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
examples=[
|
| 338 |
-
"Can you explain the concept of RLHF AI?",
|
| 339 |
-
"What are AI transformers?",
|
| 340 |
-
"What is MoE AI?",
|
| 341 |
-
"What's gate networks AI?",
|
| 342 |
-
"I am making a switch, please generating baking recipe?"
|
| 343 |
-
],
|
| 344 |
-
inputs=msg
|
| 345 |
)
|
| 346 |
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
gr.
|
| 367 |
-
|
| 368 |
-
gr.
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
|
| 373 |
# Launch the AI chatbot
|
| 374 |
if __name__ == "__main__":
|
|
|
|
| 283 |
gr.Markdown("# 📚 AI Tutor - We.(POC)")
|
| 284 |
gr.Markdown("An interactive Personal AI Tutor chatbot to help with your learning needs.")
|
| 285 |
|
| 286 |
+
# Chatbot Tab
|
| 287 |
+
with gr.Tab("AI Chatbot"):
|
| 288 |
+
with gr.Row():
|
| 289 |
+
with gr.Column(scale=3):
|
| 290 |
+
chatbot = gr.Chatbot(height=500, type="messages")
|
| 291 |
+
|
| 292 |
+
with gr.Column(scale=1):
|
| 293 |
+
audio_playback = gr.Audio(label="Audio Response", type="filepath")
|
| 294 |
+
|
| 295 |
+
# Move the input controls here to span full width
|
| 296 |
+
with gr.Row():
|
| 297 |
+
msg = gr.Textbox(
|
| 298 |
+
label="Ask a question",
|
| 299 |
+
placeholder="Type your question here...",
|
| 300 |
+
container=False # Removes the default container styling
|
| 301 |
+
)
|
| 302 |
+
submit = gr.Button("Send")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
|
| 304 |
+
with gr.Row():
|
| 305 |
+
with gr.Column(scale=1):
|
| 306 |
+
audio_input = gr.Audio(type="numpy", label="Record or Upload Audio")
|
| 307 |
+
|
| 308 |
+
# Clear chat history button
|
| 309 |
+
clear_btn = gr.Button("Clear Chat")
|
| 310 |
+
|
| 311 |
+
# Handle chat interaction
|
| 312 |
+
submit.click(
|
| 313 |
+
chat_with_groq,
|
| 314 |
+
inputs=[msg, chatbot],
|
| 315 |
+
outputs=[chatbot, msg, audio_playback]
|
| 316 |
+
)
|
| 317 |
+
|
| 318 |
+
# Clear chat history function
|
| 319 |
+
clear_btn.click(
|
| 320 |
+
lambda: [], # Return empty list in message format
|
| 321 |
+
inputs=None,
|
| 322 |
+
outputs=[chatbot]
|
| 323 |
+
)
|
| 324 |
+
|
| 325 |
+
# Also allow Enter key to submit
|
| 326 |
+
msg.submit(
|
| 327 |
+
chat_with_groq,
|
| 328 |
+
inputs=[msg, chatbot],
|
| 329 |
+
outputs=[chatbot, msg, audio_playback]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
)
|
| 331 |
|
| 332 |
+
# Add some examples of questions students might ask
|
| 333 |
+
with gr.Accordion("Example Questions", open=False):
|
| 334 |
+
gr.Examples(
|
| 335 |
+
examples=[
|
| 336 |
+
"Can you explain the concept of RLHF AI?",
|
| 337 |
+
"What are AI transformers?",
|
| 338 |
+
"What is MoE AI?",
|
| 339 |
+
"What's gate networks AI?",
|
| 340 |
+
"I am making a switch, please generating baking recipe?"
|
| 341 |
+
],
|
| 342 |
+
inputs=msg
|
| 343 |
+
)
|
| 344 |
+
|
| 345 |
+
# Connect audio input to transcription
|
| 346 |
+
audio_input.change(fn=transcribe_audio, inputs=audio_input, outputs=msg)
|
| 347 |
+
|
| 348 |
+
# Upload Notes & Generate Quiz Tab
|
| 349 |
+
with gr.Tab("Upload Notes & Generate Quiz"):
|
| 350 |
+
with gr.Row():
|
| 351 |
+
with gr.Column(scale=2):
|
| 352 |
+
file_input = gr.File(label="Upload Lecture Notes (PDF, DOCX, PPTX)")
|
| 353 |
+
with gr.Column(scale=3):
|
| 354 |
+
quiz_output = gr.Textbox(label="Generated Quiz", lines=10)
|
| 355 |
+
|
| 356 |
+
# Connect file input to document processing
|
| 357 |
+
file_input.change(process_document, inputs=file_input, outputs=quiz_output)
|
| 358 |
+
|
| 359 |
+
# Introduction Video Tab - Now with the working video
|
| 360 |
+
with gr.Tab("Introduction Video"):
|
| 361 |
+
with gr.Row():
|
| 362 |
+
with gr.Column(scale=1):
|
| 363 |
+
gr.Markdown("### Welcome to the Introduction Video")
|
| 364 |
+
gr.Markdown("Music from Xu Mengyuan - China-O, musician Xu Mengyuan YUAN! | 徐梦圆 - China-O 音乐人徐梦圆YUAN!")
|
| 365 |
+
# Use the local video file that's stored in your Space
|
| 366 |
+
gr.Video("We_not_me_video.mp4", label="Introduction Video")
|
| 367 |
+
|
| 368 |
+
# Launch the application
|
| 369 |
+
app.launch(share=False)
|
| 370 |
|
| 371 |
# Launch the AI chatbot
|
| 372 |
if __name__ == "__main__":
|