Update developer.py
Browse files- developer.py +43 -1
developer.py
CHANGED
|
@@ -6,7 +6,22 @@ import streamlit as st
|
|
| 6 |
|
| 7 |
def project_developer_page():
|
| 8 |
|
|
|
|
|
|
|
| 9 |
st.title('NBS Project Submission Evaluation')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def extract_text_from_pdf(uploaded_file, start_page, end_page):
|
| 12 |
if uploaded_file is None:
|
|
@@ -26,7 +41,34 @@ def project_developer_page():
|
|
| 26 |
text += page.extract_text()
|
| 27 |
|
| 28 |
return text
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Rest of your code remains the same
|
| 32 |
|
|
|
|
| 6 |
|
| 7 |
def project_developer_page():
|
| 8 |
|
| 9 |
+
|
| 10 |
+
|
| 11 |
st.title('NBS Project Submission Evaluation')
|
| 12 |
+
|
| 13 |
+
def initialize_firebase():
|
| 14 |
+
cred = credentials.Certificate('/Users/elanukarakus/Desktop/verifyX/serviceAccountKey.json')
|
| 15 |
+
if not firebase_admin._apps:
|
| 16 |
+
firebase_admin.initialize_app(cred, {
|
| 17 |
+
'storageBucket': 'verifyx-a1164.appspot.com' # Replace with your actual bucket name
|
| 18 |
+
})
|
| 19 |
+
|
| 20 |
+
# Initialize Firebase
|
| 21 |
+
initialize_firebase()
|
| 22 |
+
# Firestore and Storage clients
|
| 23 |
+
db = firestore.client()
|
| 24 |
+
bucket = storage.bucket()
|
| 25 |
|
| 26 |
def extract_text_from_pdf(uploaded_file, start_page, end_page):
|
| 27 |
if uploaded_file is None:
|
|
|
|
| 41 |
text += page.extract_text()
|
| 42 |
|
| 43 |
return text
|
| 44 |
+
|
| 45 |
+
def upload_pdf_to_storage(pdf_file):
|
| 46 |
+
pdf_file.seek(0) # Move to the start of the file
|
| 47 |
+
blob = bucket.blob(pdf_file.name)
|
| 48 |
+
blob.upload_from_file(pdf_file)
|
| 49 |
+
blob.make_public() # Make the file publicly accessible
|
| 50 |
+
return blob.public_url # Return the public URL of the uploaded PDF
|
| 51 |
+
pdf_file = st.file_uploader("Upload a project submission", type="pdf")
|
| 52 |
+
|
| 53 |
+
if pdf_file is not None:
|
| 54 |
+
start_page = 0
|
| 55 |
+
end_page = 117 # Adjust as necessary
|
| 56 |
+
submission_text = extract_text_from_pdf(pdf_file, start_page, end_page)
|
| 57 |
+
# Upload PDF to Firebase Storage
|
| 58 |
+
pdf_url = upload_pdf_to_storage(pdf_file)
|
| 59 |
+
# Save the PDF URL and extracted text to Firestore
|
| 60 |
+
if st.button("Upload"):
|
| 61 |
+
# Add the document and store the reference
|
| 62 |
+
doc_ref = db.collection('pdf_uploads').add({
|
| 63 |
+
'filename': pdf_file.name,
|
| 64 |
+
'text': submission_text,
|
| 65 |
+
'pdf_url': pdf_url,
|
| 66 |
+
'upload_time': firestore.SERVER_TIMESTAMP
|
| 67 |
+
})
|
| 68 |
+
doc_ref = doc_ref[1]
|
| 69 |
+
# Access the document ID correctly
|
| 70 |
+
st.success(f"File uploaded successfully with ID: {doc_ref.id}") # Accessing the id
|
| 71 |
+
|
| 72 |
|
| 73 |
# Rest of your code remains the same
|
| 74 |
|