ankban commited on
Commit
0a0c7fa
Β·
verified Β·
1 Parent(s): 8e9e651

Update file_module.py

Browse files
Files changed (1) hide show
  1. 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.Column() as file_panel:
14
- gr.Markdown("""
15
- <div style='text-align: center;'>
16
- <img src='file/images/chatter_owl.png' width='120'>
17
- <h2>πŸ“„ File-Based Learning with <strong>Chatter the Owl</strong></h2>
18
- <p>Upload your notes, textbooks, or slides, and let me turn them into summaries, quizzes, and flashcards!</p>
19
- </div>
20
- """)
 
 
 
 
21
 
22
- file_upload = gr.File(label="πŸ“ Upload Your Study Material", file_types=[".pdf", ".txt", ".md", ".pptx"])
23
- question_box = gr.Textbox(label="πŸ’¬ Ask a question about the uploaded file")
 
24
 
25
- with gr.Tabs():
26
- with gr.Tab("πŸ“š Summary"):
27
- summary_output = gr.Textbox(label="Generated Summary", lines=8, interactive=False)
28
- with gr.Tab("🧠 Flashcards"):
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
- text_state = gr.State("")
 
36
 
37
- def handle_file_upload(file):
38
- text = extract_text_from_file(file)
39
- if not text or "Unsupported file type" in text:
40
- return text, "", "", ""
41
 
42
- summary = generate_summary(text)
43
- flashcards = generate_flashcards(text)
44
- quiz = generate_quiz(text)
45
- return text, summary, flashcards, quiz
46
 
47
- def handle_question(text, question):
48
- if not text.strip():
49
- return "Please upload a file first."
50
- if not question.strip():
51
- return "Please enter a question."
52
- return answer_question(text, question)
 
 
 
 
 
 
 
 
 
 
53
 
54
  file_upload.change(
55
- fn=handle_file_upload,
56
  inputs=[file_upload],
57
- outputs=[text_state, summary_output, flashcard_output, quiz_output]
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