Update file_module.py
Browse files- file_module.py +36 -1
file_module.py
CHANGED
|
@@ -130,4 +130,39 @@ def file_dashboard():
|
|
| 130 |
show_progress="minimal"
|
| 131 |
)
|
| 132 |
|
| 133 |
-
return file_content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
show_progress="minimal"
|
| 131 |
)
|
| 132 |
|
| 133 |
+
return file_content
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def file_study_guide_dashboard():
|
| 137 |
+
uploaded_files = gr.State([])
|
| 138 |
+
file_sections = gr.State({})
|
| 139 |
+
file_texts = gr.State({})
|
| 140 |
+
|
| 141 |
+
with gr.Column(scale=4, elem_id="main-column") as guide_content:
|
| 142 |
+
file_upload = gr.File(label="📤 Upload File for Study Guide", file_types=[".pdf", ".txt", ".md", ".pptx"])
|
| 143 |
+
study_guide_output = gr.Markdown("Upload a file to generate a personalized study guide.")
|
| 144 |
+
|
| 145 |
+
def generate_study_guide(file, current_files, section_map, text_map):
|
| 146 |
+
if file is None:
|
| 147 |
+
return current_files, section_map, text_map, "No file uploaded."
|
| 148 |
+
|
| 149 |
+
text = extract_text_from_file(file)
|
| 150 |
+
filename = os.path.basename(file.name)
|
| 151 |
+
|
| 152 |
+
prompt = f"Divide this document into 4-6 detailed learning sections. For each section, include a bold title and detailed explanation.\n\n{text}"
|
| 153 |
+
response = call_llm(prompt, system_message="You are an AI tutor creating study guides.")
|
| 154 |
+
|
| 155 |
+
updated_files = current_files + [filename] if filename not in current_files else current_files
|
| 156 |
+
section_map[filename] = response
|
| 157 |
+
text_map[filename] = text
|
| 158 |
+
|
| 159 |
+
return updated_files, section_map, text_map, f"### {filename} Study Guide\n\n{response}"
|
| 160 |
+
|
| 161 |
+
file_upload.change(
|
| 162 |
+
fn=generate_study_guide,
|
| 163 |
+
inputs=[file_upload, uploaded_files, file_sections, file_texts],
|
| 164 |
+
outputs=[uploaded_files, file_sections, file_texts, study_guide_output],
|
| 165 |
+
show_progress="minimal"
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
return guide_content
|