Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,13 @@ REDIRECT_URI = 'https://huggingface.co/spaces/awacke1/MSGraphAPI' # π Make s
|
|
| 15 |
# π― Define the scopes your app will need
|
| 16 |
SCOPES = ['User.Read', 'Calendars.ReadWrite', 'Mail.ReadWrite', 'Notes.ReadWrite.All', 'Files.ReadWrite.All']
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# π οΈ Initialize the MSAL client
|
| 19 |
def get_msal_app():
|
| 20 |
return msal.ConfidentialClientApplication(
|
|
@@ -51,10 +58,66 @@ def get_access_token(code):
|
|
| 51 |
#st.stop()
|
| 52 |
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
def process_query_parms():
|
| 55 |
# βοΈq= Run ArXiv search from query parameters
|
| 56 |
try:
|
| 57 |
query_params = st.query_params
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
query = (query_params.get('q') or query_params.get('query') or [''])
|
| 59 |
if len(query) > 1:
|
| 60 |
#result = search_arxiv(query)
|
|
@@ -85,225 +148,252 @@ def process_query_parms():
|
|
| 85 |
# πββοΈ Main application function
|
| 86 |
def main():
|
| 87 |
st.title("π¦ Simple Streamlit App with MS Graph API")
|
|
|
|
|
|
|
| 88 |
|
| 89 |
-
|
| 90 |
-
st.sidebar.title("Navigation")
|
| 91 |
-
menu = st.sidebar.radio("Go to", [
|
| 92 |
-
"1οΈβ£ Dashboard with Widgets",
|
| 93 |
-
"π Landing Page",
|
| 94 |
-
"π
Upcoming Events",
|
| 95 |
-
"π Schedule",
|
| 96 |
-
"π Agenda",
|
| 97 |
-
"π Event Details",
|
| 98 |
-
"β Add Event",
|
| 99 |
-
"π Filter By"
|
| 100 |
-
])
|
| 101 |
-
|
| 102 |
-
# π M365 Products with MS Graph Integration & AI Features
|
| 103 |
-
st.sidebar.title("π M365 Products")
|
| 104 |
-
st.sidebar.write("Toggle integration for each product:")
|
| 105 |
-
|
| 106 |
-
# ποΈ Product Integration Toggles
|
| 107 |
-
products = {
|
| 108 |
-
"π§ Outlook": {
|
| 109 |
-
"ai_capabilities": "Copilot for enhanced email writing, calendar management, and scheduling.",
|
| 110 |
-
"graph_api": "Access to mail, calendar, contacts, and events."
|
| 111 |
-
},
|
| 112 |
-
"π OneNote": {
|
| 113 |
-
"ai_capabilities": "Content suggestion, note organization, and OCR for extracting text from images.",
|
| 114 |
-
"graph_api": "Manage notebooks, sections, and pages."
|
| 115 |
-
},
|
| 116 |
-
"π Excel": {
|
| 117 |
-
"ai_capabilities": "Copilot for advanced data analysis, data insights, and formula generation.",
|
| 118 |
-
"graph_api": "Create and manage worksheets, tables, charts, and workbooks."
|
| 119 |
-
},
|
| 120 |
-
"π Word": {
|
| 121 |
-
"ai_capabilities": "Copilot for document drafting, summarization, and grammar improvements.",
|
| 122 |
-
"graph_api": "Document content access, templates, and file management."
|
| 123 |
-
},
|
| 124 |
-
"ποΈ SharePoint": {
|
| 125 |
-
"ai_capabilities": "Intelligent search, document tagging, and metadata extraction.",
|
| 126 |
-
"graph_api": "Access to sites, lists, files, and document libraries."
|
| 127 |
-
},
|
| 128 |
-
"π
Teams": {
|
| 129 |
-
"ai_capabilities": "Copilot for meeting summaries, transcription, and chat suggestions.",
|
| 130 |
-
"graph_api": "Manage chats, teams, channels, and meetings."
|
| 131 |
-
},
|
| 132 |
-
"π¬ Viva": {
|
| 133 |
-
"ai_capabilities": "Personalized learning insights, well-being insights, and productivity suggestions.",
|
| 134 |
-
"graph_api": "Access to user analytics and learning modules."
|
| 135 |
-
},
|
| 136 |
-
"π Power Platform": {
|
| 137 |
-
"ai_capabilities": "Automation with AI Builder, data insights, and custom AI models.",
|
| 138 |
-
"graph_api": "Automation workflows, app creation, and data visualization."
|
| 139 |
-
},
|
| 140 |
-
"π§ Copilot": {
|
| 141 |
-
"ai_capabilities": "Embedded across Word, Excel, Outlook, Teams, and more for AI-driven productivity.",
|
| 142 |
-
"graph_api": "Underpins Copilot's access to data and integrations."
|
| 143 |
-
},
|
| 144 |
-
"ποΈ OneDrive": {
|
| 145 |
-
"ai_capabilities": "Intelligent file organization and search.",
|
| 146 |
-
"graph_api": "File and folder access, sharing, and metadata."
|
| 147 |
-
},
|
| 148 |
-
"π‘ PowerPoint": {
|
| 149 |
-
"ai_capabilities": "Design suggestions, presentation summarization, and speaker coaching.",
|
| 150 |
-
"graph_api": "Presentation creation, slide management, and templates."
|
| 151 |
-
},
|
| 152 |
-
"π Microsoft Bookings": {
|
| 153 |
-
"ai_capabilities": "Automated scheduling and reminders.",
|
| 154 |
-
"graph_api": "Booking calendars, services, and appointment details."
|
| 155 |
-
},
|
| 156 |
-
"π Loop": {
|
| 157 |
-
"ai_capabilities": "Real-time collaboration and content suggestions.",
|
| 158 |
-
"graph_api": "Access to shared workspaces and collaborative pages."
|
| 159 |
-
},
|
| 160 |
-
"π£οΈ Translator": {
|
| 161 |
-
"ai_capabilities": "Real-time language translation and text-to-speech.",
|
| 162 |
-
"graph_api": "Integrated into communication and translation services."
|
| 163 |
-
},
|
| 164 |
-
"π To Do & Planner": {
|
| 165 |
-
"ai_capabilities": "Task prioritization and smart reminders.",
|
| 166 |
-
"graph_api": "Task creation, management, and synchronization."
|
| 167 |
-
},
|
| 168 |
-
"π Azure OpenAI Service": {
|
| 169 |
-
"ai_capabilities": "Access to GPT models for custom AI implementations.",
|
| 170 |
-
"graph_api": "Used indirectly for building custom AI models into workflows."
|
| 171 |
-
}
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
# π³οΈ Create toggles for each product
|
| 175 |
-
selected_products = {}
|
| 176 |
-
for product, info in products.items():
|
| 177 |
-
selected = st.sidebar.checkbox(product)
|
| 178 |
-
if selected:
|
| 179 |
-
st.sidebar.write(f"**AI Capabilities:** {info['ai_capabilities']}")
|
| 180 |
-
st.sidebar.write(f"**Graph API:** {info['graph_api']}")
|
| 181 |
-
selected_products[product] = True
|
| 182 |
|
| 183 |
-
# π Authentication
|
| 184 |
if 'access_token' not in st.session_state:
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
#st.write('Parsing query ' + query_params )
|
| 191 |
-
if 'code' in query_params:
|
| 192 |
-
#code = query_params['code'][0]
|
| 193 |
-
code = query_params.get('code')
|
| 194 |
-
|
| 195 |
-
st.write('πAccess Code Obtained from MS Graph Redirectπ!:' + code)
|
| 196 |
-
|
| 197 |
-
st.write('π Acquiring access token from redirect URL for code parameter.')
|
| 198 |
-
access_token = get_access_token(code)
|
| 199 |
-
|
| 200 |
-
st.session_state['access_token'] = access_token # π Save it for later
|
| 201 |
-
|
| 202 |
-
st.rerun() # Reload the app to clear the code from URL
|
| 203 |
else:
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
authorization_url = client_instance.get_authorization_request_url(
|
| 207 |
-
scopes=SCOPES,
|
| 208 |
-
redirect_uri=REDIRECT_URI
|
| 209 |
-
)
|
| 210 |
-
st.write('π Please [click here]({}) to log in and authorize the app.'.format(authorization_url))
|
| 211 |
-
st.stop()
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
else:
|
| 215 |
-
# π₯³ User is authenticated, proceed with the app
|
| 216 |
-
access_token = st.session_state['access_token']
|
| 217 |
-
headers = {'Authorization': 'Bearer ' + access_token}
|
| 218 |
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
st.write("Widgets will be displayed here. ποΈ")
|
| 232 |
-
# Add your widgets here
|
| 233 |
-
|
| 234 |
-
elif menu == "π Landing Page":
|
| 235 |
-
st.header("π Landing Page")
|
| 236 |
-
st.write("Welcome to the app! π₯³")
|
| 237 |
-
# Add landing page content here
|
| 238 |
-
|
| 239 |
-
elif menu == "π
Upcoming Events":
|
| 240 |
-
st.header("π
Upcoming Events")
|
| 241 |
-
events = get_upcoming_events(access_token)
|
| 242 |
-
for event in events:
|
| 243 |
-
st.write(f"π {event['subject']} on {event['start']['dateTime']}")
|
| 244 |
-
# Display upcoming events
|
| 245 |
-
|
| 246 |
-
elif menu == "π Schedule":
|
| 247 |
-
st.header("π Schedule")
|
| 248 |
-
schedule = get_schedule(access_token)
|
| 249 |
-
st.write(schedule)
|
| 250 |
-
# Display schedule
|
| 251 |
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
if event_id:
|
| 261 |
-
event_details = get_event_details(access_token, event_id)
|
| 262 |
-
st.write(event_details)
|
| 263 |
-
# Display event details based on ID
|
| 264 |
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
|
| 297 |
-
#
|
| 298 |
-
if
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
# π§© Function to handle product integration
|
| 308 |
def handle_product_integration(access_token, product):
|
| 309 |
if product == "π§ Outlook":
|
|
|
|
| 15 |
# π― Define the scopes your app will need
|
| 16 |
SCOPES = ['User.Read', 'Calendars.ReadWrite', 'Mail.ReadWrite', 'Notes.ReadWrite.All', 'Files.ReadWrite.All']
|
| 17 |
|
| 18 |
+
# New function to generate PKCE code verifier and challenge
|
| 19 |
+
def generate_pkce_codes():
|
| 20 |
+
code_verifier = secrets.token_urlsafe(64)
|
| 21 |
+
code_challenge = base64.urlsafe_b64encode(hashlib.sha256(code_verifier.encode()).digest()).decode().rstrip('=')
|
| 22 |
+
return code_verifier, code_challenge
|
| 23 |
+
|
| 24 |
+
|
| 25 |
# π οΈ Initialize the MSAL client
|
| 26 |
def get_msal_app():
|
| 27 |
return msal.ConfidentialClientApplication(
|
|
|
|
| 58 |
#st.stop()
|
| 59 |
|
| 60 |
|
| 61 |
+
def get_access_token(code, code_verifier):
|
| 62 |
+
client_instance = get_msal_app()
|
| 63 |
+
|
| 64 |
+
st.write("Debug: MSAL App Configuration:")
|
| 65 |
+
st.write(f"Client ID: {APPLICATION_ID_KEY[:5]}...")
|
| 66 |
+
st.write(f"Authority: {AUTHORITY_URL}")
|
| 67 |
+
st.write(f"Redirect URI: {REDIRECT_URI}")
|
| 68 |
+
|
| 69 |
+
try:
|
| 70 |
+
result = client_instance.acquire_token_by_authorization_code(
|
| 71 |
+
code=code,
|
| 72 |
+
scopes=SCOPES,
|
| 73 |
+
redirect_uri=REDIRECT_URI,
|
| 74 |
+
code_verifier=code_verifier # Include the code verifier here
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
if 'access_token' in result:
|
| 78 |
+
return result['access_token']
|
| 79 |
+
else:
|
| 80 |
+
error_description = result.get('error_description', 'No error description provided')
|
| 81 |
+
raise Exception(f"Error acquiring token: {error_description}")
|
| 82 |
+
except Exception as e:
|
| 83 |
+
st.error(f"Exception in get_access_token: {str(e)}")
|
| 84 |
+
raise
|
| 85 |
+
|
| 86 |
def process_query_parms():
|
| 87 |
# βοΈq= Run ArXiv search from query parameters
|
| 88 |
try:
|
| 89 |
query_params = st.query_params
|
| 90 |
+
st.write("Debug: All query parameters:", query_params)
|
| 91 |
+
|
| 92 |
+
if 'error' in query_params:
|
| 93 |
+
error = query_params.get('error')
|
| 94 |
+
error_description = query_params.get('error_description', 'No description provided')
|
| 95 |
+
st.error(f"Authentication Error: {error}")
|
| 96 |
+
st.error(f"Error Description: {urllib.parse.unquote(error_description)}")
|
| 97 |
+
st.stop()
|
| 98 |
+
|
| 99 |
+
if 'code' in query_params:
|
| 100 |
+
code = query_params.get('code')
|
| 101 |
+
st.write('π Authorization Code Obtained:', code[:10] + '...')
|
| 102 |
+
|
| 103 |
+
try:
|
| 104 |
+
# Retrieve the code verifier from session state
|
| 105 |
+
code_verifier = st.session_state.get('code_verifier')
|
| 106 |
+
if not code_verifier:
|
| 107 |
+
st.error("Code verifier not found in session state.")
|
| 108 |
+
st.stop()
|
| 109 |
+
|
| 110 |
+
access_token = get_access_token(code, code_verifier)
|
| 111 |
+
st.session_state['access_token'] = access_token
|
| 112 |
+
st.success("Access token acquired successfully!")
|
| 113 |
+
st.rerun()
|
| 114 |
+
except Exception as e:
|
| 115 |
+
st.error(f"Error acquiring access token: {str(e)}")
|
| 116 |
+
st.stop()
|
| 117 |
+
else:
|
| 118 |
+
st.warning("No authorization code found in the query parameters.")
|
| 119 |
+
|
| 120 |
+
|
| 121 |
query = (query_params.get('q') or query_params.get('query') or [''])
|
| 122 |
if len(query) > 1:
|
| 123 |
#result = search_arxiv(query)
|
|
|
|
| 148 |
# πββοΈ Main application function
|
| 149 |
def main():
|
| 150 |
st.title("π¦ Simple Streamlit App with MS Graph API")
|
| 151 |
+
|
| 152 |
+
|
| 153 |
|
| 154 |
+
process_query_params()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
|
|
|
| 156 |
if 'access_token' not in st.session_state:
|
| 157 |
+
if 'code_verifier' not in st.session_state:
|
| 158 |
+
# Generate PKCE codes
|
| 159 |
+
code_verifier, code_challenge = generate_pkce_codes()
|
| 160 |
+
st.session_state['code_verifier'] = code_verifier
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
else:
|
| 162 |
+
code_verifier = st.session_state['code_verifier']
|
| 163 |
+
code_challenge = base64.urlsafe_b64encode(hashlib.sha256(code_verifier.encode()).digest()).decode().rstrip('=')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
+
client_instance = get_msal_app()
|
| 166 |
+
auth_url = client_instance.get_authorization_request_url(
|
| 167 |
+
scopes=SCOPES,
|
| 168 |
+
redirect_uri=REDIRECT_URI,
|
| 169 |
+
code_challenge=code_challenge,
|
| 170 |
+
code_challenge_method="S256"
|
| 171 |
+
)
|
| 172 |
+
st.write('π Please [click here]({}) to log in and authorize the app.'.format(auth_url))
|
| 173 |
+
st.stop()
|
| 174 |
+
else:
|
| 175 |
+
|
| 176 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
+
# π Sidebar navigation
|
| 179 |
+
st.sidebar.title("Navigation")
|
| 180 |
+
menu = st.sidebar.radio("Go to", [
|
| 181 |
+
"1οΈβ£ Dashboard with Widgets",
|
| 182 |
+
"π Landing Page",
|
| 183 |
+
"π
Upcoming Events",
|
| 184 |
+
"π Schedule",
|
| 185 |
+
"π Agenda",
|
| 186 |
+
"π Event Details",
|
| 187 |
+
"β Add Event",
|
| 188 |
+
"π Filter By"
|
| 189 |
+
])
|
| 190 |
|
| 191 |
+
# π M365 Products with MS Graph Integration & AI Features
|
| 192 |
+
st.sidebar.title("π M365 Products")
|
| 193 |
+
st.sidebar.write("Toggle integration for each product:")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
+
# ποΈ Product Integration Toggles
|
| 196 |
+
products = {
|
| 197 |
+
"π§ Outlook": {
|
| 198 |
+
"ai_capabilities": "Copilot for enhanced email writing, calendar management, and scheduling.",
|
| 199 |
+
"graph_api": "Access to mail, calendar, contacts, and events."
|
| 200 |
+
},
|
| 201 |
+
"π OneNote": {
|
| 202 |
+
"ai_capabilities": "Content suggestion, note organization, and OCR for extracting text from images.",
|
| 203 |
+
"graph_api": "Manage notebooks, sections, and pages."
|
| 204 |
+
},
|
| 205 |
+
"π Excel": {
|
| 206 |
+
"ai_capabilities": "Copilot for advanced data analysis, data insights, and formula generation.",
|
| 207 |
+
"graph_api": "Create and manage worksheets, tables, charts, and workbooks."
|
| 208 |
+
},
|
| 209 |
+
"π Word": {
|
| 210 |
+
"ai_capabilities": "Copilot for document drafting, summarization, and grammar improvements.",
|
| 211 |
+
"graph_api": "Document content access, templates, and file management."
|
| 212 |
+
},
|
| 213 |
+
"ποΈ SharePoint": {
|
| 214 |
+
"ai_capabilities": "Intelligent search, document tagging, and metadata extraction.",
|
| 215 |
+
"graph_api": "Access to sites, lists, files, and document libraries."
|
| 216 |
+
},
|
| 217 |
+
"π
Teams": {
|
| 218 |
+
"ai_capabilities": "Copilot for meeting summaries, transcription, and chat suggestions.",
|
| 219 |
+
"graph_api": "Manage chats, teams, channels, and meetings."
|
| 220 |
+
},
|
| 221 |
+
"π¬ Viva": {
|
| 222 |
+
"ai_capabilities": "Personalized learning insights, well-being insights, and productivity suggestions.",
|
| 223 |
+
"graph_api": "Access to user analytics and learning modules."
|
| 224 |
+
},
|
| 225 |
+
"π Power Platform": {
|
| 226 |
+
"ai_capabilities": "Automation with AI Builder, data insights, and custom AI models.",
|
| 227 |
+
"graph_api": "Automation workflows, app creation, and data visualization."
|
| 228 |
+
},
|
| 229 |
+
"π§ Copilot": {
|
| 230 |
+
"ai_capabilities": "Embedded across Word, Excel, Outlook, Teams, and more for AI-driven productivity.",
|
| 231 |
+
"graph_api": "Underpins Copilot's access to data and integrations."
|
| 232 |
+
},
|
| 233 |
+
"ποΈ OneDrive": {
|
| 234 |
+
"ai_capabilities": "Intelligent file organization and search.",
|
| 235 |
+
"graph_api": "File and folder access, sharing, and metadata."
|
| 236 |
+
},
|
| 237 |
+
"π‘ PowerPoint": {
|
| 238 |
+
"ai_capabilities": "Design suggestions, presentation summarization, and speaker coaching.",
|
| 239 |
+
"graph_api": "Presentation creation, slide management, and templates."
|
| 240 |
+
},
|
| 241 |
+
"π Microsoft Bookings": {
|
| 242 |
+
"ai_capabilities": "Automated scheduling and reminders.",
|
| 243 |
+
"graph_api": "Booking calendars, services, and appointment details."
|
| 244 |
+
},
|
| 245 |
+
"π Loop": {
|
| 246 |
+
"ai_capabilities": "Real-time collaboration and content suggestions.",
|
| 247 |
+
"graph_api": "Access to shared workspaces and collaborative pages."
|
| 248 |
+
},
|
| 249 |
+
"π£οΈ Translator": {
|
| 250 |
+
"ai_capabilities": "Real-time language translation and text-to-speech.",
|
| 251 |
+
"graph_api": "Integrated into communication and translation services."
|
| 252 |
+
},
|
| 253 |
+
"π To Do & Planner": {
|
| 254 |
+
"ai_capabilities": "Task prioritization and smart reminders.",
|
| 255 |
+
"graph_api": "Task creation, management, and synchronization."
|
| 256 |
+
},
|
| 257 |
+
"π Azure OpenAI Service": {
|
| 258 |
+
"ai_capabilities": "Access to GPT models for custom AI implementations.",
|
| 259 |
+
"graph_api": "Used indirectly for building custom AI models into workflows."
|
| 260 |
+
}
|
| 261 |
+
}
|
| 262 |
|
| 263 |
+
# π³οΈ Create toggles for each product
|
| 264 |
+
selected_products = {}
|
| 265 |
+
for product, info in products.items():
|
| 266 |
+
selected = st.sidebar.checkbox(product)
|
| 267 |
+
if selected:
|
| 268 |
+
st.sidebar.write(f"**AI Capabilities:** {info['ai_capabilities']}")
|
| 269 |
+
st.sidebar.write(f"**Graph API:** {info['graph_api']}")
|
| 270 |
+
selected_products[product] = True
|
| 271 |
|
| 272 |
+
# π Authentication
|
| 273 |
+
if 'access_token' not in st.session_state:
|
| 274 |
+
# π΅οΈββοΈ Check for authorization code in query parameters
|
| 275 |
+
query_params = st.query_params
|
| 276 |
+
query = (query_params.get('code'))
|
| 277 |
+
#if len(query) > 1:
|
| 278 |
+
|
| 279 |
+
#st.write('Parsing query ' + query_params )
|
| 280 |
+
if 'code' in query_params:
|
| 281 |
+
#code = query_params['code'][0]
|
| 282 |
+
code = query_params.get('code')
|
| 283 |
+
|
| 284 |
+
st.write('πAccess Code Obtained from MS Graph Redirectπ!:' + code)
|
| 285 |
+
|
| 286 |
+
st.write('π Acquiring access token from redirect URL for code parameter.')
|
| 287 |
+
access_token = get_access_token(code)
|
| 288 |
+
|
| 289 |
+
st.session_state['access_token'] = access_token # π Save it for later
|
| 290 |
+
|
| 291 |
+
st.rerun() # Reload the app to clear the code from URL
|
| 292 |
+
else:
|
| 293 |
+
# π’ Prompt user to log in
|
| 294 |
+
client_instance = get_msal_app()
|
| 295 |
+
authorization_url = client_instance.get_authorization_request_url(
|
| 296 |
+
scopes=SCOPES,
|
| 297 |
+
redirect_uri=REDIRECT_URI
|
| 298 |
+
)
|
| 299 |
+
st.write('π Please [click here]({}) to log in and authorize the app.'.format(authorization_url))
|
| 300 |
+
st.stop()
|
| 301 |
|
| 302 |
+
|
| 303 |
+
else:
|
| 304 |
+
# π₯³ User is authenticated, proceed with the app
|
| 305 |
+
access_token = st.session_state['access_token']
|
| 306 |
+
headers = {'Authorization': 'Bearer ' + access_token}
|
| 307 |
+
|
| 308 |
+
# π€ Greet the user
|
| 309 |
+
response = requests.get('https://graph.microsoft.com/v1.0/me', headers=headers)
|
| 310 |
+
if response.status_code == 200:
|
| 311 |
+
user_info = response.json()
|
| 312 |
+
st.sidebar.write(f"π Hello, {user_info['displayName']}!")
|
| 313 |
+
else:
|
| 314 |
+
st.error('Failed to fetch user info.')
|
| 315 |
+
st.write(response.text)
|
| 316 |
+
|
| 317 |
+
# ποΈ Handle menu options
|
| 318 |
+
if menu == "1οΈβ£ Dashboard with Widgets":
|
| 319 |
+
st.header("1οΈβ£ Dashboard with Widgets")
|
| 320 |
+
st.write("Widgets will be displayed here. ποΈ")
|
| 321 |
+
# Add your widgets here
|
| 322 |
+
|
| 323 |
+
elif menu == "π Landing Page":
|
| 324 |
+
st.header("π Landing Page")
|
| 325 |
+
st.write("Welcome to the app! π₯³")
|
| 326 |
+
# Add landing page content here
|
| 327 |
+
|
| 328 |
+
elif menu == "π
Upcoming Events":
|
| 329 |
+
st.header("π
Upcoming Events")
|
| 330 |
+
events = get_upcoming_events(access_token)
|
| 331 |
+
for event in events:
|
| 332 |
+
st.write(f"π {event['subject']} on {event['start']['dateTime']}")
|
| 333 |
+
# Display upcoming events
|
| 334 |
+
|
| 335 |
+
elif menu == "π Schedule":
|
| 336 |
+
st.header("π Schedule")
|
| 337 |
+
schedule = get_schedule(access_token)
|
| 338 |
+
st.write(schedule)
|
| 339 |
+
# Display schedule
|
| 340 |
+
|
| 341 |
+
elif menu == "π Agenda":
|
| 342 |
+
st.header("π Agenda")
|
| 343 |
+
st.write("Your agenda for today. π")
|
| 344 |
+
# Display agenda
|
| 345 |
+
|
| 346 |
+
elif menu == "π Event Details":
|
| 347 |
+
st.header("π Event Details")
|
| 348 |
+
event_id = st.text_input("Enter Event ID")
|
| 349 |
+
if event_id:
|
| 350 |
+
event_details = get_event_details(access_token, event_id)
|
| 351 |
+
st.write(event_details)
|
| 352 |
+
# Display event details based on ID
|
| 353 |
+
|
| 354 |
+
elif menu == "β Add Event":
|
| 355 |
+
st.header("β Add Event")
|
| 356 |
+
event_subject = st.text_input("Event Subject")
|
| 357 |
+
event_start = st.date_input("Event Start Date")
|
| 358 |
+
event_start_time = st.time_input("Event Start Time")
|
| 359 |
+
event_end = st.date_input("Event End Date")
|
| 360 |
+
event_end_time = st.time_input("Event End Time")
|
| 361 |
+
if st.button("Add Event"):
|
| 362 |
+
event_details = {
|
| 363 |
+
"subject": event_subject,
|
| 364 |
+
"start": {
|
| 365 |
+
"dateTime": f"{event_start}T{event_start_time}",
|
| 366 |
+
"timeZone": "UTC"
|
| 367 |
+
},
|
| 368 |
+
"end": {
|
| 369 |
+
"dateTime": f"{event_end}T{event_end_time}",
|
| 370 |
+
"timeZone": "UTC"
|
| 371 |
+
}
|
| 372 |
+
}
|
| 373 |
+
add_event(access_token, event_details)
|
| 374 |
+
st.success("Event added successfully! π")
|
| 375 |
+
# Form to add new event
|
| 376 |
+
|
| 377 |
+
elif menu == "π Filter By":
|
| 378 |
+
st.header("π Filter Events")
|
| 379 |
+
filter_criteria = st.text_input("Enter filter criteria")
|
| 380 |
+
if filter_criteria:
|
| 381 |
+
filtered_events = filter_events(access_token, filter_criteria)
|
| 382 |
+
for event in filtered_events:
|
| 383 |
+
st.write(f"π
{event['subject']} on {event['start']['dateTime']}")
|
| 384 |
+
# Filter events based on criteria
|
| 385 |
+
|
| 386 |
+
# π§© Handle selected products
|
| 387 |
+
if selected_products:
|
| 388 |
+
st.header("π§© M365 Product Integrations")
|
| 389 |
+
for product in selected_products:
|
| 390 |
+
st.subheader(f"{product}")
|
| 391 |
+
# Call the function corresponding to the product
|
| 392 |
+
handle_product_integration(access_token, product)
|
| 393 |
+
else:
|
| 394 |
+
st.write("No products selected.")
|
| 395 |
+
pass
|
| 396 |
+
|
| 397 |
# π§© Function to handle product integration
|
| 398 |
def handle_product_integration(access_token, product):
|
| 399 |
if product == "π§ Outlook":
|