Spaces:
Sleeping
Sleeping
raymondEDS commited on
Commit Β·
104b6b9
1
Parent(s): 68d29ed
try work around
Browse files122 unmodified lines123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165122 unmodified linesst.title("π€ Upload Documents")st.markdown("---")uploaded_file = st.file_uploader("Choose a PDF file",type=['pdf'],help="Upload PDF documents to the LMS")if uploaded_file is not None:# Display file infofile_details = {"Filename": uploaded_file.name,"File size": f"{uploaded_file.size / 1024:.2f} KB","File type": uploaded_file.type}st.write("**File Details:**")for key, value in file_details.items():st.write(f"- {key}: {value}")# Extract and display PDF contentpdf_text = extract_pdf_text(uploaded_file)if pdf_text.strip():st.subheader("π Document Preview")with st.expander("View extracted text"):st.text_area("PDF Content", pdf_text, height=300)# Upload buttonif st.button("Upload Document"):# Save document infosave_document_info(uploaded_file.name,uploaded_file.read(),"PDF")st.success(f"β Document '{uploaded_file.name}' uploaded successfully!")st.balloons()def show_my_documents():"""Show uploaded documents"""122 unmodified lines123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199122 unmodified linesst.title("π€ Upload Documents")st.markdown("---")# Add information about file uploadst.info("π‘ **Note:** File upload is optimized for Hugging Face Spaces. If you experience issues, try refreshing the page.")uploaded_file = st.file_uploader("Choose a PDF file",type=['pdf'],help="Upload PDF documents to the LMS (max 200MB)",accept_multiple_files=False)if uploaded_file is not None:try:# Display file infofile_details = {"Filename": uploaded_file.name,"File size": f"{uploaded_file.size / 1024:.2f} KB","File type": uploaded_file.type}st.write("**File Details:**")for key, value in file_details.items():st.write(f"- {key}: {value}")# Extract and display PDF contentpdf_text = extract_pdf_text(uploaded_file)if pdf_text.strip():st.subheader("π Document Preview")with st.expander("View extracted text"):st.text_area("PDF Content", pdf_text, height=300)else:st.warning("β οΈ Could not extract text from this PDF. The file may be image-based or encrypted.")# Upload buttonif st.button("Upload Document", type="primary"):try:# Reset file pointer to beginninguploaded_file.seek(0)# Save document infosave_document_info(uploaded_file.name,uploaded_file.read(),"PDF")st.success(f"β Document '{uploaded_file.name}' uploaded successfully!")st.balloons()# Clear the file uploaderst.rerun()except Exception as e:st.error(f"β Error uploading document: {str(e)}")st.info("π‘ Try uploading a smaller file or refresh the page.")except Exception as e:st.error(f"β Error processing file: {str(e)}")st.info("π‘ Please try uploading a different PDF file.")# Add helpful tipswith st.expander("π‘ Upload Tips"):st.markdown("""**For best results:**- Use PDF files under 200MB- Ensure PDFs contain text (not just images)- Avoid password-protected PDFs- If upload fails, try refreshing the page**Supported formats:** PDF only""")def show_my_documents():"""Show uploaded documents"""
src/streamlit_app.py+64-30