Update file_module.py
Browse files- file_module.py +24 -66
file_module.py
CHANGED
|
@@ -6,90 +6,48 @@ from file_utils import (
|
|
| 6 |
)
|
| 7 |
|
| 8 |
|
|
|
|
| 9 |
def file_dashboard():
|
| 10 |
with gr.Blocks(elem_id="file-learning-layout") as file_panel:
|
| 11 |
with gr.Row():
|
|
|
|
| 12 |
with gr.Column(scale=1, min_width=220):
|
| 13 |
-
gr.Markdown("""
|
| 14 |
-
|
| 15 |
-
- **Upload Files**
|
| 16 |
-
- **Study Guides**
|
| 17 |
-
- **Files**
|
| 18 |
-
---
|
| 19 |
-
**Ankush Bansal**
|
| 20 |
-
ankban@wharton.upenn.edu
|
| 21 |
-
""", elem_id="sidebar")
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
section_content_box = gr.Markdown("> Select a section to view content\n\n*No section selected yet.*", elem_id="section-content")
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
| 38 |
|
|
|
|
| 39 |
def parse_sections(file):
|
| 40 |
if file is None:
|
| 41 |
-
return "
|
| 42 |
|
| 43 |
text = extract_text_from_file(file)
|
| 44 |
-
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
Return them in this format:
|
| 48 |
-
|
| 49 |
-
1. Title One: Short summary
|
| 50 |
-
2. Title Two: Short summary
|
| 51 |
-
...
|
| 52 |
-
|
| 53 |
-
Content:
|
| 54 |
-
{text}
|
| 55 |
-
"""
|
| 56 |
-
response = call_llm(prompt, system_message="You break study material into logical learning sections.")
|
| 57 |
-
|
| 58 |
-
lines = response.strip().split("\n")
|
| 59 |
-
section_titles = []
|
| 60 |
-
section_summaries = []
|
| 61 |
-
|
| 62 |
-
for line in lines:
|
| 63 |
-
if ":" in line:
|
| 64 |
-
title, summary = line.split(":", 1)
|
| 65 |
-
section_titles.append(title.strip())
|
| 66 |
-
section_summaries.append(summary.strip())
|
| 67 |
-
|
| 68 |
-
overview_md = "### π Section Overview\n" + "\n".join([f"{i+1}. {title}" for i, title in enumerate(section_titles)])
|
| 69 |
-
section_list = section_titles
|
| 70 |
-
initial_content = f"### {section_titles[0]}\n\n{section_summaries[0]}" if section_titles else "*No sections returned.*"
|
| 71 |
-
file_header = f"**File:** {name} | **Progress:** 30%"
|
| 72 |
-
|
| 73 |
-
return file_header, overview_md, section_list, section_summaries, text
|
| 74 |
-
|
| 75 |
-
def show_selected_section(index, summaries):
|
| 76 |
-
try:
|
| 77 |
-
return f"### {index}\n\n{summaries[index]}"
|
| 78 |
-
except:
|
| 79 |
-
return "Error showing section."
|
| 80 |
|
| 81 |
file_upload.change(
|
| 82 |
fn=parse_sections,
|
| 83 |
inputs=[file_upload],
|
| 84 |
-
outputs=[
|
| 85 |
-
show_progress="minimal"
|
| 86 |
-
)
|
| 87 |
-
|
| 88 |
-
section_list.change(
|
| 89 |
-
fn=show_selected_section,
|
| 90 |
-
inputs=[section_list, sections_state],
|
| 91 |
-
outputs=section_content_box,
|
| 92 |
show_progress="minimal"
|
| 93 |
)
|
| 94 |
|
| 95 |
-
return file_panel
|
|
|
|
| 6 |
)
|
| 7 |
|
| 8 |
|
| 9 |
+
# === FILE-BASED LEARNING LAYOUT WITH NAVIGATION ===
|
| 10 |
def file_dashboard():
|
| 11 |
with gr.Blocks(elem_id="file-learning-layout") as file_panel:
|
| 12 |
with gr.Row():
|
| 13 |
+
# === LEFT SIDEBAR ===
|
| 14 |
with gr.Column(scale=1, min_width=220):
|
| 15 |
+
gr.Markdown("""### π Educare"", elem_id="sidebar-title")
|
| 16 |
+
gr.Markdown("---")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
with gr.Accordion("π§ Learning Modes", open=True):
|
| 19 |
+
btn_spoken = gr.Button("π£ Spoken Communication")
|
| 20 |
+
btn_written = gr.Button("βοΈ Written Communication")
|
| 21 |
|
| 22 |
+
with gr.Accordion("π File-Based Learning", open=True):
|
| 23 |
+
btn_study_guides = gr.Button("π Study Guides")
|
| 24 |
+
btn_file_view = gr.Button("π Files")
|
|
|
|
| 25 |
|
| 26 |
+
gr.Markdown("---")
|
| 27 |
+
gr.Markdown("""**Ankush Bansal**
|
| 28 |
+
ankban@wharton.upenn.edu""", elem_id="sidebar-user")
|
| 29 |
|
| 30 |
+
# === MAIN CONTENT AREA ===
|
| 31 |
+
with gr.Column(scale=4, elem_id="main-column") as main_content:
|
| 32 |
+
file_upload = gr.File(label="π€ Upload File", file_types=[".pdf", ".txt", ".md", ".pptx"])
|
| 33 |
+
content_output = gr.Markdown("Upload a file to get started.", elem_id="file-main-area")
|
| 34 |
|
| 35 |
+
# === File Upload Handler ===
|
| 36 |
def parse_sections(file):
|
| 37 |
if file is None:
|
| 38 |
+
return "No file uploaded."
|
| 39 |
|
| 40 |
text = extract_text_from_file(file)
|
| 41 |
+
prompt = f"Break this content into 4β6 learning sections with a title and short explanation.\n\n{text}"
|
| 42 |
+
response = call_llm(prompt, system_message="You are an education assistant.")
|
| 43 |
|
| 44 |
+
return f"### π Auto-Generated Study Guide\n\n{response}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
file_upload.change(
|
| 47 |
fn=parse_sections,
|
| 48 |
inputs=[file_upload],
|
| 49 |
+
outputs=[content_output],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
show_progress="minimal"
|
| 51 |
)
|
| 52 |
|
| 53 |
+
return file_panel
|