Skip to content

Commit 9ce9c36

Browse files
authored
Add files via upload
1 parent 1a8e80b commit 9ce9c36

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

streamlit_app.py

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,55 @@
11
import streamlit as st
2-
import tempfile
3-
import os
4-
from google.oauth2 import service_account
2+
import pandas as pd
53
from googleapiclient.discovery import build
64
from googleapiclient.http import MediaFileUpload
5+
from google.oauth2.credentials import Credentials
6+
from google.auth.transport.requests import Request
7+
import os
78

8-
# Set page title
9-
st.set_page_config(page_title="Scientific Slide Library", page_icon="🔬")
10-
st.title("🔬 Scientific Slide Library Uploader")
11-
st.markdown("Use the form below to upload your slides and update the tracking sheet.")
9+
# --- 1. SETTINGS & AUTHENTICATION ---
1210

13-
# 1. AUTHENTICATION (Using Streamlit Secrets)
14-
try:
15-
# Get IDs and JSON contents from Secrets
16-
SHEET_ID = st.secrets["SHEET_ID"]
17-
FOLDER_ID = st.secrets["FOLDER_ID"]
18-
19-
# Map the service account keys from the [gcp_service_account] section in Secrets
20-
credentials_info = st.secrets["gcp_service_account"]
11+
# Replace these with your actual IDs
12+
SPREADSHEET_ID = st.secrets["SHEET_ID"]
13+
FOLDER_ID = st.secrets["FOLDER_ID"]
14+
15+
def get_gdrive_service():
16+
"""Authenticates using the OAuth Refresh Token from st.secrets"""
17+
creds_info = st.secrets["google_oauth"]
2118

22-
creds = service_account.Credentials.from_service_account_info(
23-
credentials_info,
24-
scopes=[
25-
"https://www.googleapis.com/auth/spreadsheets",
26-
"https://www.googleapis.com/auth/drive.file"
27-
]
19+
# Create credentials object using your specific Refresh Token
20+
creds = Credentials(
21+
token=None, # Access token starts empty
22+
refresh_token=creds_info["refresh_token"],
23+
client_id=creds_info["client_id"],
24+
client_secret=creds_info["client_secret"],
25+
token_uri="https://oauth2.googleapis.com/token"
2826
)
27+
28+
# Refresh the access token automatically if it's expired
29+
if not creds.valid:
30+
creds.refresh(Request())
31+
32+
# Build the services
33+
drive_service = build('drive', 'v3', credentials=creds)
34+
sheets_service = build('sheets', 'v4', credentials=creds)
2935

30-
# Build the API services
31-
sheets_service = build("sheets", "v4", credentials=creds)
32-
drive_service = build("drive", "v3", credentials=creds)
36+
return drive_service, sheets_service
37+
38+
# Initialize the services
39+
try:
40+
drive_service, sheets_service = get_gdrive_service()
3341
except Exception as e:
34-
st.error("⚠️ Authentication Error: Please check your Streamlit 'Secrets' configuration.")
42+
st.error(f"Authentication Failed: {e}")
3543
st.stop()
3644

45+
# --- APP INTERFACE START ---
46+
st.title("Scientific Slide Library")
47+
st.write("Upload your slides and details below.")
48+
3749
# 2. THE UPLOAD FORM
3850
with st.form("upload_form", clear_on_submit=True):
39-
name = st.text_input("Presenter Name")
51+
person = st.text_input("Your name")
52+
name = st.text_input("Name of Presentation")
4053
description = st.text_area("Topic/Description")
4154
keywords = st.text_input("Keywords (comma separated)")
4255

@@ -91,7 +104,7 @@
91104
# --- STEP B: UPDATE GOOGLE SHEET ---
92105
try:
93106
# Prepare row data
94-
row_data = [[name, description, keywords, file_link]]
107+
row_data = [[name, description, keywords, file_link, person]]
95108

96109
sheets_service.spreadsheets().values().append(
97110
spreadsheetId=SHEET_ID,

0 commit comments

Comments
 (0)