Dhom1 commited on
Commit
cf6f7bf
·
verified ·
1 Parent(s): dc2890b

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +52 -27
streamlit_app.py CHANGED
@@ -29,49 +29,75 @@ incident_description = st.text_area("Enter Email Body:")
29
 
30
  # حوادث شائعة
31
  st.sidebar.title("Common Incidents")
32
- common_incidents = ["Forgot Password", "Unable to access CRM", "Service Unavailable", "Data not syncing", "User unable to login"]
33
 
34
  for incident in common_incidents:
35
  if st.sidebar.button(incident):
36
  incident_description = incident
37
 
38
- # ✅ تحسين التصنيف مع المزيد من الكلمات المفتاحية
39
- def categorize_email(email_text):
40
  email_text = email_text.lower()
41
-
42
- # تحديد الحالات بناءً على كلمات مفتاحية
43
  if re.search(r"(password|reset|forgot)", email_text):
44
- return "Forgot Password"
45
  elif re.search(r"(access|login|account|unable to login|cannot access)", email_text):
46
- return "Support Request"
47
  elif re.search(r"(quote|price|pricing|cost|sales)", email_text):
48
- return "Sales Inquiry"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  else:
50
- return "Uncategorized"
 
 
51
 
52
  # ✅ توليد الحلول المؤقتة
53
  def generate_temporary_solution(incident_type):
54
- if incident_type == "Forgot Password":
55
- return (
56
  "To reset your password, please click on the 'Forgot Password' link on the login page. "
57
  "If you still face issues, kindly share any error messages you encounter."
58
- )
59
- elif incident_type == "Support Request":
60
- return (
61
  "If you are unable to access your account, try the following:\n"
62
  "1. Ensure that you are using the correct username and password.\n"
63
  "2. Clear your browser cache and try again.\n"
64
  "3. If the issue persists, please provide the error message or screenshot for further assistance."
65
- )
66
- elif incident_type == "Sales Inquiry":
67
- return (
68
  "Thank you for your interest. Our sales team will reach out to you shortly. "
69
  "In the meantime, please specify the product or service you are inquiring about."
70
- )
71
- else:
72
- return (
 
 
 
73
  "Your request is not clear. Please provide more information so we can assist you effectively."
74
- )
 
 
 
75
 
76
  # ✅ توليد الرد النهائي
77
  def generate_response(subject, body, incident_type):
@@ -94,8 +120,8 @@ def generate_response(subject, body, incident_type):
94
  if st.button("Submit"):
95
  if subject and incident_description:
96
  with st.spinner("Processing..."):
97
- # تصنيف الحادث
98
- incident_type = categorize_email(incident_description)
99
 
100
  # توليد الردود والحلول
101
  acknowledgement, solution, response = generate_response(subject, incident_description, incident_type)
@@ -124,10 +150,9 @@ if st.button("Submit"):
124
 
125
  # ✅ تعبئة الحقول في CRM
126
  st.subheader("🛠️ CRM Fields")
127
- st.write("**Title:**", incident_type)
128
- st.write("**Affect Service:**", "CRM" if "crm" in incident_description.lower() else "General")
129
- st.write("**Configuration:**", "Default Configuration")
130
- st.write("**Incident Area:**", "Login" if "login" in incident_description.lower() else "General")
131
  st.write("**Submitted On:**", datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
132
  st.write("**Incident Description:**", incident_description)
133
  st.write("**Solution:**", solution)
 
29
 
30
  # حوادث شائعة
31
  st.sidebar.title("Common Incidents")
32
+ common_incidents = ["Forgot Password", "Unable to access CRM", "Service Unavailable", "Data not syncing", "Payment Issue"]
33
 
34
  for incident in common_incidents:
35
  if st.sidebar.button(incident):
36
  incident_description = incident
37
 
38
+ # ✅ تحسين التحليل باستخدام الكلمات المفتاحية
39
+ def analyze_content(email_text):
40
  email_text = email_text.lower()
41
+
42
+ # تحديد نوع الحادث
43
  if re.search(r"(password|reset|forgot)", email_text):
44
+ incident_type = "Forgot Password"
45
  elif re.search(r"(access|login|account|unable to login|cannot access)", email_text):
46
+ incident_type = "Support Request"
47
  elif re.search(r"(quote|price|pricing|cost|sales)", email_text):
48
+ incident_type = "Sales Inquiry"
49
+ elif re.search(r"(payment|billing|invoice)", email_text):
50
+ incident_type = "Payment Issue"
51
+ else:
52
+ incident_type = "Uncategorized"
53
+
54
+ # تحديد المنطقة المتأثرة
55
+ if re.search(r"(login|sign in|authentication)", email_text):
56
+ affected_area = "Login"
57
+ elif re.search(r"(crm|dashboard|portal)", email_text):
58
+ affected_area = "CRM"
59
+ elif re.search(r"(payment|invoice|billing)", email_text):
60
+ affected_area = "Payment"
61
+ else:
62
+ affected_area = "General"
63
+
64
+ # تحديد مستوى الأهمية
65
+ if re.search(r"(urgent|immediately|critical|important)", email_text):
66
+ severity = "Critical"
67
+ elif re.search(r"(slow|delay|not working)", email_text):
68
+ severity = "Normal"
69
  else:
70
+ severity = "Low"
71
+
72
+ return incident_type, affected_area, severity
73
 
74
  # ✅ توليد الحلول المؤقتة
75
  def generate_temporary_solution(incident_type):
76
+ solutions = {
77
+ "Forgot Password": (
78
  "To reset your password, please click on the 'Forgot Password' link on the login page. "
79
  "If you still face issues, kindly share any error messages you encounter."
80
+ ),
81
+ "Support Request": (
 
82
  "If you are unable to access your account, try the following:\n"
83
  "1. Ensure that you are using the correct username and password.\n"
84
  "2. Clear your browser cache and try again.\n"
85
  "3. If the issue persists, please provide the error message or screenshot for further assistance."
86
+ ),
87
+ "Sales Inquiry": (
 
88
  "Thank you for your interest. Our sales team will reach out to you shortly. "
89
  "In the meantime, please specify the product or service you are inquiring about."
90
+ ),
91
+ "Payment Issue": (
92
+ "If you are facing a payment issue, please verify the payment method and try again. "
93
+ "If the issue persists, provide the transaction ID or screenshot of the error."
94
+ ),
95
+ "Uncategorized": (
96
  "Your request is not clear. Please provide more information so we can assist you effectively."
97
+ ),
98
+ }
99
+
100
+ return solutions.get(incident_type, "Your request is not clear. Please provide more information.")
101
 
102
  # ✅ توليد الرد النهائي
103
  def generate_response(subject, body, incident_type):
 
120
  if st.button("Submit"):
121
  if subject and incident_description:
122
  with st.spinner("Processing..."):
123
+ # تصنيف الحادث وتحليل المحتوى
124
+ incident_type, affected_area, severity = analyze_content(incident_description)
125
 
126
  # توليد الردود والحلول
127
  acknowledgement, solution, response = generate_response(subject, incident_description, incident_type)
 
150
 
151
  # ✅ تعبئة الحقول في CRM
152
  st.subheader("🛠️ CRM Fields")
153
+ st.write("**Incident Type:**", incident_type)
154
+ st.write("**Affected Area:**", affected_area)
155
+ st.write("**Severity Level:**", severity)
 
156
  st.write("**Submitted On:**", datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
157
  st.write("**Incident Description:**", incident_description)
158
  st.write("**Solution:**", solution)