ankban commited on
Commit
5206c58
Β·
verified Β·
1 Parent(s): b67dec4

Update file_module.py

Browse files
Files changed (1) hide show
  1. 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
- ### πŸ“‚ My Course
15
- - **Upload Files**
16
- - **Study Guides**
17
- - **Files**
18
- ---
19
- **Ankush Bansal**
20
- ankban@wharton.upenn.edu
21
- """, elem_id="sidebar")
22
 
23
- with gr.Column(scale=4):
24
- with gr.Row():
25
- uploaded_file_label = gr.Markdown("**File:** _No file uploaded_ | **Progress:** 0%", elem_id="file-header")
26
 
27
- with gr.Row():
28
- with gr.Column(scale=4):
29
- section_overview = gr.Markdown("### πŸ“‘ Section Overview\nUpload a file to generate section outline...", elem_id="section-overview")
30
- section_content_box = gr.Markdown("> Select a section to view content\n\n*No section selected yet.*", elem_id="section-content")
31
 
32
- with gr.Column(scale=1, min_width=200):
33
- section_list = gr.Radio(choices=[], label="πŸ—‚ Sections", interactive=True, elem_id="section-sidebar")
 
34
 
35
- file_upload = gr.File(label="πŸ“ Upload PDF/Text File", file_types=[".pdf", ".txt", ".md", ".pptx"])
36
- sections_state = gr.State([])
37
- text_state = gr.State("")
 
38
 
 
39
  def parse_sections(file):
40
  if file is None:
41
- return "**File:** _No file uploaded_ | **Progress:** 0%", "No file uploaded.", [], [], ""
42
 
43
  text = extract_text_from_file(file)
44
- name = os.path.basename(file.name)
 
45
 
46
- prompt = f"""You are an education assistant. Read the following content and break it into 4–6 clear sections.
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=[uploaded_file_label, section_overview, section_list, sections_state, text_state],
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