Update file_module.py
Browse files- file_module.py +45 -42
file_module.py
CHANGED
|
@@ -10,57 +10,60 @@ from file_utils import (
|
|
| 10 |
|
| 11 |
|
| 12 |
def file_dashboard():
|
| 13 |
-
with gr.
|
| 14 |
-
gr.
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
flashcard_output = gr.Textbox(label="Generated Flashcards", lines=8, interactive=False)
|
| 30 |
-
with gr.Tab("β Quiz"):
|
| 31 |
-
quiz_output = gr.Textbox(label="Generated Quiz Questions", lines=8, interactive=False)
|
| 32 |
-
with gr.Tab("π¬ Answer to Your Question"):
|
| 33 |
-
answer_output = gr.Textbox(label="Answer", lines=4, interactive=False)
|
| 34 |
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
if not text or "Unsupported file type" in text:
|
| 40 |
-
return text, "", "", ""
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
return text, summary, flashcards, quiz
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
if
|
| 51 |
-
return "
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
file_upload.change(
|
| 55 |
-
fn=
|
| 56 |
inputs=[file_upload],
|
| 57 |
-
outputs=[
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
question_box.change(
|
| 61 |
-
fn=handle_question,
|
| 62 |
-
inputs=[text_state, question_box],
|
| 63 |
-
outputs=[answer_output]
|
| 64 |
)
|
| 65 |
|
| 66 |
return file_panel
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
def file_dashboard():
|
| 13 |
+
with gr.Blocks(elem_id="file-learning-layout") as file_panel:
|
| 14 |
+
with gr.Row():
|
| 15 |
+
with gr.Column(scale=1, min_width=220):
|
| 16 |
+
gr.Markdown("""
|
| 17 |
+
### π My Course
|
| 18 |
+
- **Upload Files**
|
| 19 |
+
- **Study Guides**
|
| 20 |
+
- **Files**
|
| 21 |
+
---
|
| 22 |
+
**Ankush Bansal**
|
| 23 |
+
ankban@wharton.upenn.edu
|
| 24 |
+
""", elem_id="sidebar")
|
| 25 |
|
| 26 |
+
with gr.Column(scale=4):
|
| 27 |
+
with gr.Row():
|
| 28 |
+
uploaded_file_label = gr.Markdown("**File:** _No file uploaded_ | **Progress:** 0%", elem_id="file-header")
|
| 29 |
|
| 30 |
+
with gr.Row():
|
| 31 |
+
with gr.Column(scale=4):
|
| 32 |
+
section_overview = gr.Markdown("""### π Section Overview
|
| 33 |
+
Upload a file to generate section outline...""", elem_id="section-overview")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
section_content_box = gr.Markdown("""
|
| 36 |
+
> Select a section to view content
|
| 37 |
|
| 38 |
+
*No section selected yet.*
|
| 39 |
+
""", elem_id="section-content")
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
with gr.Column(scale=1, min_width=200):
|
| 42 |
+
section_list = gr.Markdown("""### π Sections
|
| 43 |
+
_(auto-generated)_""", elem_id="section-sidebar")
|
|
|
|
| 44 |
|
| 45 |
+
file_upload = gr.File(label="π Upload PDF/Text File", file_types=[".pdf", ".txt", ".md", ".pptx"])
|
| 46 |
+
|
| 47 |
+
def placeholder_file_parse(file):
|
| 48 |
+
if file is None:
|
| 49 |
+
return "**File:** _No file uploaded_ | **Progress:** 0%", \
|
| 50 |
+
"### π Section Overview\nNo file uploaded.", \
|
| 51 |
+
"*No section selected yet.*", \
|
| 52 |
+
"### π Sections\n_(none)_"
|
| 53 |
+
|
| 54 |
+
name = os.path.basename(file.name)
|
| 55 |
+
return (
|
| 56 |
+
f"**File:** {name} | **Progress:** 3%",
|
| 57 |
+
"### π Section Overview\n1. Introduction\n2. Key Topics\n3. Summary\n4. Conclusion",
|
| 58 |
+
"#### π Introduction\n\nThis is a placeholder section content. More details coming soon.",
|
| 59 |
+
"### π Sections\n- Introduction\n- Key Topics\n- Summary\n- Conclusion"
|
| 60 |
+
)
|
| 61 |
|
| 62 |
file_upload.change(
|
| 63 |
+
fn=placeholder_file_parse,
|
| 64 |
inputs=[file_upload],
|
| 65 |
+
outputs=[uploaded_file_label, section_overview, section_content_box, section_list],
|
| 66 |
+
show_progress="minimal"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
)
|
| 68 |
|
| 69 |
return file_panel
|