| import gradio as gr |
| import os |
| from tempfile import NamedTemporaryFile |
|
|
|
|
| def file_dashboard(): |
| with gr.Column() as file_panel: |
| gr.Markdown(""" |
| <div style='text-align: center;'> |
| <img src='file/images/chatter_owl.png' width='120'> |
| <h2>π File-Based Learning with <strong>Chatter the Owl</strong></h2> |
| <p>Upload your notes, textbooks, or slides, and let me turn them into summaries, quizzes, and flashcards!</p> |
| </div> |
| """) |
|
|
| file_upload = gr.File(label="π Upload Your Study Material", file_types=[".pdf", ".txt", ".md", ".pptx"]) |
| question_box = gr.Textbox(label="π¬ Ask a question about the uploaded file") |
|
|
| with gr.Tabs(): |
| with gr.Tab("π Summary"): |
| summary_output = gr.Textbox(label="Generated Summary", lines=8, interactive=False) |
| with gr.Tab("π§ Flashcards"): |
| flashcard_output = gr.Textbox(label="Generated Flashcards", lines=8, interactive=False) |
| with gr.Tab("β Quiz"): |
| quiz_output = gr.Textbox(label="Generated Quiz Questions", lines=8, interactive=False) |
| with gr.Tab("π¬ Answer to Your Question"): |
| answer_output = gr.Textbox(label="Answer", lines=4, interactive=False) |
|
|
| def placeholder_logic(file, question): |
| |
| summary = "This is a summary of your uploaded content." |
| flashcards = "Flashcard 1: Question? | Answer.\nFlashcard 2: Question? | Answer." |
| quiz = "1. What is...?\n2. Explain..." |
| answer = f"You asked: {question}\nHere's a helpful answer from your content." |
| return summary, flashcards, quiz, answer |
|
|
| file_upload.change( |
| fn=lambda file: placeholder_logic(file, ""), |
| inputs=[file_upload], |
| outputs=[summary_output, flashcard_output, quiz_output, answer_output] |
| ) |
|
|
| question_box.change( |
| fn=lambda question: placeholder_logic(None, question), |
| inputs=[question_box], |
| outputs=[summary_output, flashcard_output, quiz_output, answer_output] |
| ) |
|
|
| return file_panel |
|
|