DevNumb commited on
Commit
c50f44a
·
verified ·
1 Parent(s): 4ec9fa4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -651
app.py CHANGED
@@ -1,655 +1,17 @@
1
- import gradio as gr
2
- import requests
3
- import os
4
- import base64
5
- from PIL import Image
6
- import io
7
- import datetime
8
 
9
- # Configuration from environment variables
10
- OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
11
- DEFAULT_REPORT_EMAIL = os.getenv("REPORT_EMAIL")
12
- BREVO_API_KEY = os.getenv("BREVO_API_KEY")
13
- BREVO_FROM_EMAIL = os.getenv("BREVO_FROM_EMAIL", "noreply@yourdomain.com")
14
 
15
- # Store conversation history and settings
16
- conversation_history = []
17
- current_report_email = DEFAULT_REPORT_EMAIL
 
18
 
19
- # Department configurations
20
- departments = {
21
- "administration": {
22
- "name": "Administration",
23
- "email": os.getenv("ADMIN_EMAIL", ""),
24
- "responsibilities": "Overall management, decision making, and coordination"
25
- },
26
- "production": {
27
- "name": "Production",
28
- "email": os.getenv("PRODUCTION_EMAIL", ""),
29
- "responsibilities": "Manufacturing, quality control, and production planning"
30
- },
31
- "magazine": {
32
- "name": "Magazine Management",
33
- "email": os.getenv("MAGAZINE_EMAIL", ""),
34
- "responsibilities": "Content creation, publishing, and distribution"
35
- }
36
- }
37
 
38
- def update_report_email(new_email):
39
- """Update the report email address"""
40
- global current_report_email
41
- if new_email and "@" in new_email and "." in new_email:
42
- current_report_email = new_email.strip()
43
- return f"✅ Report email updated to: {current_report_email}"
44
- else:
45
- return "❌ Please enter a valid email address"
46
-
47
- def send_email_brevo_api(to_email, subject, html_content, from_name="AI Coordination System"):
48
- """Send email using Brevo API"""
49
- try:
50
- if not BREVO_API_KEY:
51
- return "❌ Email not configured - missing Brevo API key"
52
-
53
- response = requests.post(
54
- "https://api.brevo.com/v3/smtp/email",
55
- headers={
56
- "accept": "application/json",
57
- "content-type": "application/json",
58
- "api-key": BREVO_API_KEY
59
- },
60
- json={
61
- "sender": {
62
- "name": from_name,
63
- "email": BREVO_FROM_EMAIL
64
- },
65
- "to": [{"email": to_email}],
66
- "subject": subject,
67
- "htmlContent": html_content
68
- },
69
- timeout=10
70
- )
71
-
72
- if response.status_code == 201:
73
- return f"✅ Email sent to {to_email}"
74
- else:
75
- error_msg = response.json().get('message', 'Unknown error')
76
- return f"❌ Failed to send email: {error_msg}"
77
-
78
- except Exception as e:
79
- return f"❌ Email error: {str(e)}"
80
-
81
- def analyze_coordination_needs(user_message, department, user_name, image=None):
82
- """Use LLM to analyze coordination needs and suggest actions - with image support"""
83
-
84
- if image:
85
- # Convert image to base64 for vision model
86
- buffered = io.BytesIO()
87
- image.save(buffered, format="PNG")
88
- img_base64 = base64.b64encode(buffered.getvalue()).decode()
89
-
90
- prompt = f"""As a helpful coordination assistant, analyze this request from {user_name} in the {department} department along with the attached image.
91
-
92
- Please provide clear, practical advice in plain English that's easy for anyone to understand.
93
-
94
- REQUEST DETAILS:
95
- - Department: {department}
96
- - Requestor: {user_name}
97
- - Message: {user_message}
98
-
99
- Please analyze both the text and image to provide helpful guidance about:
100
-
101
- 1. Which teams need to be involved
102
- 2. What specific steps should be taken next
103
- 3. Any important information from the image
104
- 4. What priority this request should have
105
- 5. What follow-up might be needed
106
-
107
- Please format your response in a friendly, conversational way that's easy to read and act upon."""
108
-
109
- try:
110
- response = requests.post(
111
- "https://openrouter.ai/api/v1/chat/completions",
112
- headers={
113
- "Authorization": f"Bearer {OPENROUTER_API_KEY}",
114
- "Content-Type": "application/json",
115
- },
116
- json={
117
- "model": "google/gemma-3-27b-it:free", # Vision model
118
- "messages": [
119
- {
120
- "role": "user",
121
- "content": [
122
- {
123
- "type": "text",
124
- "text": prompt
125
- },
126
- {
127
- "type": "image_url",
128
- "image_url": {
129
- "url": f"data:image/png;base64,{img_base64}"
130
- }
131
- }
132
- ]
133
- }
134
- ],
135
- "temperature": 0.3
136
- },
137
- timeout=60
138
- )
139
-
140
- if response.status_code == 200:
141
- data = response.json()
142
- return data["choices"][0]["message"]["content"]
143
- else:
144
- return "I'm having trouble analyzing the image right now. Please try again in a moment."
145
-
146
- except Exception as e:
147
- return f"Sorry, I couldn't process the image. Error: {str(e)}"
148
-
149
- else:
150
- # Text-only analysis
151
- prompt = f"""As a helpful coordination assistant, analyze this request from {user_name} in the {department} department.
152
-
153
- Please provide clear, practical advice in plain English that's easy for anyone to understand.
154
-
155
- REQUEST DETAILS:
156
- - Department: {department}
157
- - Requestor: {user_name}
158
- - Message: {user_message}
159
-
160
- Please provide helpful guidance about:
161
- - Which teams need to be involved
162
- - What specific steps should be taken next
163
- - What priority this request should have
164
- - What follow-up might be needed
165
-
166
- Please format your response in a friendly, conversational way that's easy to read and act upon. Avoid technical jargon and use bullet points or simple sections to organize your thoughts."""
167
-
168
- try:
169
- response = requests.post(
170
- "https://openrouter.ai/api/v1/chat/completions",
171
- headers={
172
- "Authorization": f"Bearer {OPENROUTER_API_KEY}",
173
- "Content-Type": "application/json",
174
- },
175
- json={
176
- "model": "google/gemma-3-27b-it:free",
177
- "messages": [{"role": "user", "content": prompt}],
178
- "temperature": 0.3
179
- },
180
- timeout=30
181
- )
182
-
183
- if response.status_code == 200:
184
- data = response.json()
185
- return data["choices"][0]["message"]["content"]
186
- else:
187
- return "I'm having trouble analyzing your request right now. Please try again in a moment."
188
-
189
- except Exception as e:
190
- return f"Sorry, I couldn't process your request. Error: {str(e)}"
191
-
192
- def send_department_email(sender_dept, recipient_dept, subject, message, user_name, urgency="Normal", image=None):
193
- """Send email between departments with optional image attachment"""
194
- try:
195
- # Determine recipient email
196
- recipient_email = departments[recipient_dept]["email"]
197
- if not recipient_email:
198
- # If no department email configured, use the current report email
199
- recipient_email = current_report_email
200
-
201
- # Create professional email content
202
- image_note = "<p style='margin: 5px 0;'><strong>📎 Attachment:</strong> Image included with request</p>" if image else ""
203
- urgency_class = f"urgency-{urgency.lower()}" if urgency.lower() in ['high', 'medium'] else "urgency-normal"
204
- image_footer = "<p><em>Note: An image was included with this request. Please check the original system for image details.</em></p>" if image else ""
205
-
206
- html_content = f"""<html>
207
- <head>
208
- <style>
209
- body {{ font-family: Arial, sans-serif; margin: 20px; }}
210
- .header {{ background-color: #f4f4f4; padding: 20px; border-radius: 8px; margin-bottom: 20px; }}
211
- .urgency-high {{ border-left: 5px solid #dc2626; background-color: #fef2f2; }}
212
- .urgency-medium {{ border-left: 5px solid #d97706; background-color: #fffbeb; }}
213
- .urgency-normal {{ border-left: 5px solid #2563eb; background-color: #eff6ff; }}
214
- .message-content {{ padding: 20px; background-color: white; border-radius: 8px; margin: 15px 0; }}
215
- .user-info {{ background-color: #f8fafc; padding: 10px 15px; border-radius: 6px; margin: 10px 0; }}
216
- </style>
217
- </head>
218
- <body>
219
- <div class="header">
220
- <h1 style="margin: 0; color: #1f2937;">🏢 Inter-Department Communication</h1>
221
- <p style="margin: 5px 0;"><strong>From:</strong> {departments[sender_dept]['name']}</p>
222
- <p style="margin: 5px 0;"><strong>Requested by:</strong> {user_name}</p>
223
- <p style="margin: 5px 0;"><strong>To:</strong> {departments[recipient_dept]['name']}</p>
224
- <p style="margin: 5px 0;"><strong>Date:</strong> {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</p>
225
- <p style="margin: 5px 0;"><strong>Urgency:</strong> {urgency}</p>
226
- {image_note}
227
- </div>
228
-
229
- <div class="user-info">
230
- <strong>👤 Requestor Details:</strong><br>
231
- Name: {user_name}<br>
232
- Department: {departments[sender_dept]['name']}
233
- </div>
234
-
235
- <div class="message-content {urgency_class}">
236
- <h3 style="margin-top: 0;">{subject}</h3>
237
- <div style="white-space: pre-line;">{message}</div>
238
- </div>
239
-
240
- <div style="color: #6b7280; font-size: 0.9em; margin-top: 20px;">
241
- <p>This is an automated message from the AI Coordination System.</p>
242
- {image_footer}
243
- </div>
244
- </body>
245
- </html>"""
246
-
247
- # Send email using Brevo API
248
- from_name = f"{departments[sender_dept]['name']}"
249
- email_status = send_email_brevo_api(recipient_email, f"[{urgency}] {subject}", html_content, from_name)
250
- return email_status
251
-
252
- except Exception as e:
253
- return f"❌ Failed to send email: {str(e)}"
254
-
255
- def send_email_report(conversation_data):
256
- """Send comprehensive coordination report to administration"""
257
- if not BREVO_API_KEY or not current_report_email:
258
- return "Email reporting not configured - missing Brevo API key or report email"
259
-
260
- try:
261
- # Calculate department activity
262
- dept_activity = {}
263
- user_activity = {}
264
- for entry in conversation_data:
265
- dept = entry.get('department', 'Unknown')
266
- user = entry.get('user_name', 'Unknown')
267
- dept_activity[dept] = dept_activity.get(dept, 0) + 1
268
- user_activity[user] = user_activity.get(user, 0) + 1
269
-
270
- # Format email content
271
- subject = f"Coordination Report - {datetime.datetime.now().strftime('%Y-%m-%d %H:%M')}"
272
-
273
- # Create department activity HTML
274
- dept_activity_html = ""
275
- for dept, count in dept_activity.items():
276
- dept_activity_html += f"<p><strong>{dept.title()}:</strong> {count} interactions</p>"
277
-
278
- # Create user activity HTML
279
- user_activity_html = ""
280
- for user, count in user_activity.items():
281
- if user != 'Unknown':
282
- user_activity_html += f"<p><strong>{user}:</strong> {count} requests</p>"
283
-
284
- # Create recent activities HTML
285
- recent_activities_html = ""
286
- for i, entry in enumerate(conversation_data[-10:], 1):
287
- dept_badge = f"<span class='department-badge'>{entry.get('department', 'General').title()}</span>" if entry.get('department') else ""
288
- user_badge = f"<span class='user-badge'>{entry.get('user_name', 'User')}</span>" if entry.get('user_name') else ""
289
- image_indicator = " <span class='image-indicator'>📷</span>" if entry.get('image_uploaded') else ""
290
- email_indicator = " 📧" if entry.get('email_sent') else ""
291
-
292
- recent_activities_html += f"""<div class="exchange">
293
- <div style="display: flex; justify-content: between; align-items: center; margin-bottom: 10px;">
294
- <h4 style="margin: 0; color: #374151;">Activity #{i}</h4>
295
- <div>
296
- {dept_badge}
297
- {user_badge}
298
- {image_indicator}
299
- </div>
300
- </div>
301
- <p class="user"><strong>💬 Message:</strong> {entry['user_input']}{email_indicator}</p>
302
- <p class="ai"><strong>🤖 AI Coordination:</strong> {entry['ai_response']}</p>
303
- <p class="timestamp">{entry['timestamp']}</p>
304
- </div>"""
305
-
306
- # Create comprehensive HTML report
307
- html_content = f"""<html>
308
- <head>
309
- <style>
310
- body {{ font-family: Arial, sans-serif; margin: 20px; }}
311
- .header {{ background-color: #1f2937; color: white; padding: 25px; border-radius: 8px; margin-bottom: 20px; }}
312
- .stats {{ display: flex; justify-content: space-between; margin: 20px 0; }}
313
- .stat-card {{ background-color: #f8fafc; padding: 15px; border-radius: 8px; text-align: center; flex: 1; margin: 0 10px; }}
314
- .exchange {{ border: 1px solid #e0e0e0; margin: 15px 0; padding: 15px; border-radius: 8px; background-color: #fafafa; }}
315
- .user {{ color: #2563eb; font-weight: 600; }}
316
- .ai {{ color: #059669; }}
317
- .timestamp {{ color: #6b7280; font-size: 0.8em; font-style: italic; }}
318
- .department-badge {{ background-color: #3b82f6; color: white; padding: 2px 8px; border-radius: 12px; font-size: 0.8em; }}
319
- .user-badge {{ background-color: #10b981; color: white; padding: 2px 8px; border-radius: 12px; font-size: 0.8em; margin-left: 5px; }}
320
- .image-indicator {{ background-color: #f59e0b; color: white; padding: 2px 6px; border-radius: 10px; font-size: 0.7em; margin-left: 5px; }}
321
- </style>
322
- </head>
323
- <body>
324
- <div class="header">
325
- <h1 style="margin: 0;">🤖 AI Coordination System Report</h1>
326
- <p style="margin: 5px 0; opacity: 0.9;">Comprehensive inter-department coordination summary</p>
327
- <p style="margin: 5px 0;"><strong>Generated:</strong> {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</p>
328
- </div>
329
-
330
- <div class="stats">
331
- <div class="stat-card">
332
- <h3 style="margin: 0; color: #3b82f6;">{len(conversation_data)}</h3>
333
- <p style="margin: 5px 0;">Total Interactions</p>
334
- </div>
335
- <div class="stat-card">
336
- <h3 style="margin: 0; color: #10b981;">{len(dept_activity)}</h3>
337
- <p style="margin: 5px 0;">Active Departments</p>
338
- </div>
339
- <div class="stat-card">
340
- <h3 style="margin: 0; color: #f59e0b;">{sum(1 for entry in conversation_history if entry.get('email_sent'))}</h3>
341
- <p style="margin: 5px 0;">Emails Sent</p>
342
- </div>
343
- </div>
344
-
345
- <h3>📊 Department Activity</h3>
346
- {dept_activity_html}
347
-
348
- <h3>👥 User Activity</h3>
349
- {user_activity_html if user_activity_html else "<p>No user activity data</p>"}
350
-
351
- <h3>🔄 Recent Coordination Activities</h3>
352
- {recent_activities_html if recent_activities_html else "<p>No recent activities</p>"}
353
-
354
- <div style="margin-top: 30px; padding: 15px; background-color: #f0fdf4; border-radius: 8px;">
355
- <p style="margin: 0;"><strong>🤖 AI Note:</strong> This report is automatically generated by the coordination system. All inter-department communications are logged and monitored for efficiency.</p>
356
- </div>
357
- </body>
358
- </html>"""
359
-
360
- # Send email using Brevo API
361
- email_status = send_email_brevo_api(current_report_email, subject, html_content, "AI Coordination System")
362
- return email_status
363
-
364
- except Exception as e:
365
- return f"Failed to send report: {str(e)}"
366
-
367
- def add_to_conversation_history(user_input, department, user_name, ai_response, email_sent=False, image_uploaded=False):
368
- """Add current exchange to conversation history"""
369
- entry = {
370
- 'timestamp': datetime.datetime.now().isoformat(),
371
- 'user_input': user_input,
372
- 'department': department,
373
- 'user_name': user_name,
374
- 'ai_response': ai_response,
375
- 'email_sent': email_sent,
376
- 'image_uploaded': image_uploaded
377
- }
378
- conversation_history.append(entry)
379
-
380
- # Keep only last 50 exchanges to prevent memory issues
381
- if len(conversation_history) > 50:
382
- conversation_history.pop(0)
383
-
384
- def process_coordination_request(name, department, message, image, recipient_dept, send_email, urgency):
385
- """Process coordination requests between departments with image support"""
386
- if not message.strip():
387
- return "Please enter a coordination message."
388
-
389
- if not department:
390
- return "Please select your department."
391
-
392
- if not name.strip():
393
- return "Please enter your name."
394
-
395
- # Get AI analysis and suggestions (with image if provided)
396
- ai_analysis = analyze_coordination_needs(message, department, name, image)
397
-
398
- # Prepare response
399
- response_parts = []
400
- response_parts.append(f"**👤 Request from:** {name} | **🏢 Department:** {departments[department]['name']}")
401
-
402
- if image:
403
- response_parts.append("**📷 Image attached and analyzed**")
404
-
405
- response_parts.append(f"\n**🤖 Coordination Guidance:**\n{ai_analysis}")
406
-
407
- # Send email if requested
408
- email_status = ""
409
- if send_email and recipient_dept:
410
- subject = f"Coordination Request from {departments[department]['name']} - {name}"
411
-
412
- # Build email message
413
- email_lines = [
414
- f"Requestor: {name}",
415
- f"Department: {departments[department]['name']}",
416
- "",
417
- "Message:",
418
- message,
419
- ""
420
- ]
421
-
422
- if image:
423
- email_lines.append("Note: An image was included with this request. Please check the system for visual details.")
424
- email_lines.append("")
425
-
426
- email_lines.extend([
427
- "---",
428
- "Coordination Suggestions:",
429
- ai_analysis
430
- ])
431
-
432
- email_message = "\n".join(email_lines)
433
- email_status = send_department_email(department, recipient_dept, subject, email_message, name, urgency, image)
434
- response_parts.append(f"\n**📧 Email Status:** {email_status}")
435
-
436
- full_response = "\n".join(response_parts)
437
-
438
- # Add to conversation history
439
- add_to_conversation_history(
440
- user_input=message,
441
- department=department,
442
- user_name=name,
443
- ai_response=full_response,
444
- email_sent=bool(send_email and recipient_dept),
445
- image_uploaded=image is not None
446
- )
447
-
448
- return full_response
449
-
450
- def get_conversation_stats():
451
- """Get statistics about current coordination activities"""
452
- if not conversation_history:
453
- return "No coordination activities yet"
454
-
455
- total_exchanges = len(conversation_history)
456
- dept_activity = {}
457
- user_activity = {}
458
- emails_sent = sum(1 for entry in conversation_history if entry.get('email_sent'))
459
- images_uploaded = sum(1 for entry in conversation_history if entry.get('image_uploaded'))
460
-
461
- for entry in conversation_history:
462
- dept = entry.get('department', 'Unknown')
463
- user = entry.get('user_name', 'Unknown')
464
- dept_activity[dept] = dept_activity.get(dept, 0) + 1
465
- if user != 'Unknown':
466
- user_activity[user] = user_activity.get(user, 0) + 1
467
-
468
- stats_text = f"📊 **Coordination Summary:**\n"
469
- stats_text += f"• Total Activities: {total_exchanges}\n"
470
- stats_text += f"• Emails Sent: {emails_sent}\n"
471
- stats_text += f"• Images Shared: {images_uploaded}\n\n"
472
-
473
- stats_text += "**Department Activity:**\n"
474
- for dept, count in dept_activity.items():
475
- stats_text += f"• {dept.title()}: {count} requests\n"
476
-
477
- if user_activity:
478
- stats_text += f"\n**Active Team Members:** {', '.join(user_activity.keys())}"
479
-
480
- return stats_text
481
-
482
- def clear_conversation():
483
- """Clear the conversation history"""
484
- global conversation_history
485
- conversation_history = []
486
- return "🗑️ Coordination history cleared!"
487
-
488
- def get_current_email():
489
- """Get the current report email address"""
490
- return current_report_email if current_report_email else "Not set"
491
-
492
- def clear_form():
493
- """Clear the form fields"""
494
- return ["", None, "", None, "administration", "Normal", False]
495
-
496
- # Gradio Interface
497
- # Add this at the top of your Gradio Blocks
498
- with gr.Blocks(
499
- theme=gr.themes.Soft(),
500
- title="AI Coordination System"
501
- ) as ui:
502
- gr.Markdown("# 🏢 AI Department Coordination System")
503
- gr.Markdown("*Streamline communication between Administration, Production, and Magazine Management*")
504
-
505
- with gr.Row():
506
- with gr.Column(scale=1):
507
- gr.Markdown("### ⚙️ System Settings")
508
- email_input = gr.Textbox(
509
- label="Administration Report Email",
510
- value=get_current_email,
511
- placeholder="admin@company.com"
512
- )
513
- email_status = gr.Textbox(
514
- label="Email Status",
515
- value=get_current_email,
516
- interactive=False,
517
- max_lines=2
518
- )
519
- update_email_btn = gr.Button("💾 Save Email", variant="primary")
520
-
521
- gr.Markdown("---")
522
- gr.Markdown("### 📝 New Coordination Request")
523
-
524
- with gr.Group():
525
- gr.Markdown("#### 👤 Your Information")
526
- name_input = gr.Textbox(
527
- label="Your Name",
528
- placeholder="Enter your full name"
529
- )
530
-
531
- department_dropdown = gr.Dropdown(
532
- choices=["administration", "production", "magazine"],
533
- label="Your Department"
534
- )
535
-
536
- with gr.Group():
537
- gr.Markdown("#### 💬 Request Details")
538
- message_input = gr.Textbox(
539
- label="What do you need help with?",
540
- lines=4,
541
- placeholder="Describe what you need from other departments..."
542
- )
543
-
544
- image_input = gr.Image(
545
- label="📷 Attach Image (Optional)",
546
- type="pil"
547
- )
548
-
549
- with gr.Group():
550
- gr.Markdown("#### 📧 Notification Options")
551
- recipient_dropdown = gr.Dropdown(
552
- choices=["administration", "production", "magazine"],
553
- label="Notify Department"
554
- )
555
-
556
- urgency_dropdown = gr.Dropdown(
557
- choices=["Normal", "Medium", "High"],
558
- value="Normal",
559
- label="Priority Level"
560
- )
561
-
562
- send_email_checkbox = gr.Checkbox(
563
- label="Send email notification",
564
- value=True
565
- )
566
-
567
- with gr.Row():
568
- submit_btn = gr.Button("🚀 Get Coordination Help", variant="primary")
569
- clear_form_btn = gr.Button("🗑️ Clear Form", variant="secondary")
570
-
571
- with gr.Row():
572
- report_btn = gr.Button("📋 Submit & Send Report", variant="secondary")
573
- clear_btn = gr.Button("🗂️ Clear History", variant="stop")
574
- stats_btn = gr.Button("📈 View Stats")
575
-
576
- status_display = gr.Textbox(
577
- label="System Status",
578
- interactive=False,
579
- max_lines=2
580
- )
581
-
582
- stats_display = gr.Textbox(
583
- label="Activity Summary",
584
- interactive=False,
585
- max_lines=6
586
- )
587
-
588
- with gr.Column(scale=2):
589
- gr.Markdown("### 💡 Coordination Guidance")
590
- output = gr.Textbox(
591
- label="Recommended Actions",
592
- lines=18,
593
- show_copy_button=True
594
- )
595
-
596
- with gr.Accordion("🏢 Department Overview", open=True):
597
- gr.Markdown("**Administration**: Overall management, decision making, and coordination \n**Production**: Manufacturing, quality control, and production planning \n**Magazine Management**: Content creation, publishing, and distribution \n \n*The AI will analyze your message and any attached images to provide specific coordination recommendations.*")
598
-
599
- with gr.Accordion("📜 Recent Activity", open=False):
600
- history_display = gr.JSON(
601
- label="Activity Log",
602
- value=conversation_history[-10:] if conversation_history else []
603
- )
604
-
605
- # Event handlers
606
- update_email_btn.click(
607
- fn=update_report_email,
608
- inputs=[email_input],
609
- outputs=email_status
610
- )
611
-
612
- email_input.submit(
613
- fn=update_report_email,
614
- inputs=[email_input],
615
- outputs=email_status
616
- )
617
-
618
- submit_btn.click(
619
- fn=process_coordination_request,
620
- inputs=[name_input, department_dropdown, message_input, image_input, recipient_dropdown, send_email_checkbox, urgency_dropdown],
621
- outputs=output
622
- )
623
-
624
- report_btn.click(
625
- fn=lambda name, dept, msg, img, rec, send, urg: process_coordination_request(name, dept, msg, img, rec, send, urg) + "\n\n---\n" + send_email_report(conversation_history),
626
- inputs=[name_input, department_dropdown, message_input, image_input, recipient_dropdown, send_email_checkbox, urgency_dropdown],
627
- outputs=output
628
- )
629
-
630
- message_input.submit(
631
- fn=process_coordination_request,
632
- inputs=[name_input, department_dropdown, message_input, image_input, recipient_dropdown, send_email_checkbox, urgency_dropdown],
633
- outputs=output
634
- )
635
-
636
- clear_btn.click(
637
- fn=clear_conversation,
638
- inputs=[],
639
- outputs=status_display
640
- )
641
-
642
- clear_form_btn.click(
643
- fn=clear_form,
644
- inputs=[],
645
- outputs=[name_input, image_input, message_input, recipient_dropdown, department_dropdown, urgency_dropdown, send_email_checkbox]
646
- )
647
-
648
- stats_btn.click(
649
- fn=get_conversation_stats,
650
- inputs=[],
651
- outputs=stats_display
652
- )
653
-
654
- if __name__ == "__main__":
655
- ui.launch(share=True )
 
1
+ === COORDINATION SUMMARY ===
2
+ Production line downtime reported requiring immediate technical intervention.
 
 
 
 
 
3
 
4
+ === DEPARTMENTS INVOLVED ===
5
+ Production – technical inspection
6
+ Administration – approval of maintenance budget
 
 
7
 
8
+ === RECOMMENDED ACTION PLAN ===
9
+ 1. Inspect equipment
10
+ 2. Log maintenance ticket
11
+ 3. Schedule repair within 24 hours
12
 
13
+ === PRIORITY LEVEL ===
14
+ High Direct operational impact
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
+ === FOLLOW-UP ===
17
+ Daily status update until resolution