Ai_Agent_DI / streamlit_app.py
Dhom1's picture
Update streamlit_app.py
207aed2 verified
import streamlit as st
from transformers import pipeline, set_seed
from datetime import datetime
from PIL import Image
import re
import logging
import os
# Configure Logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
st.set_page_config(page_title="AI Incident Handler", page_icon="🤖")
# عرض اللوقو من الملف مباشرة
LOGO_PATH = "assets/company_logo.png"
if os.path.exists(LOGO_PATH):
logo = Image.open(LOGO_PATH)
st.image(logo, width=150)
st.title("AI Incident Handler")
st.write("Automate incident classification, provide temporary solutions, and fill CRM fields.")
st.markdown("---")
# إدخال الإيميل
st.subheader("📧 Enter Email Details")
subject = st.text_input("Enter Email Subject:")
incident_description = st.text_area("Enter Email Body:")
# حوادث شائعة
st.sidebar.title("Common Incidents")
common_incidents = ["Forgot Password", "Unable to access CRM", "Service Unavailable", "Data not syncing", "User unable to login"]
for incident in common_incidents:
if st.sidebar.button(incident):
incident_description = incident
# ✅ تحسين التصنيف مع المزيد من الكلمات المفتاحية
def categorize_email(email_text):
email_text = email_text.lower()
# تحديد الحالات بناءً على كلمات مفتاحية
if re.search(r"(password|reset|forgot)", email_text):
return "Forgot Password"
elif re.search(r"(access|login|account|unable to login|cannot access)", email_text):
return "Support Request"
elif re.search(r"(quote|price|pricing|cost|sales)", email_text):
return "Sales Inquiry"
else:
return "Uncategorized"
# ✅ توليد الحلول المؤقتة
def generate_temporary_solution(incident_type):
if incident_type == "Forgot Password":
return (
"To reset your password, please click on the 'Forgot Password' link on the login page. "
"If you still face issues, kindly share any error messages you encounter."
)
elif incident_type == "Support Request":
return (
"If you are unable to access your account, try the following:\n"
"1. Ensure that you are using the correct username and password.\n"
"2. Clear your browser cache and try again.\n"
"3. If the issue persists, please provide the error message or screenshot for further assistance."
)
elif incident_type == "Sales Inquiry":
return (
"Thank you for your interest. Our sales team will reach out to you shortly. "
"In the meantime, please specify the product or service you are inquiring about."
)
else:
return (
"Your request is not clear. Please provide more information so we can assist you effectively."
)
# ✅ توليد الرد النهائي
def generate_response(subject, body, incident_type):
# Acknowledgement Email
acknowledgement = f"Thank you for reaching out. We have received your request regarding '{subject}'. Our support team is currently reviewing it."
# Temporary Solution
solution = generate_temporary_solution(incident_type)
additional_info = "Could you provide more details regarding the specific problem you are experiencing?"
# إذا كان الحادث مصنفًا بوضوح، يتم عرض الحل مباشرة
if incident_type != "Uncategorized":
response = f"{acknowledgement}\n\n**Temporary Solution:**\n{solution}"
else:
response = f"{acknowledgement}\n\n**Temporary Solution:**\n{solution}\n\n**Request for More Information:**\n{additional_info}"
return acknowledgement, solution, response
# ✅ زر الإرسال
if st.button("Submit"):
if subject and incident_description:
with st.spinner("Processing..."):
# تصنيف الحادث
incident_type = categorize_email(incident_description)
# توليد الردود والحلول
acknowledgement, solution, response = generate_response(subject, incident_description, incident_type)
# عرض رسالة التأكيد
st.success("Thank you for your submission. We are currently processing your request.")
st.write("---")
# ✅ Acknowledgement Email
st.subheader("📧 Acknowledgement Email")
st.write(f"To: customer@example.com")
st.write(f"Subject: {subject}")
st.write(f"Body:\n{acknowledgement}")
st.write("---")
# ✅ Temporary Solution
st.subheader("🚀 Temporary Solution")
st.write(solution)
st.write("---")
# ✅ طلب المزيد من التفاصيل إذا كان التصنيف غير واضح
if incident_type == "Uncategorized":
st.subheader("❓ Request for More Information")
st.write("Could you provide more details regarding the specific problem you are experiencing?")
st.write("---")
# ✅ تعبئة الحقول في CRM
st.subheader("🛠️ CRM Fields")
st.write("**Title:**", incident_type)
st.write("**Affect Service:**", "CRM" if "crm" in incident_description.lower() else "General")
st.write("**Configuration:**", "Default Configuration")
st.write("**Incident Area:**", "Login" if "login" in incident_description.lower() else "General")
st.write("**Submitted On:**", datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
st.write("**Incident Description:**", incident_description)
st.write("**Solution:**", solution)
else:
st.warning("Please enter both subject and body to proceed.")