Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,7 +57,7 @@ def count_tokens(text):
|
|
| 57 |
return len(text.split())
|
| 58 |
|
| 59 |
# ===============================
|
| 60 |
-
# 3. Gmail Authentication Functions
|
| 61 |
# ===============================
|
| 62 |
def reset_session_state():
|
| 63 |
st.session_state.authenticated = False
|
|
@@ -78,6 +78,7 @@ def reset_session_state():
|
|
| 78 |
os.remove(filename)
|
| 79 |
|
| 80 |
def authenticate_gmail(credentials_file):
|
|
|
|
| 81 |
creds = None
|
| 82 |
if os.path.exists('token.json'):
|
| 83 |
try:
|
|
@@ -86,9 +87,7 @@ def authenticate_gmail(credentials_file):
|
|
| 86 |
if creds and creds.valid:
|
| 87 |
st.session_state.creds = creds
|
| 88 |
st.session_state.authenticated = True
|
| 89 |
-
|
| 90 |
-
st.success("β
Authentication successful!")
|
| 91 |
-
st.session_state.candidates_message_shown = True
|
| 92 |
return creds
|
| 93 |
except Exception as e:
|
| 94 |
st.error(f"β Invalid token.json file: {e}")
|
|
@@ -98,9 +97,7 @@ def authenticate_gmail(credentials_file):
|
|
| 98 |
creds.refresh(Request())
|
| 99 |
st.session_state.creds = creds
|
| 100 |
st.session_state.authenticated = True
|
| 101 |
-
|
| 102 |
-
st.success("β
Authentication successful!")
|
| 103 |
-
st.session_state.candidates_message_shown = True
|
| 104 |
with open('token.json', 'w') as token_file:
|
| 105 |
token_file.write(creds.to_json())
|
| 106 |
return creds
|
|
@@ -118,11 +115,9 @@ def submit_auth_code():
|
|
| 118 |
st.session_state.flow.fetch_token(code=st.session_state.auth_code)
|
| 119 |
st.session_state.creds = st.session_state.flow.credentials
|
| 120 |
st.session_state.authenticated = True
|
| 121 |
-
if not st.session_state.candidates_message_shown:
|
| 122 |
-
st.success("β
Authentication successful!")
|
| 123 |
-
st.session_state.candidates_message_shown = True
|
| 124 |
with open('token.json', 'w') as token_file:
|
| 125 |
-
|
|
|
|
| 126 |
except Exception as e:
|
| 127 |
st.error(f"β Error during authentication: {e}")
|
| 128 |
|
|
|
|
| 57 |
return len(text.split())
|
| 58 |
|
| 59 |
# ===============================
|
| 60 |
+
# 3. Gmail Authentication Functions (Updated)
|
| 61 |
# ===============================
|
| 62 |
def reset_session_state():
|
| 63 |
st.session_state.authenticated = False
|
|
|
|
| 78 |
os.remove(filename)
|
| 79 |
|
| 80 |
def authenticate_gmail(credentials_file):
|
| 81 |
+
SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']
|
| 82 |
creds = None
|
| 83 |
if os.path.exists('token.json'):
|
| 84 |
try:
|
|
|
|
| 87 |
if creds and creds.valid:
|
| 88 |
st.session_state.creds = creds
|
| 89 |
st.session_state.authenticated = True
|
| 90 |
+
st.success("β
Authentication successful!")
|
|
|
|
|
|
|
| 91 |
return creds
|
| 92 |
except Exception as e:
|
| 93 |
st.error(f"β Invalid token.json file: {e}")
|
|
|
|
| 97 |
creds.refresh(Request())
|
| 98 |
st.session_state.creds = creds
|
| 99 |
st.session_state.authenticated = True
|
| 100 |
+
st.success("β
Authentication successful!")
|
|
|
|
|
|
|
| 101 |
with open('token.json', 'w') as token_file:
|
| 102 |
token_file.write(creds.to_json())
|
| 103 |
return creds
|
|
|
|
| 115 |
st.session_state.flow.fetch_token(code=st.session_state.auth_code)
|
| 116 |
st.session_state.creds = st.session_state.flow.credentials
|
| 117 |
st.session_state.authenticated = True
|
|
|
|
|
|
|
|
|
|
| 118 |
with open('token.json', 'w') as token_file:
|
| 119 |
+
st.session_state.creds.to_json(token_file)
|
| 120 |
+
st.success("β
Authentication successful!")
|
| 121 |
except Exception as e:
|
| 122 |
st.error(f"β Error during authentication: {e}")
|
| 123 |
|