Update app.py
Browse files
app.py
CHANGED
|
@@ -2,125 +2,151 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 5 |
def load_data():
|
| 6 |
-
files = [f for f in os.listdir('.') if f.endswith(('.xls', '.xlsx', '.csv'))]
|
| 7 |
-
if not files: return pd.DataFrame()
|
| 8 |
try:
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
df.columns = [str(c).strip() for c in df.columns]
|
| 11 |
if 'رقم الطالب' in df.columns:
|
| 12 |
df['رقم الطالب'] = df['رقم الطالب'].astype(str).str.replace('.0', '', regex=False).str.strip()
|
| 13 |
return df
|
| 14 |
-
except
|
|
|
|
|
|
|
| 15 |
|
| 16 |
df_global = load_data()
|
| 17 |
|
| 18 |
def check_eligibility(student_id, doc_type):
|
| 19 |
-
if df_global.empty:
|
|
|
|
| 20 |
|
| 21 |
sid = str(student_id).strip()
|
| 22 |
student = df_global[df_global['رقم الطالب'] == sid]
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
row = student.iloc[0]
|
| 26 |
name = row.get('اسم الطالب', 'طالب')
|
| 27 |
status = str(row.get('الحالة الأكاديمية', '')).strip()
|
| 28 |
balance = float(row.get('الرصيد المالي', 0))
|
| 29 |
college = str(row.get('الكلية', '')).strip()
|
| 30 |
-
major = str(row.get('التخصص', '')).strip()
|
| 31 |
adm_type = str(row.get('نوع الالتحاق بالجامعة', '')).strip()
|
| 32 |
|
| 33 |
-
# فحص الح
|
| 34 |
discipline = "سليم"
|
| 35 |
for col in row.index:
|
| 36 |
-
if "التأديبية" in col:
|
| 37 |
discipline = str(row[col]).strip()
|
| 38 |
break
|
| 39 |
|
| 40 |
-
|
| 41 |
-
welcome = f"<h2 style='color: #2c3e50; margin-bottom: 15px;'>أهلاً وسهلاً بالطالب/ {name}</h2>"
|
| 42 |
rejections = []
|
| 43 |
|
| 44 |
-
# 1.
|
| 45 |
-
if "معاقب" in discipline:
|
| 46 |
-
rejections.append("ت
|
| 47 |
|
| 48 |
-
# ت
|
|
|
|
| 49 |
is_enrollment = "شهادة قيد" in doc_type
|
| 50 |
-
is_science_doc = "الكليات العلمية" in doc_type
|
| 51 |
-
is_financial = "إفادة مالية" in doc_type
|
| 52 |
is_external_transcript = "للاستخدام الخارجي" in doc_type
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
# 2.
|
| 55 |
-
if
|
| 56 |
-
if status not in ["منتظم", "متوقع تخرجه"]:
|
| 57 |
-
rejections.append(f"هذه الوثيقة تمنح للمنتظمين فقط، وحالتك الحالية هي ({status}).")
|
| 58 |
-
elif is_science_doc:
|
| 59 |
-
target_colleges = ["إدارة المال والأعمال", "طب الأسنان", "الدراسات المتوسطة", "التربية", "الهندسـة التطبيقية", "تكنولوجيا المعلومات", "القانون", "العلوم الطبية والصحية", "الصيدلة", "هندسة البرمجيات"]
|
| 60 |
-
if not any(c in college for c in target_colleges):
|
| 61 |
-
rejections.append(f"عذراً، كليتك ({college}) ليست ضمن الكليات العلمية المحددة لهذه الإفادة.")
|
| 62 |
-
|
| 63 |
-
if not rejections:
|
| 64 |
-
if status in ["منتظم", "متوقع تخرجه"]:
|
| 65 |
-
msg = f"{welcome}ℹ️ حالة الطالب ({status}): يرجى مراجعة كليتك مباشرة لإصدار هذه الإفادة العلمية."
|
| 66 |
-
return f"<div style='{base_style} background-color: #e3f2fd; color: #0d47a1;'>{msg}</div>", gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 67 |
-
elif status != "خريج":
|
| 68 |
-
rejections.append(f"حالتك الأكاديمية ({status}) لا تسمح بهذا الطلب.")
|
| 69 |
-
else: # بقية وثائق الخريجين
|
| 70 |
if status != "خريج":
|
| 71 |
-
rejections.append(f"هذه الوثيقة
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
if status == "خريج":
|
| 78 |
-
for c in ['صفحة الطالب', 'عمادة الكلية', 'شؤون الطلبة', 'المالية']:
|
| 79 |
-
if "نعم" not in str(row.get(f'خلو الطرف من {c}', '')):
|
| 80 |
-
rejections.append(f"لم تكتمل إجراءات خلو الطرف من جهة ({c}).")
|
| 81 |
-
|
| 82 |
-
# 4. 🔍 فحص بدل الفاقد
|
| 83 |
-
is_duplicate = False
|
| 84 |
if not rejections:
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
|
| 93 |
-
# م
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
if rejections:
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
#
|
| 100 |
-
|
| 101 |
-
status_msg = "⚠️ تنبيه: طلب بدل فاقد (الوثيقة صدرت سابقاً)" if is_duplicate else "✅ طلب استخ��اج لأول مرة"
|
| 102 |
-
final_html = f"<div style='{base_style} background-color: {bg_color};'>{welcome}<h3>{status_msg}</h3><p>أنت مستحق لـ ({doc_type}). يرجى إرفاق المستندات المطلوبة.</p></div>"
|
| 103 |
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
| 105 |
|
|
|
|
|
|
|
|
|
|
| 106 |
docs_list = [
|
| 107 |
-
"طلب استخراج شهادة إلكترونية",
|
| 108 |
-
"
|
| 109 |
-
"طلب
|
| 110 |
-
"
|
| 111 |
-
"طلب كشف درجات
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
]
|
|
|
|
| 113 |
with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {direction: rtl;}") as demo:
|
| 114 |
-
gr.HTML("<h1 style='text-align: center;
|
| 115 |
with gr.Row():
|
| 116 |
-
t_id = gr.Textbox(label="الرقم الجامعي", placeholder="
|
| 117 |
-
d_doc = gr.Dropdown(choices=docs_list, label="اسم الوثيقة", value=docs_list[0])
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
with gr.Column() as
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# وظيفة تحميل البيانات مع معالجة الأخطاء لضمان عدم توقف النظام
|
| 6 |
def load_data():
|
|
|
|
|
|
|
| 7 |
try:
|
| 8 |
+
files = [f for f in os.listdir('.') if f.endswith(('.xls', '.xlsx', '.csv'))]
|
| 9 |
+
if not files:
|
| 10 |
+
return pd.DataFrame()
|
| 11 |
+
|
| 12 |
+
file_path = files[0]
|
| 13 |
+
if file_path.endswith('.csv'):
|
| 14 |
+
df = pd.read_csv(file_path, encoding='utf-8-sig')
|
| 15 |
+
else:
|
| 16 |
+
df = pd.read_excel(file_path)
|
| 17 |
+
|
| 18 |
df.columns = [str(c).strip() for c in df.columns]
|
| 19 |
if 'رقم الطالب' in df.columns:
|
| 20 |
df['رقم الطالب'] = df['رقم الطالب'].astype(str).str.replace('.0', '', regex=False).str.strip()
|
| 21 |
return df
|
| 22 |
+
except Exception as e:
|
| 23 |
+
print(f"Error loading data: {e}")
|
| 24 |
+
return pd.DataFrame()
|
| 25 |
|
| 26 |
df_global = load_data()
|
| 27 |
|
| 28 |
def check_eligibility(student_id, doc_type):
|
| 29 |
+
if df_global.empty:
|
| 30 |
+
return "<div style='text-align:center; color:orange;'>⚠️ تنبيه: قاعدة البيانات غير متصلة حالياً.</div>", gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 31 |
|
| 32 |
sid = str(student_id).strip()
|
| 33 |
student = df_global[df_global['رقم الطالب'] == sid]
|
| 34 |
+
|
| 35 |
+
if len(student) == 0:
|
| 36 |
+
return "<div style='text-align:center; color:red;'>❌ الرقم الجامعي غير موجود بالنظام.</div>", gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 37 |
|
| 38 |
row = student.iloc[0]
|
| 39 |
name = row.get('اسم الطالب', 'طالب')
|
| 40 |
status = str(row.get('الحالة الأكاديمية', '')).strip()
|
| 41 |
balance = float(row.get('الرصيد المالي', 0))
|
| 42 |
college = str(row.get('الكلية', '')).strip()
|
|
|
|
| 43 |
adm_type = str(row.get('نوع الالتحاق بالجامعة', '')).strip()
|
| 44 |
|
| 45 |
+
# فحص الحظر التأديبي
|
| 46 |
discipline = "سليم"
|
| 47 |
for col in row.index:
|
| 48 |
+
if "تأديبية" in col or "التأديبية" in col:
|
| 49 |
discipline = str(row[col]).strip()
|
| 50 |
break
|
| 51 |
|
| 52 |
+
welcome_msg = f"<h2 style='text-align:center; color:#2c3e50;'>أهلاً بك: {name}</h2>"
|
|
|
|
| 53 |
rejections = []
|
| 54 |
|
| 55 |
+
# 1. القاعدة العامة: الحظر التأديبي
|
| 56 |
+
if "معاقب" in discipline or "محروم" in discipline:
|
| 57 |
+
rejections.append("أنت محروم بقرار تأديبي من الحصول على الوثائق الجامعية.")
|
| 58 |
|
| 59 |
+
# تحديد نوع الوثيقة
|
| 60 |
+
is_grad_doc = any(x in doc_type for x in ["خريج", "شهادة إلكترونية", "بدل فاقد"])
|
| 61 |
is_enrollment = "شهادة قيد" in doc_type
|
|
|
|
|
|
|
| 62 |
is_external_transcript = "للاستخدام الخارجي" in doc_type
|
| 63 |
+
is_financial = "إفادة مالية" in doc_type
|
| 64 |
+
is_science = "الكليات العلمية" in doc_type
|
| 65 |
|
| 66 |
+
# 2. فحص الحالة الأكاديمية حسب نوع الطلب
|
| 67 |
+
if is_grad_doc:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
if status != "خريج":
|
| 69 |
+
rejections.append(f"هذه الوثيقة تتطلب حالة (خريج)، وحالتك الحالية هي ({status}).")
|
| 70 |
+
elif is_enrollment or is_external_transcript:
|
| 71 |
+
if status not in ["منتظم", "متوقع تخرجه"]:
|
| 72 |
+
rejections.append(f"هذه الوثيقة للمنتظمين فقط، وحالتك الحالية هي ({status})[cite: 4].")
|
| 73 |
+
|
| 74 |
+
# 3. فحص الرصيد المالي وخلو الطرف (مستثنى منه شهادة القيد والإفادة المالية حسب الشروط)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
if not rejections:
|
| 76 |
+
if not (is_enrollment or is_financial or is_science):
|
| 77 |
+
if balance > 0:
|
| 78 |
+
rejections.append(f"يجب تسديد كامل الرسوم (الرصيد الحالي: {balance} دينار).")
|
| 79 |
+
if status == "خريج":
|
| 80 |
+
for c in ['صفحة الطالب', 'عمادة الكلية', 'شؤون الطلبة', 'المالية']:
|
| 81 |
+
if "نعم" not in str(row.get(f'خلو الطرف من {c}', '')):
|
| 82 |
+
rejections.append(f"لم تكتمل إجراءات خلو الطرف من جهة ({c}).")
|
| 83 |
|
| 84 |
+
# 4. منطق بدل الفاقد
|
| 85 |
+
is_duplicate = False
|
| 86 |
+
check_col = ""
|
| 87 |
+
if "شهادة إلكترونية" in doc_type: check_col = "صدرت له شهادة"
|
| 88 |
+
elif "كشف درجات خريج" in doc_type: check_col = doc_type.replace("طلب ", "")
|
| 89 |
+
|
| 90 |
+
if check_col in row.index and str(row[check_col]).strip() == "نعم":
|
| 91 |
+
is_duplicate = True
|
| 92 |
+
|
| 93 |
+
# عرض الرفض
|
| 94 |
if rejections:
|
| 95 |
+
reasons = "".join([f"<li style='color:#842029;'>{r}</li>" for r in rejections])
|
| 96 |
+
return f"{welcome_msg}<div style='background:#f8d7da; padding:15px; border-radius:10px;'><b>تم الرفض:</b><ul>{reasons}</ul></div>", gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 97 |
+
|
| 98 |
+
# النجاح والاستحقاق
|
| 99 |
+
res_style = "background:#fff3cd;" if is_duplicate else "background:#f0fff4;"
|
| 100 |
+
status_label = "⚠️ طلب بدل فاقد" if is_duplicate else "✅ طلب استخراج جديد"
|
|
|
|
|
|
|
| 101 |
|
| 102 |
+
html_res = f"""<div style='{res_style} padding:20px; border-radius:15px; text-align:center;'>
|
| 103 |
+
{welcome_msg} <h3>{status_label}</h3>
|
| 104 |
+
<p>طلبك لـ ({doc_type}) مستوفي للشروط. يرجى رفع المرفقات المطلوبة أدناه.</p>
|
| 105 |
+
</div>"""
|
| 106 |
|
| 107 |
+
return html_res, gr.update(visible=True), gr.update(visible="مجسر" in adm_type), gr.update(visible="منتقل" in adm_type), gr.update(visible=True)
|
| 108 |
+
|
| 109 |
+
# القائمة الكاملة والمرتبة كما في الخانة الأولى من الجدول
|
| 110 |
docs_list = [
|
| 111 |
+
"طلب استخراج شهادة إلكترونية",
|
| 112 |
+
"طلب استخراج شهادة (بدل فاقد)",
|
| 113 |
+
"طلب كشف درجات خريج (العربية)",
|
| 114 |
+
"طلب كشف درجات خريج (الإنجليزية)",
|
| 115 |
+
"طلب كشف درجات خريج (بدل فاقد) - العربية",
|
| 116 |
+
"طلب كشف درجات خريج (بدل فاقد) - الإنجليزية",
|
| 117 |
+
"طلب إفادة خريج رسمية بالمعدل (العربية)",
|
| 118 |
+
"طلب إفادة خريج رسمية (الإنجليزية)",
|
| 119 |
+
"طلب إفادة مالية لخريج بدون معدل (العربية)",
|
| 120 |
+
"طلب إفادة مالية لخريج بدون معدل (الإنجليزية)",
|
| 121 |
+
"طلب إفادة دراسة باللغة الإنجليزية (الكليات العلمية)",
|
| 122 |
+
"طلب شهادة قيد (العربية)",
|
| 123 |
+
"طلب شهادة قيد (الانجليزية)",
|
| 124 |
+
"طلب كشف درجات للاستخدام الخارجي (معتمد) - العربية",
|
| 125 |
+
"طلب كشف درجات للاستخدام الخارجي (معتمد) - الإنجليزية"
|
| 126 |
]
|
| 127 |
+
|
| 128 |
with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {direction: rtl;}") as demo:
|
| 129 |
+
gr.HTML("<h1 style='text-align: center;'>🎓 نظام خدمات القبول والتسجيل الإلكتروني</h1>")
|
| 130 |
with gr.Row():
|
| 131 |
+
t_id = gr.Textbox(label="الرقم الجامعي", placeholder="مثال: 20241010")
|
| 132 |
+
d_doc = gr.Dropdown(choices=docs_list, label="اسم الوثيقة المطلوب استخراجها", value=docs_list[0])
|
| 133 |
+
|
| 134 |
+
btn = gr.Button("تحقق من الاستحقاق وفتح نموذج الطلب", variant="primary")
|
| 135 |
+
res_area = gr.HTML()
|
| 136 |
+
|
| 137 |
+
with gr.Group(visible=False) as upload_form:
|
| 138 |
+
gr.Markdown("### 📥 المستندات المطلوبة (يرجى الرفع بصيغة PDF أو صور)")
|
| 139 |
+
gr.File(label="📷 صورة الهوية الشخصية / جواز السفر (إلزامي)")
|
| 140 |
+
with gr.Column(visible=False) as mujasir_sec:
|
| 141 |
+
gr.File(label="📜 شهادة الشامل أو كشف درجات الدبلوم (للمجسرين) ")
|
| 142 |
+
with gr.Column(visible=False) as transfer_sec:
|
| 143 |
+
gr.File(label="📑 كشف درجات الجامعة السابقة (للمنتقلين)")
|
| 144 |
+
with gr.Column() as payment_sec:
|
| 145 |
+
gr.File(label="📑 إشعار الدفع البنكي (للطلبات التي تتطلب رسوم)")
|
| 146 |
+
|
| 147 |
+
email = gr.Textbox(label="البريد الإلكتروني الشخصي (للتواصل) ", placeholder="name@example.com")
|
| 148 |
+
gr.Button("إرسال الطلب لعمادة القبول والتسجيل").click(lambda: "✅ تم استلام طلبك بنجاح. يمكنك تعقب الحالة عبر صفحتك الشخصية.", None, gr.Textbox(label="الحالة"))
|
| 149 |
+
|
| 150 |
+
btn.click(check_eligibility, [t_id, d_doc], [res_area, upload_form, mujasir_sec, transfer_sec, payment_sec])
|
| 151 |
+
|
| 152 |
+
demo.launch()
|