Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -179,229 +179,227 @@ def main():
|
|
| 179 |
code_challenge_method="S256"
|
| 180 |
)
|
| 181 |
st.write('π Please [click here]({}) to log in and authorize the app.'.format(auth_url))
|
| 182 |
-
st.stop()
|
| 183 |
-
else:
|
| 184 |
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
"
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
"
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
"
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
"
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
"
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
"
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
"
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
"
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
"
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
"
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
"
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
"
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
"
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
"
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
"
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
"
|
| 267 |
-
|
| 268 |
-
"graph_api": "Used indirectly for building custom AI models into workflows."
|
| 269 |
-
}
|
| 270 |
}
|
| 271 |
-
|
| 272 |
-
# π³οΈ Create toggles for each product
|
| 273 |
-
selected_products = {}
|
| 274 |
-
for product, info in products.items():
|
| 275 |
-
selected = st.sidebar.checkbox(product)
|
| 276 |
-
if selected:
|
| 277 |
-
st.sidebar.write(f"**AI Capabilities:** {info['ai_capabilities']}")
|
| 278 |
-
st.sidebar.write(f"**Graph API:** {info['graph_api']}")
|
| 279 |
-
selected_products[product] = True
|
| 280 |
-
|
| 281 |
-
# π Authentication
|
| 282 |
-
if 'access_token' not in st.session_state:
|
| 283 |
-
# π΅οΈββοΈ Check for authorization code in query parameters
|
| 284 |
-
query_params = st.query_params
|
| 285 |
-
query = (query_params.get('code'))
|
| 286 |
-
#if len(query) > 1:
|
| 287 |
-
|
| 288 |
-
#st.write('Parsing query ' + query_params )
|
| 289 |
-
if 'code' in query_params:
|
| 290 |
-
#code = query_params['code'][0]
|
| 291 |
-
code = query_params.get('code')
|
| 292 |
-
|
| 293 |
-
st.write('πAccess Code Obtained from MS Graph Redirectπ!:' + code)
|
| 294 |
-
|
| 295 |
-
st.write('π Acquiring access token from redirect URL for code parameter.')
|
| 296 |
-
access_token = get_access_token(code)
|
| 297 |
-
|
| 298 |
-
st.session_state['access_token'] = access_token # π Save it for later
|
| 299 |
-
|
| 300 |
-
st.rerun() # Reload the app to clear the code from URL
|
| 301 |
-
else:
|
| 302 |
-
# π’ Prompt user to log in
|
| 303 |
-
client_instance = get_msal_app()
|
| 304 |
-
authorization_url = client_instance.get_authorization_request_url(
|
| 305 |
-
scopes=SCOPES,
|
| 306 |
-
redirect_uri=REDIRECT_URI
|
| 307 |
-
)
|
| 308 |
-
st.write('π Please [click here]({}) to log in and authorize the app.'.format(authorization_url))
|
| 309 |
-
st.stop()
|
| 310 |
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
elif menu == "π Landing Page":
|
| 333 |
-
st.header("π Landing Page")
|
| 334 |
-
st.write("Welcome to the app! π₯³")
|
| 335 |
-
# Add landing page content here
|
| 336 |
-
|
| 337 |
-
elif menu == "π
Upcoming Events":
|
| 338 |
-
st.header("π
Upcoming Events")
|
| 339 |
-
events = get_upcoming_events(access_token)
|
| 340 |
-
for event in events:
|
| 341 |
-
st.write(f"π {event['subject']} on {event['start']['dateTime']}")
|
| 342 |
-
# Display upcoming events
|
| 343 |
|
| 344 |
-
|
| 345 |
-
st.header("π Schedule")
|
| 346 |
-
schedule = get_schedule(access_token)
|
| 347 |
-
st.write(schedule)
|
| 348 |
-
# Display schedule
|
| 349 |
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
st.write("Your agenda for today. π")
|
| 353 |
-
# Display agenda
|
| 354 |
|
| 355 |
-
|
| 356 |
-
st.header("π Event Details")
|
| 357 |
-
event_id = st.text_input("Enter Event ID")
|
| 358 |
-
if event_id:
|
| 359 |
-
event_details = get_event_details(access_token, event_id)
|
| 360 |
-
st.write(event_details)
|
| 361 |
-
# Display event details based on ID
|
| 362 |
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
}
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
|
|
|
| 405 |
|
| 406 |
# π§© Function to handle product integration
|
| 407 |
def handle_product_integration(access_token, product):
|
|
|
|
| 179 |
code_challenge_method="S256"
|
| 180 |
)
|
| 181 |
st.write('π Please [click here]({}) to log in and authorize the app.'.format(auth_url))
|
| 182 |
+
#st.stop()
|
|
|
|
| 183 |
|
| 184 |
+
|
| 185 |
+
# π Sidebar navigation
|
| 186 |
+
st.sidebar.title("Navigation")
|
| 187 |
+
menu = st.sidebar.radio("Go to", [
|
| 188 |
+
"1οΈβ£ Dashboard with Widgets",
|
| 189 |
+
"π Landing Page",
|
| 190 |
+
"π
Upcoming Events",
|
| 191 |
+
"π Schedule",
|
| 192 |
+
"π Agenda",
|
| 193 |
+
"π Event Details",
|
| 194 |
+
"β Add Event",
|
| 195 |
+
"π Filter By"
|
| 196 |
+
])
|
| 197 |
+
|
| 198 |
+
# π M365 Products with MS Graph Integration & AI Features
|
| 199 |
+
st.sidebar.title("π M365 Products")
|
| 200 |
+
st.sidebar.write("Toggle integration for each product:")
|
| 201 |
+
|
| 202 |
+
# ποΈ Product Integration Toggles
|
| 203 |
+
products = {
|
| 204 |
+
"π§ Outlook": {
|
| 205 |
+
"ai_capabilities": "Copilot for enhanced email writing, calendar management, and scheduling.",
|
| 206 |
+
"graph_api": "Access to mail, calendar, contacts, and events."
|
| 207 |
+
},
|
| 208 |
+
"π OneNote": {
|
| 209 |
+
"ai_capabilities": "Content suggestion, note organization, and OCR for extracting text from images.",
|
| 210 |
+
"graph_api": "Manage notebooks, sections, and pages."
|
| 211 |
+
},
|
| 212 |
+
"π Excel": {
|
| 213 |
+
"ai_capabilities": "Copilot for advanced data analysis, data insights, and formula generation.",
|
| 214 |
+
"graph_api": "Create and manage worksheets, tables, charts, and workbooks."
|
| 215 |
+
},
|
| 216 |
+
"π Word": {
|
| 217 |
+
"ai_capabilities": "Copilot for document drafting, summarization, and grammar improvements.",
|
| 218 |
+
"graph_api": "Document content access, templates, and file management."
|
| 219 |
+
},
|
| 220 |
+
"ποΈ SharePoint": {
|
| 221 |
+
"ai_capabilities": "Intelligent search, document tagging, and metadata extraction.",
|
| 222 |
+
"graph_api": "Access to sites, lists, files, and document libraries."
|
| 223 |
+
},
|
| 224 |
+
"π
Teams": {
|
| 225 |
+
"ai_capabilities": "Copilot for meeting summaries, transcription, and chat suggestions.",
|
| 226 |
+
"graph_api": "Manage chats, teams, channels, and meetings."
|
| 227 |
+
},
|
| 228 |
+
"π¬ Viva": {
|
| 229 |
+
"ai_capabilities": "Personalized learning insights, well-being insights, and productivity suggestions.",
|
| 230 |
+
"graph_api": "Access to user analytics and learning modules."
|
| 231 |
+
},
|
| 232 |
+
"π Power Platform": {
|
| 233 |
+
"ai_capabilities": "Automation with AI Builder, data insights, and custom AI models.",
|
| 234 |
+
"graph_api": "Automation workflows, app creation, and data visualization."
|
| 235 |
+
},
|
| 236 |
+
"π§ Copilot": {
|
| 237 |
+
"ai_capabilities": "Embedded across Word, Excel, Outlook, Teams, and more for AI-driven productivity.",
|
| 238 |
+
"graph_api": "Underpins Copilot's access to data and integrations."
|
| 239 |
+
},
|
| 240 |
+
"ποΈ OneDrive": {
|
| 241 |
+
"ai_capabilities": "Intelligent file organization and search.",
|
| 242 |
+
"graph_api": "File and folder access, sharing, and metadata."
|
| 243 |
+
},
|
| 244 |
+
"π‘ PowerPoint": {
|
| 245 |
+
"ai_capabilities": "Design suggestions, presentation summarization, and speaker coaching.",
|
| 246 |
+
"graph_api": "Presentation creation, slide management, and templates."
|
| 247 |
+
},
|
| 248 |
+
"π Microsoft Bookings": {
|
| 249 |
+
"ai_capabilities": "Automated scheduling and reminders.",
|
| 250 |
+
"graph_api": "Booking calendars, services, and appointment details."
|
| 251 |
+
},
|
| 252 |
+
"π Loop": {
|
| 253 |
+
"ai_capabilities": "Real-time collaboration and content suggestions.",
|
| 254 |
+
"graph_api": "Access to shared workspaces and collaborative pages."
|
| 255 |
+
},
|
| 256 |
+
"π£οΈ Translator": {
|
| 257 |
+
"ai_capabilities": "Real-time language translation and text-to-speech.",
|
| 258 |
+
"graph_api": "Integrated into communication and translation services."
|
| 259 |
+
},
|
| 260 |
+
"π To Do & Planner": {
|
| 261 |
+
"ai_capabilities": "Task prioritization and smart reminders.",
|
| 262 |
+
"graph_api": "Task creation, management, and synchronization."
|
| 263 |
+
},
|
| 264 |
+
"π Azure OpenAI Service": {
|
| 265 |
+
"ai_capabilities": "Access to GPT models for custom AI implementations.",
|
| 266 |
+
"graph_api": "Used indirectly for building custom AI models into workflows."
|
|
|
|
|
|
|
| 267 |
}
|
| 268 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
|
| 270 |
+
# π³οΈ Create toggles for each product
|
| 271 |
+
selected_products = {}
|
| 272 |
+
for product, info in products.items():
|
| 273 |
+
selected = st.sidebar.checkbox(product)
|
| 274 |
+
if selected:
|
| 275 |
+
st.sidebar.write(f"**AI Capabilities:** {info['ai_capabilities']}")
|
| 276 |
+
st.sidebar.write(f"**Graph API:** {info['graph_api']}")
|
| 277 |
+
selected_products[product] = True
|
| 278 |
+
|
| 279 |
+
# π Authentication
|
| 280 |
+
if 'access_token' not in st.session_state:
|
| 281 |
+
# π΅οΈββοΈ Check for authorization code in query parameters
|
| 282 |
+
query_params = st.query_params
|
| 283 |
+
query = (query_params.get('code'))
|
| 284 |
+
#if len(query) > 1:
|
| 285 |
+
|
| 286 |
+
#st.write('Parsing query ' + query_params )
|
| 287 |
+
if 'code' in query_params:
|
| 288 |
+
#code = query_params['code'][0]
|
| 289 |
+
code = query_params.get('code')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
|
| 291 |
+
st.write('πAccess Code Obtained from MS Graph Redirectπ!:' + code)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
|
| 293 |
+
st.write('π Acquiring access token from redirect URL for code parameter.')
|
| 294 |
+
access_token = get_access_token(code)
|
|
|
|
|
|
|
| 295 |
|
| 296 |
+
st.session_state['access_token'] = access_token # π Save it for later
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
|
| 298 |
+
st.rerun() # Reload the app to clear the code from URL
|
| 299 |
+
else:
|
| 300 |
+
# π’ Prompt user to log in
|
| 301 |
+
client_instance = get_msal_app()
|
| 302 |
+
authorization_url = client_instance.get_authorization_request_url(
|
| 303 |
+
scopes=SCOPES,
|
| 304 |
+
redirect_uri=REDIRECT_URI
|
| 305 |
+
)
|
| 306 |
+
st.write('π Please [click here]({}) to log in and authorize the app.'.format(authorization_url))
|
| 307 |
+
st.stop()
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
else:
|
| 311 |
+
# π₯³ User is authenticated, proceed with the app
|
| 312 |
+
access_token = st.session_state['access_token']
|
| 313 |
+
headers = {'Authorization': 'Bearer ' + access_token}
|
| 314 |
+
|
| 315 |
+
# π€ Greet the user
|
| 316 |
+
response = requests.get('https://graph.microsoft.com/v1.0/me', headers=headers)
|
| 317 |
+
if response.status_code == 200:
|
| 318 |
+
user_info = response.json()
|
| 319 |
+
st.sidebar.write(f"π Hello, {user_info['displayName']}!")
|
| 320 |
+
else:
|
| 321 |
+
st.error('Failed to fetch user info.')
|
| 322 |
+
st.write(response.text)
|
| 323 |
+
|
| 324 |
+
# ποΈ Handle menu options
|
| 325 |
+
if menu == "1οΈβ£ Dashboard with Widgets":
|
| 326 |
+
st.header("1οΈβ£ Dashboard with Widgets")
|
| 327 |
+
st.write("Widgets will be displayed here. ποΈ")
|
| 328 |
+
# Add your widgets here
|
| 329 |
+
|
| 330 |
+
elif menu == "π Landing Page":
|
| 331 |
+
st.header("π Landing Page")
|
| 332 |
+
st.write("Welcome to the app! π₯³")
|
| 333 |
+
# Add landing page content here
|
| 334 |
+
|
| 335 |
+
elif menu == "π
Upcoming Events":
|
| 336 |
+
st.header("π
Upcoming Events")
|
| 337 |
+
events = get_upcoming_events(access_token)
|
| 338 |
+
for event in events:
|
| 339 |
+
st.write(f"π {event['subject']} on {event['start']['dateTime']}")
|
| 340 |
+
# Display upcoming events
|
| 341 |
+
|
| 342 |
+
elif menu == "π Schedule":
|
| 343 |
+
st.header("π Schedule")
|
| 344 |
+
schedule = get_schedule(access_token)
|
| 345 |
+
st.write(schedule)
|
| 346 |
+
# Display schedule
|
| 347 |
+
|
| 348 |
+
elif menu == "π Agenda":
|
| 349 |
+
st.header("π Agenda")
|
| 350 |
+
st.write("Your agenda for today. π")
|
| 351 |
+
# Display agenda
|
| 352 |
+
|
| 353 |
+
elif menu == "π Event Details":
|
| 354 |
+
st.header("π Event Details")
|
| 355 |
+
event_id = st.text_input("Enter Event ID")
|
| 356 |
+
if event_id:
|
| 357 |
+
event_details = get_event_details(access_token, event_id)
|
| 358 |
+
st.write(event_details)
|
| 359 |
+
# Display event details based on ID
|
| 360 |
+
|
| 361 |
+
elif menu == "β Add Event":
|
| 362 |
+
st.header("β Add Event")
|
| 363 |
+
event_subject = st.text_input("Event Subject")
|
| 364 |
+
event_start = st.date_input("Event Start Date")
|
| 365 |
+
event_start_time = st.time_input("Event Start Time")
|
| 366 |
+
event_end = st.date_input("Event End Date")
|
| 367 |
+
event_end_time = st.time_input("Event End Time")
|
| 368 |
+
if st.button("Add Event"):
|
| 369 |
+
event_details = {
|
| 370 |
+
"subject": event_subject,
|
| 371 |
+
"start": {
|
| 372 |
+
"dateTime": f"{event_start}T{event_start_time}",
|
| 373 |
+
"timeZone": "UTC"
|
| 374 |
+
},
|
| 375 |
+
"end": {
|
| 376 |
+
"dateTime": f"{event_end}T{event_end_time}",
|
| 377 |
+
"timeZone": "UTC"
|
| 378 |
}
|
| 379 |
+
}
|
| 380 |
+
add_event(access_token, event_details)
|
| 381 |
+
st.success("Event added successfully! π")
|
| 382 |
+
# Form to add new event
|
| 383 |
+
|
| 384 |
+
elif menu == "π Filter By":
|
| 385 |
+
st.header("π Filter Events")
|
| 386 |
+
filter_criteria = st.text_input("Enter filter criteria")
|
| 387 |
+
if filter_criteria:
|
| 388 |
+
filtered_events = filter_events(access_token, filter_criteria)
|
| 389 |
+
for event in filtered_events:
|
| 390 |
+
st.write(f"π
{event['subject']} on {event['start']['dateTime']}")
|
| 391 |
+
# Filter events based on criteria
|
| 392 |
+
|
| 393 |
+
# π§© Handle selected products
|
| 394 |
+
if selected_products:
|
| 395 |
+
st.header("π§© M365 Product Integrations")
|
| 396 |
+
for product in selected_products:
|
| 397 |
+
st.subheader(f"{product}")
|
| 398 |
+
# Call the function corresponding to the product
|
| 399 |
+
handle_product_integration(access_token, product)
|
| 400 |
+
else:
|
| 401 |
+
st.write("No products selected.")
|
| 402 |
+
pass
|
| 403 |
|
| 404 |
# π§© Function to handle product integration
|
| 405 |
def handle_product_integration(access_token, product):
|