Update verifier.py
Browse files- verifier.py +64 -63
verifier.py
CHANGED
|
@@ -1,63 +1,64 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
firebase_admin.
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
if
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
| 1 |
+
def verifier_page():
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import firebase_admin
|
| 4 |
+
from firebase_admin import credentials, firestore
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
# Initialize Firebase
|
| 8 |
+
cred = credentials.Certificate('serviceAccountKey.json')
|
| 9 |
+
if not firebase_admin._apps:
|
| 10 |
+
firebase_admin.initialize_app(cred)
|
| 11 |
+
|
| 12 |
+
# Create a Firestore client
|
| 13 |
+
db = firestore.client()
|
| 14 |
+
|
| 15 |
+
# Fetch and display submissions
|
| 16 |
+
def fetch_data(selected_fields):
|
| 17 |
+
docs = db.collection('pdf_uploads').stream()
|
| 18 |
+
data = []
|
| 19 |
+
for doc in docs:
|
| 20 |
+
doc_dict = doc.to_dict()
|
| 21 |
+
filtered_data = {field: doc_dict.get(field) for field in selected_fields if field in doc_dict}
|
| 22 |
+
data.append(filtered_data)
|
| 23 |
+
return data
|
| 24 |
+
|
| 25 |
+
fields_to_fetch = ['filename', 'pdf_url', 'text']
|
| 26 |
+
|
| 27 |
+
# Create an empty placeholder for the data table and file details
|
| 28 |
+
data_placeholder = st.empty()
|
| 29 |
+
|
| 30 |
+
# Check if a file has already been selected and displayed
|
| 31 |
+
if 'selected_file' in st.session_state:
|
| 32 |
+
# When a file is selected, display details and hide the table
|
| 33 |
+
st.title(f"File Details: {st.session_state.selected_file}")
|
| 34 |
+
st.write(f"Text: {st.session_state.selected_text}")
|
| 35 |
+
else:
|
| 36 |
+
# Automatically load and display the data table on page load
|
| 37 |
+
data = fetch_data(fields_to_fetch)
|
| 38 |
+
if data:
|
| 39 |
+
df = pd.DataFrame(data)
|
| 40 |
+
|
| 41 |
+
# Use the placeholder to display the DataFrame
|
| 42 |
+
with data_placeholder:
|
| 43 |
+
st.dataframe(df)
|
| 44 |
+
|
| 45 |
+
# Add buttons for each row in the DataFrame
|
| 46 |
+
for index, row in df.iterrows():
|
| 47 |
+
col1, col2 = st.columns([4, 1])
|
| 48 |
+
with col1:
|
| 49 |
+
st.write(row['filename'])
|
| 50 |
+
|
| 51 |
+
with col2:
|
| 52 |
+
# Button to view details of each row
|
| 53 |
+
button_key = f"view_{index}"
|
| 54 |
+
if st.button(f"View {row['filename']}", key=button_key):
|
| 55 |
+
# Update the session state with the selected file details
|
| 56 |
+
st.session_state.selected_file = row['filename']
|
| 57 |
+
st.session_state.selected_text = row['text']
|
| 58 |
+
|
| 59 |
+
# Clear the data table and show file details
|
| 60 |
+
data_placeholder.empty()
|
| 61 |
+
|
| 62 |
+
# Display the file details
|
| 63 |
+
st.write(f"Selected File: {st.session_state.selected_file}")
|
| 64 |
+
st.write(f"Text: {st.session_state.selected_text}")
|