ibraheem007 commited on
Commit
6187f1d
Β·
verified Β·
1 Parent(s): 51c2398

Update components/file_processor.py

Browse files
Files changed (1) hide show
  1. components/file_processor.py +3 -78
components/file_processor.py CHANGED
@@ -120,8 +120,8 @@ def get_student_content_input():
120
  )
121
  if uploaded_file:
122
  with st.spinner("πŸ“– Reading your document..."):
123
- # Add debug info
124
- st.write(f"πŸ“ Testing file: {uploaded_file.name} ({len(uploaded_file.getvalue())} bytes)")
125
 
126
  content_text, error = process_uploaded_file(uploaded_file)
127
 
@@ -141,79 +141,4 @@ def get_student_content_input():
141
  placeholder="Paste complex textbook content, lecture notes, or any difficult learning material here..."
142
  )
143
 
144
- return content_text, filename
145
-
146
- # import streamlit as st
147
- # import tempfile
148
- # import os
149
- # from utils.file_utils import extract_text_from_pdf, extract_text_from_pptx, extract_text_from_docx
150
-
151
- # def process_uploaded_file(uploaded_file):
152
- # """Process uploaded file and extract text with proper error handling"""
153
- # try:
154
- # with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1]) as tmp:
155
- # tmp.write(uploaded_file.getvalue())
156
- # tmp_path = tmp.name
157
-
158
- # file_extension = uploaded_file.name.lower()
159
-
160
- # if file_extension.endswith('.pdf'):
161
- # full_text = extract_text_from_pdf(tmp_path)
162
- # elif file_extension.endswith('.pptx'):
163
- # full_text = extract_text_from_pptx(tmp_path)
164
- # elif file_extension.endswith('.docx'):
165
- # full_text = extract_text_from_docx(tmp_path)
166
- # else:
167
- # return None, "Unsupported file type"
168
-
169
- # # Clean up temp file
170
- # os.unlink(tmp_path)
171
-
172
- # if not full_text.strip():
173
- # return None, "No text could be extracted from the file"
174
-
175
- # return full_text, None
176
-
177
- # except Exception as e:
178
- # # Clean up temp file if it exists
179
- # try:
180
- # if 'tmp_path' in locals():
181
- # os.unlink(tmp_path)
182
- # except:
183
- # pass
184
- # return None, f"Error processing file: {str(e)}"
185
-
186
- # def get_student_content_input():
187
- # """Get content input from student (file upload or text)"""
188
- # st.subheader("πŸ“š Provide Your Learning Material")
189
- # content_source = st.radio(
190
- # "How would you like to provide the content?",
191
- # ["Upload File (PDF, PPTX, DOCX)", "Paste Text"],
192
- # key="student_source"
193
- # )
194
-
195
- # content_text = ""
196
- # filename = "simplified_content"
197
-
198
- # if content_source == "Upload File (PDF, PPTX, DOCX)":
199
- # uploaded_file = st.file_uploader(
200
- # "Upload your course material",
201
- # type=["pdf", "pptx", "docx"],
202
- # help="Upload lecture slides, textbook chapters, or any difficult course material"
203
- # )
204
- # if uploaded_file:
205
- # with st.spinner("πŸ“– Reading your document..."):
206
- # content_text, error = process_uploaded_file(uploaded_file)
207
- # if error:
208
- # st.error(f"❌ {error}")
209
- # else:
210
- # st.success("βœ… Document processed successfully!")
211
- # filename = uploaded_file.name
212
- # else:
213
- # content_text = st.text_area(
214
- # "Paste the content you want to simplify:",
215
- # height=200,
216
- # placeholder="Paste complex textbook content, lecture notes, or any difficult learning material here..."
217
- # )
218
-
219
- # return content_text, filename
 
120
  )
121
  if uploaded_file:
122
  with st.spinner("πŸ“– Reading your document..."):
123
+ # # Add debug info
124
+ # st.write(f"πŸ“ Testing file: {uploaded_file.name} ({len(uploaded_file.getvalue())} bytes)")
125
 
126
  content_text, error = process_uploaded_file(uploaded_file)
127
 
 
141
  placeholder="Paste complex textbook content, lecture notes, or any difficult learning material here..."
142
  )
143
 
144
+ return content_text, filename