raymondEDS commited on
Commit
104b6b9
Β·
1 Parent(s): 68d29ed

try work around

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +64 -30
src/streamlit_app.py CHANGED
@@ -123,43 +123,77 @@ def show_upload_documents():
123
  st.title("πŸ“€ Upload Documents")
124
  st.markdown("---")
125
 
 
 
 
126
  uploaded_file = st.file_uploader(
127
  "Choose a PDF file",
128
  type=['pdf'],
129
- help="Upload PDF documents to the LMS"
 
130
  )
131
 
132
  if uploaded_file is not None:
133
- # Display file info
134
- file_details = {
135
- "Filename": uploaded_file.name,
136
- "File size": f"{uploaded_file.size / 1024:.2f} KB",
137
- "File type": uploaded_file.type
138
- }
139
-
140
- st.write("**File Details:**")
141
- for key, value in file_details.items():
142
- st.write(f"- {key}: {value}")
143
-
144
- # Extract and display PDF content
145
- pdf_text = extract_pdf_text(uploaded_file)
146
-
147
- if pdf_text.strip():
148
- st.subheader("πŸ“„ Document Preview")
149
- with st.expander("View extracted text"):
150
- st.text_area("PDF Content", pdf_text, height=300)
151
-
152
- # Upload button
153
- if st.button("Upload Document"):
154
- # Save document info
155
- save_document_info(
156
- uploaded_file.name,
157
- uploaded_file.read(),
158
- "PDF"
159
- )
160
 
161
- st.success(f"βœ… Document '{uploaded_file.name}' uploaded successfully!")
162
- st.balloons()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
  def show_my_documents():
165
  """Show uploaded documents"""
 
123
  st.title("πŸ“€ Upload Documents")
124
  st.markdown("---")
125
 
126
+ # Add information about file upload
127
+ st.info("πŸ’‘ **Note:** File upload is optimized for Hugging Face Spaces. If you experience issues, try refreshing the page.")
128
+
129
  uploaded_file = st.file_uploader(
130
  "Choose a PDF file",
131
  type=['pdf'],
132
+ help="Upload PDF documents to the LMS (max 200MB)",
133
+ accept_multiple_files=False
134
  )
135
 
136
  if uploaded_file is not None:
137
+ try:
138
+ # Display file info
139
+ file_details = {
140
+ "Filename": uploaded_file.name,
141
+ "File size": f"{uploaded_file.size / 1024:.2f} KB",
142
+ "File type": uploaded_file.type
143
+ }
144
+
145
+ st.write("**File Details:**")
146
+ for key, value in file_details.items():
147
+ st.write(f"- {key}: {value}")
148
+
149
+ # Extract and display PDF content
150
+ pdf_text = extract_pdf_text(uploaded_file)
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
+ if pdf_text.strip():
153
+ st.subheader("πŸ“„ Document Preview")
154
+ with st.expander("View extracted text"):
155
+ st.text_area("PDF Content", pdf_text, height=300)
156
+ else:
157
+ st.warning("⚠️ Could not extract text from this PDF. The file may be image-based or encrypted.")
158
+
159
+ # Upload button
160
+ if st.button("Upload Document", type="primary"):
161
+ try:
162
+ # Reset file pointer to beginning
163
+ uploaded_file.seek(0)
164
+
165
+ # Save document info
166
+ save_document_info(
167
+ uploaded_file.name,
168
+ uploaded_file.read(),
169
+ "PDF"
170
+ )
171
+
172
+ st.success(f"βœ… Document '{uploaded_file.name}' uploaded successfully!")
173
+ st.balloons()
174
+
175
+ # Clear the file uploader
176
+ st.rerun()
177
+
178
+ except Exception as e:
179
+ st.error(f"❌ Error uploading document: {str(e)}")
180
+ st.info("πŸ’‘ Try uploading a smaller file or refresh the page.")
181
+
182
+ except Exception as e:
183
+ st.error(f"❌ Error processing file: {str(e)}")
184
+ st.info("πŸ’‘ Please try uploading a different PDF file.")
185
+
186
+ # Add helpful tips
187
+ with st.expander("πŸ’‘ Upload Tips"):
188
+ st.markdown("""
189
+ **For best results:**
190
+ - Use PDF files under 200MB
191
+ - Ensure PDFs contain text (not just images)
192
+ - Avoid password-protected PDFs
193
+ - If upload fails, try refreshing the page
194
+
195
+ **Supported formats:** PDF only
196
+ """)
197
 
198
  def show_my_documents():
199
  """Show uploaded documents"""