DevNumb commited on
Commit
0f42db7
Β·
verified Β·
1 Parent(s): 4775479

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -66
app.py CHANGED
@@ -87,28 +87,25 @@ def analyze_coordination_needs(user_message, department, user_name, image=None):
87
  image.save(buffered, format="PNG")
88
  img_base64 = base64.b64encode(buffered.getvalue()).decode()
89
 
90
- prompt = f"""As an AI coordination agent, analyze this message from {user_name} in the {department} department.
91
- Also analyze the attached image and provide comprehensive coordination suggestions.
92
 
93
- DEPARTMENT: {department}
94
- REQUESTOR: {user_name}
95
- MESSAGE: {user_message}
96
 
97
- Analyze both the text message and the image to understand:
98
- 1. Which other departments need to be involved?
99
- 2. What specific actions should be taken based on both text and visual information?
100
- 3. What information needs to be shared between departments?
101
- 4. What are the priority levels?
102
- 5. What follow-up is needed?
103
- 6. Any insights from the image that affect coordination?
 
 
 
 
 
 
 
104
 
105
- Provide a structured response with:
106
- - Coordination needed with: [departments]
107
- - Image analysis insights: [key points from image]
108
- - Recommended actions: [bullet points]
109
- - Priority: [High/Medium/Low]
110
- - Next steps: [suggestions]"""
111
-
112
  try:
113
  response = requests.post(
114
  "https://openrouter.ai/api/v1/chat/completions",
@@ -144,32 +141,30 @@ Provide a structured response with:
144
  data = response.json()
145
  return data["choices"][0]["message"]["content"]
146
  else:
147
- return "AI analysis with image temporarily unavailable."
148
 
149
  except Exception as e:
150
- return f"Image analysis error: {str(e)}"
151
 
152
  else:
153
  # Text-only analysis
154
- prompt = f"""As an AI coordination agent, analyze this message from {user_name} in the {department} department and suggest appropriate actions:
155
 
156
- DEPARTMENT: {department}
157
- REQUESTOR: {user_name}
158
- MESSAGE: {user_message}
159
 
160
- Consider:
161
- 1. Which other departments need to be involved?
162
- 2. What specific actions should be taken?
163
- 3. What information needs to be shared?
164
- 4. What are the priority levels?
165
- 5. What follow-up is needed?
 
 
 
 
 
 
166
 
167
- Provide a structured response with:
168
- - Coordination needed with: [departments]
169
- - Recommended actions: [bullet points]
170
- - Priority: [High/Medium/Low]
171
- - Next steps: [suggestions]"""
172
-
173
  try:
174
  response = requests.post(
175
  "https://openrouter.ai/api/v1/chat/completions",
@@ -189,10 +184,10 @@ Provide a structured response with:
189
  data = response.json()
190
  return data["choices"][0]["message"]["content"]
191
  else:
192
- return "AI analysis temporarily unavailable."
193
 
194
  except Exception as e:
195
- return f"Analysis error: {str(e)}"
196
 
197
  def send_department_email(sender_dept, recipient_dept, subject, message, user_name, urgency="Normal", image=None):
198
  """Send email between departments with optional image attachment"""
@@ -407,7 +402,7 @@ def process_coordination_request(name, department, message, image, recipient_dep
407
  if image:
408
  response_parts.append("**πŸ“· Image attached and analyzed**")
409
 
410
- response_parts.append(f"\n**πŸ€– AI Coordination Analysis:**\n{ai_analysis}")
411
 
412
  # Send email if requested
413
  email_status = ""
@@ -430,7 +425,7 @@ def process_coordination_request(name, department, message, image, recipient_dep
430
 
431
  email_lines.extend([
432
  "---",
433
- "AI Coordination Suggestions:",
434
  ai_analysis
435
  ])
436
 
@@ -470,11 +465,17 @@ def get_conversation_stats():
470
  if user != 'Unknown':
471
  user_activity[user] = user_activity.get(user, 0) + 1
472
 
473
- stats_text = f"Total Activities: {total_exchanges} | Emails Sent: {emails_sent} | Images: {images_uploaded}\n"
474
- stats_text += "Department Activity: " + ", ".join([f"{k}: {v}" for k, v in dept_activity.items()])
 
 
 
 
 
 
475
 
476
  if user_activity:
477
- stats_text += f"\nActive Users: {', '.join(user_activity.keys())}"
478
 
479
  return stats_text
480
 
@@ -482,7 +483,7 @@ def clear_conversation():
482
  """Clear the conversation history"""
483
  global conversation_history
484
  conversation_history = []
485
- return "Coordination history cleared!"
486
 
487
  def get_current_email():
488
  """Get the current report email address"""
@@ -495,11 +496,11 @@ def clear_form():
495
  # Gradio Interface
496
  with gr.Blocks(theme=gr.themes.Soft(), title="AI Coordination System") as ui:
497
  gr.Markdown("# 🏒 AI Department Coordination System")
498
- gr.Markdown("*Automated coordination between Administration, Production, and Magazine Management*")
499
 
500
  with gr.Row():
501
  with gr.Column(scale=1):
502
- gr.Markdown("### πŸ“§ System Configuration")
503
  email_input = gr.Textbox(
504
  label="Administration Report Email",
505
  value=get_current_email,
@@ -511,15 +512,15 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI Coordination System") as ui:
511
  interactive=False,
512
  max_lines=2
513
  )
514
- update_email_btn = gr.Button("πŸ’Ύ Update Email", variant="primary")
515
 
516
  gr.Markdown("---")
517
- gr.Markdown("### πŸ‘€ Coordination Request Form")
518
 
519
  with gr.Group():
520
- gr.Markdown("#### Personal Information")
521
  name_input = gr.Textbox(
522
- label="Your Full Name",
523
  placeholder="Enter your full name"
524
  )
525
 
@@ -529,9 +530,9 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI Coordination System") as ui:
529
  )
530
 
531
  with gr.Group():
532
- gr.Markdown("#### Request Details")
533
  message_input = gr.Textbox(
534
- label="Coordination Message",
535
  lines=4,
536
  placeholder="Describe what you need from other departments..."
537
  )
@@ -542,31 +543,31 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI Coordination System") as ui:
542
  )
543
 
544
  with gr.Group():
545
- gr.Markdown("#### Email Options")
546
  recipient_dropdown = gr.Dropdown(
547
  choices=["administration", "production", "magazine"],
548
- label="Recipient Department"
549
  )
550
 
551
  urgency_dropdown = gr.Dropdown(
552
  choices=["Normal", "Medium", "High"],
553
  value="Normal",
554
- label="Urgency Level"
555
  )
556
 
557
  send_email_checkbox = gr.Checkbox(
558
- label="πŸ“§ Send email to recipient department",
559
  value=True
560
  )
561
 
562
  with gr.Row():
563
- submit_btn = gr.Button("πŸš€ Submit Coordination Request", variant="primary")
564
  clear_form_btn = gr.Button("πŸ—‘οΈ Clear Form", variant="secondary")
565
 
566
  with gr.Row():
567
- report_btn = gr.Button("πŸ“Š Submit & Send Report", variant="secondary")
568
  clear_btn = gr.Button("πŸ—‚οΈ Clear History", variant="stop")
569
- stats_btn = gr.Button("πŸ“ˆ Get Stats")
570
 
571
  status_display = gr.Textbox(
572
  label="System Status",
@@ -575,23 +576,23 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI Coordination System") as ui:
575
  )
576
 
577
  stats_display = gr.Textbox(
578
- label="Coordination Statistics",
579
  interactive=False,
580
- max_lines=4
581
  )
582
 
583
  with gr.Column(scale=2):
584
- gr.Markdown("### πŸ€– AI Coordination Response")
585
  output = gr.Textbox(
586
- label="Coordination Analysis & Actions",
587
  lines=18,
588
  show_copy_button=True
589
  )
590
 
591
- with gr.Accordion("🏒 Department Information", open=True):
592
  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.*")
593
 
594
- with gr.Accordion("πŸ“œ Recent Coordination Activities", open=False):
595
  history_display = gr.JSON(
596
  label="Activity Log",
597
  value=conversation_history[-10:] if conversation_history else []
 
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",
 
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",
 
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"""
 
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 = ""
 
425
 
426
  email_lines.extend([
427
  "---",
428
+ "Coordination Suggestions:",
429
  ai_analysis
430
  ])
431
 
 
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
 
 
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"""
 
496
  # Gradio Interface
497
  with gr.Blocks(theme=gr.themes.Soft(), title="AI Coordination System") as ui:
498
  gr.Markdown("# 🏒 AI Department Coordination System")
499
+ gr.Markdown("*Streamline communication between Administration, Production, and Magazine Management*")
500
 
501
  with gr.Row():
502
  with gr.Column(scale=1):
503
+ gr.Markdown("### βš™οΈ System Settings")
504
  email_input = gr.Textbox(
505
  label="Administration Report Email",
506
  value=get_current_email,
 
512
  interactive=False,
513
  max_lines=2
514
  )
515
+ update_email_btn = gr.Button("πŸ’Ύ Save Email", variant="primary")
516
 
517
  gr.Markdown("---")
518
+ gr.Markdown("### πŸ“ New Coordination Request")
519
 
520
  with gr.Group():
521
+ gr.Markdown("#### πŸ‘€ Your Information")
522
  name_input = gr.Textbox(
523
+ label="Your Name",
524
  placeholder="Enter your full name"
525
  )
526
 
 
530
  )
531
 
532
  with gr.Group():
533
+ gr.Markdown("#### πŸ’¬ Request Details")
534
  message_input = gr.Textbox(
535
+ label="What do you need help with?",
536
  lines=4,
537
  placeholder="Describe what you need from other departments..."
538
  )
 
543
  )
544
 
545
  with gr.Group():
546
+ gr.Markdown("#### πŸ“§ Notification Options")
547
  recipient_dropdown = gr.Dropdown(
548
  choices=["administration", "production", "magazine"],
549
+ label="Notify Department"
550
  )
551
 
552
  urgency_dropdown = gr.Dropdown(
553
  choices=["Normal", "Medium", "High"],
554
  value="Normal",
555
+ label="Priority Level"
556
  )
557
 
558
  send_email_checkbox = gr.Checkbox(
559
+ label="Send email notification",
560
  value=True
561
  )
562
 
563
  with gr.Row():
564
+ submit_btn = gr.Button("πŸš€ Get Coordination Help", variant="primary")
565
  clear_form_btn = gr.Button("πŸ—‘οΈ Clear Form", variant="secondary")
566
 
567
  with gr.Row():
568
+ report_btn = gr.Button("πŸ“‹ Submit & Send Report", variant="secondary")
569
  clear_btn = gr.Button("πŸ—‚οΈ Clear History", variant="stop")
570
+ stats_btn = gr.Button("πŸ“ˆ View Stats")
571
 
572
  status_display = gr.Textbox(
573
  label="System Status",
 
576
  )
577
 
578
  stats_display = gr.Textbox(
579
+ label="Activity Summary",
580
  interactive=False,
581
+ max_lines=6
582
  )
583
 
584
  with gr.Column(scale=2):
585
+ gr.Markdown("### πŸ’‘ Coordination Guidance")
586
  output = gr.Textbox(
587
+ label="Recommended Actions",
588
  lines=18,
589
  show_copy_button=True
590
  )
591
 
592
+ with gr.Accordion("🏒 Department Overview", open=True):
593
  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.*")
594
 
595
+ with gr.Accordion("πŸ“œ Recent Activity", open=False):
596
  history_display = gr.JSON(
597
  label="Activity Log",
598
  value=conversation_history[-10:] if conversation_history else []