Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,901 +0,0 @@
|
|
| 1 |
-
# app.py
|
| 2 |
-
# ================== الاستيراد ==================
|
| 3 |
-
import gradio as gr
|
| 4 |
-
import pandas as pd
|
| 5 |
-
import numpy as np
|
| 6 |
-
import tempfile
|
| 7 |
-
import os, pickle
|
| 8 |
-
from datetime import datetime
|
| 9 |
-
import io, base64
|
| 10 |
-
import arabic_reshaper
|
| 11 |
-
from bidi.algorithm import get_display
|
| 12 |
-
import matplotlib.pyplot as plt
|
| 13 |
-
from sentence_transformers import SentenceTransformer, util
|
| 14 |
-
from Bio import Entrez
|
| 15 |
-
import gdown
|
| 16 |
-
|
| 17 |
-
# ================== دوال مساعدة ==================
|
| 18 |
-
def download_from_drive(file_id, output):
|
| 19 |
-
url = f"https://drive.google.com/uc?id={file_id}"
|
| 20 |
-
try:
|
| 21 |
-
gdown.download(url, output, quiet=True)
|
| 22 |
-
except Exception:
|
| 23 |
-
# إذا فشل التحميل من Drive نتابع لوجود ملفات محلية بالفعل
|
| 24 |
-
pass
|
| 25 |
-
|
| 26 |
-
# ================== إعدادات ومسارات ==================
|
| 27 |
-
Entrez.email = "emananter0123@gmail.com"
|
| 28 |
-
EMB_DIR = "embeddings_cache"
|
| 29 |
-
os.makedirs(EMB_DIR, exist_ok=True)
|
| 30 |
-
|
| 31 |
-
def embeddings_path(name):
|
| 32 |
-
return os.path.join(EMB_DIR, f"{name}_embeddings.pkl")
|
| 33 |
-
|
| 34 |
-
BOOKS_FILE, THESES_FILE, FAQ_FILE = "book.xlsx", "theses.xlsx", "faq.xlsx"
|
| 35 |
-
QUESTIONS_FILE = "questions.csv" # ملف حفظ الأسئلة
|
| 36 |
-
FACULTY_BORROW_FILE = "faculty_borrow.csv" # طلبات أعضاء هيئة التدريس للاستعارة
|
| 37 |
-
|
| 38 |
-
# محاولة تنزيل الملفات من Google Drive (إن أردتِ يمكنك حذف السطور التالية إذا الملفات محلية)
|
| 39 |
-
download_from_drive("1FElHiASfiVLeuHWYaqd2Q5foxWRlJT-O", BOOKS_FILE) # book.xlsx
|
| 40 |
-
download_from_drive("1K2Mtze6ZdvfKUsFMCOWlRBjDq-ZnJNrv", THESES_FILE) # theses.xlsx
|
| 41 |
-
download_from_drive("1ONjXtfv709BOxiIR0Qzmz6lQngnWEEso", FAQ_FILE) # faq.xlsx
|
| 42 |
-
|
| 43 |
-
# ================== تحميل البيانات المحلية ==================
|
| 44 |
-
def load_local_data():
|
| 45 |
-
if not os.path.exists(BOOKS_FILE) or not os.path.exists(THESES_FILE):
|
| 46 |
-
raise FileNotFoundError("تأكدي من رفع الملفات book.xlsx و theses.xlsx في مجلد المشروع.")
|
| 47 |
-
books = pd.read_excel(BOOKS_FILE).fillna("غير متوافر")
|
| 48 |
-
theses = pd.read_excel(THESES_FILE).fillna("غير متوافر")
|
| 49 |
-
# توحيد اسم عمود العنوان بين ملفات مختلفة
|
| 50 |
-
if "Title" not in books.columns and "العنوان" in books.columns:
|
| 51 |
-
books["Title"] = books["العنوان"].astype(str)
|
| 52 |
-
elif "Title" not in books.columns:
|
| 53 |
-
books["Title"] = books.iloc[:,0].astype(str)
|
| 54 |
-
|
| 55 |
-
if "Title" not in theses.columns and "العنوان" in theses.columns:
|
| 56 |
-
theses["Title"] = theses["العنوان"].astype(str)
|
| 57 |
-
elif "Title" not in theses.columns:
|
| 58 |
-
theses["Title"] = theses.iloc[:,0].astype(str)
|
| 59 |
-
|
| 60 |
-
return books, theses
|
| 61 |
-
|
| 62 |
-
books_df, theses_df = load_local_data()
|
| 63 |
-
|
| 64 |
-
# ================== نموذج Semantic ==================
|
| 65 |
-
MODEL_NAME = "all-MiniLM-L6-v2"
|
| 66 |
-
model = SentenceTransformer(MODEL_NAME)
|
| 67 |
-
|
| 68 |
-
def build_or_load_embeddings(df, name):
|
| 69 |
-
path = embeddings_path(name)
|
| 70 |
-
if os.path.exists(path):
|
| 71 |
-
try:
|
| 72 |
-
with open(path,"rb") as f:
|
| 73 |
-
emb = pickle.load(f)
|
| 74 |
-
if len(emb) == len(df):
|
| 75 |
-
return emb
|
| 76 |
-
except Exception:
|
| 77 |
-
pass
|
| 78 |
-
texts = df["Title"].astype(str).tolist()
|
| 79 |
-
emb = model.encode(texts, convert_to_numpy=True, show_progress_bar=True)
|
| 80 |
-
with open(path,"wb") as f:
|
| 81 |
-
pickle.dump(emb,f)
|
| 82 |
-
return emb
|
| 83 |
-
|
| 84 |
-
books_embeddings = build_or_load_embeddings(books_df,"books")
|
| 85 |
-
theses_embeddings = build_or_load_embeddings(theses_df,"theses")
|
| 86 |
-
|
| 87 |
-
# ================== FAQ & مساعد ذكي ==================
|
| 88 |
-
if os.path.exists(FAQ_FILE):
|
| 89 |
-
faq_df = pd.read_excel(FAQ_FILE).fillna("")
|
| 90 |
-
else:
|
| 91 |
-
faq_df = pd.DataFrame({
|
| 92 |
-
"السؤال":["مواعيد المكتبة","خدمات المكتبة","كيفية الاستعارة","التسجيل في بنك المعرفة","التصوير","أقسام المكتبة","التواصل"],
|
| 93 |
-
"الإجابة":[
|
| 94 |
-
"🕘 المكتبة تعمل من السبت إلى الخميس من 9 صباحًا حتى 2 ظهرًا",
|
| 95 |
-
"📌 خدمات المكتبة: الإحاطة الجارية، التسجيل على بنك المعرفة، التصوير، البحث الإلكتروني، الاستعارة الخارجية",
|
| 96 |
-
"✅ يتم استعارة الكتب لمدة أسبوعين (أو حسب القاعدة المحلية)",
|
| 97 |
-
"🔗 التسجيل في بنك المعرفة عبر موقع بنك المعرفة المصري",
|
| 98 |
-
"🖨️ التصوير متاح وفق القواعد",
|
| 99 |
-
"📚 المكتبة بها: قاعة المراجع، قاعة الكتب الدراسية، قاعة الدوريات، قاعة الرسائل الجامعية",
|
| 100 |
-
"☎️ للتواصل: <a href='https://www.facebook.com/share/1AuUSQUn4n/' target='_blank'>صفحة الفيسبوك</a>"
|
| 101 |
-
]
|
| 102 |
-
})
|
| 103 |
-
|
| 104 |
-
faq_questions = faq_df["السؤال"].astype(str).tolist()
|
| 105 |
-
faq_answers = faq_df["الإجابة"].astype(str).tolist()
|
| 106 |
-
|
| 107 |
-
FAQ_EMB_PATH = embeddings_path("faq")
|
| 108 |
-
def build_or_load_faq_embeddings(questions):
|
| 109 |
-
if os.path.exists(FAQ_EMB_PATH):
|
| 110 |
-
try:
|
| 111 |
-
with open(FAQ_EMB_PATH,"rb") as f:
|
| 112 |
-
emb = pickle.load(f)
|
| 113 |
-
if len(emb) == len(questions):
|
| 114 |
-
return emb
|
| 115 |
-
except Exception:
|
| 116 |
-
pass
|
| 117 |
-
emb = model.encode(questions, convert_to_numpy=True, show_progress_bar=False)
|
| 118 |
-
with open(FAQ_EMB_PATH,"wb") as f:
|
| 119 |
-
pickle.dump(emb,f)
|
| 120 |
-
return emb
|
| 121 |
-
|
| 122 |
-
faq_embeddings = build_or_load_faq_embeddings(faq_questions)
|
| 123 |
-
|
| 124 |
-
def library_assistant_smart(question):
|
| 125 |
-
if not str(question).strip():
|
| 126 |
-
return "⚠️ من فضلك اكتب سؤالك"
|
| 127 |
-
q_emb = model.encode([str(question)], convert_to_numpy=True)
|
| 128 |
-
sims = util.cos_sim(q_emb, faq_embeddings)[0].cpu().numpy()
|
| 129 |
-
idx_best = int(np.argmax(sims))
|
| 130 |
-
best_score = sims[idx_best]
|
| 131 |
-
log_usage("المساعد الذكي", question, "FAQ", 1)
|
| 132 |
-
if best_score < 0.75:
|
| 133 |
-
return "❗ لم أجد إجابة مناسبة، حاول صياغة سؤالك بشكل مختلف."
|
| 134 |
-
return f"<b>الإجابة الأقرب:</b><br>{faq_answers[idx_best]}<br><i>درجة التشابه: {best_score:.2f}</i>"
|
| 135 |
-
|
| 136 |
-
# ================== CSS ==================
|
| 137 |
-
CUSTOM_CSS = """<style>
|
| 138 |
-
.styled-table {
|
| 139 |
-
border-collapse: collapse;
|
| 140 |
-
margin: 15px 0;
|
| 141 |
-
font-size: 14px;
|
| 142 |
-
width: 100%;
|
| 143 |
-
text-align: right;
|
| 144 |
-
direction: rtl;
|
| 145 |
-
}
|
| 146 |
-
.styled-table th, .styled-table td {
|
| 147 |
-
border: 1px solid #ddd;
|
| 148 |
-
padding: 8px;
|
| 149 |
-
}
|
| 150 |
-
.styled-table tr:nth-child(even) {background-color: #f9f9f9;}
|
| 151 |
-
.styled-table tr:nth-child(odd) {background-color: #ffffff;}
|
| 152 |
-
.styled-table th {background-color: #4da6ff; color: white;}
|
| 153 |
-
a {color: #0066cc; text-decoration: none;}
|
| 154 |
-
a:hover {text-decoration: underline;}
|
| 155 |
-
.question-card {
|
| 156 |
-
border: 1px solid #ddd;
|
| 157 |
-
padding: 10px;
|
| 158 |
-
margin-bottom: 12px;
|
| 159 |
-
border-radius: 8px;
|
| 160 |
-
background: #fff;
|
| 161 |
-
direction: rtl;
|
| 162 |
-
}
|
| 163 |
-
.question-meta { font-size: 13px; color: #666; margin-bottom:6px; }
|
| 164 |
-
.answer { margin-top:8px; padding:8px; border-radius:6px; background:#f7f7f7; }
|
| 165 |
-
.anon { color:#999; font-style:italic; }
|
| 166 |
-
</style>"""
|
| 167 |
-
|
| 168 |
-
# ================== تتبع الاستخدام ==================
|
| 169 |
-
def log_usage(tab, query="", mode="", results_count=0):
|
| 170 |
-
file_path = "usage_stats.xlsx"
|
| 171 |
-
entry = pd.DataFrame([{
|
| 172 |
-
"التاريخ": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
| 173 |
-
"التب": tab,
|
| 174 |
-
"الكلمة المفتاحية": query,
|
| 175 |
-
"نوع البحث": mode,
|
| 176 |
-
"عدد النتائج": results_count
|
| 177 |
-
}])
|
| 178 |
-
if os.path.exists(file_path):
|
| 179 |
-
try:
|
| 180 |
-
old = pd.read_excel(file_path)
|
| 181 |
-
entry = pd.concat([old, entry], ignore_index=True)
|
| 182 |
-
except Exception:
|
| 183 |
-
entry = entry
|
| 184 |
-
entry.to_excel(file_path, index=False)
|
| 185 |
-
|
| 186 |
-
# ================== عرض إحصاءات الاستخدام ==================
|
| 187 |
-
def show_usage_stats():
|
| 188 |
-
file_path = "usage_stats.xlsx"
|
| 189 |
-
if not os.path.exists(file_path):
|
| 190 |
-
return "<p>📊 لا توجد بيانات بعد</p>"
|
| 191 |
-
df = pd.read_excel(file_path)
|
| 192 |
-
total = len(df)
|
| 193 |
-
by_tab = df["التب"].value_counts()
|
| 194 |
-
fig, ax = plt.subplots()
|
| 195 |
-
labels = [get_display(arabic_reshaper.reshape(str(t))) for t in by_tab.index]
|
| 196 |
-
ax.bar(labels, by_tab.values)
|
| 197 |
-
for i, v in enumerate(by_tab.values):
|
| 198 |
-
ax.text(i, v + 0.1, str(v), ha='center', va='bottom', fontsize=10)
|
| 199 |
-
ax.set_title(get_display(arabic_reshaper.reshape("عدد مرات استخدام كل تب")))
|
| 200 |
-
ax.set_xlabel(get_display(arabic_reshaper.reshape("التب")))
|
| 201 |
-
ax.set_ylabel(get_display(arabic_reshaper.reshape("عدد العمليات")))
|
| 202 |
-
plt.xticks(rotation=30, ha='right')
|
| 203 |
-
buf = io.BytesIO()
|
| 204 |
-
plt.tight_layout()
|
| 205 |
-
plt.savefig(buf, format="png")
|
| 206 |
-
plt.close(fig)
|
| 207 |
-
buf.seek(0)
|
| 208 |
-
img = base64.b64encode(buf.read()).decode("utf-8")
|
| 209 |
-
summary = f"<h3>📈 إجمالي الاستخدام: {total} عملية</h3>"
|
| 210 |
-
html = summary + "<img src='data:image/png;base64," + img + "'/>"
|
| 211 |
-
return CUSTOM_CSS + html + df.to_html(escape=False, index=False, classes="styled-table")
|
| 212 |
-
|
| 213 |
-
# ================== تحويل نتائج إلى HTML أنيق ==================
|
| 214 |
-
def results_to_html(df):
|
| 215 |
-
if df.empty:
|
| 216 |
-
return "<p>❌ لا توجد نتائج</p>"
|
| 217 |
-
html = CUSTOM_CSS + "<div style='direction:rtl;text-align:right;'>"
|
| 218 |
-
for i, row in df.iterrows():
|
| 219 |
-
html += "<table class='styled-table' style='margin-bottom:15px;'>"
|
| 220 |
-
html += f"<caption style='caption-side:top;text-align:right;font-weight:bold;margin-bottom:5px;'>📘 النتيجة {i+1}</caption>"
|
| 221 |
-
for col, val in row.items():
|
| 222 |
-
html += f"<tr><th>{col}</th><td>{val}</td></tr>"
|
| 223 |
-
html += "</table>"
|
| 224 |
-
html += "</div>"
|
| 225 |
-
return html
|
| 226 |
-
|
| 227 |
-
def df_to_html(df):
|
| 228 |
-
if isinstance(df, str):
|
| 229 |
-
return df
|
| 230 |
-
if df.empty:
|
| 231 |
-
return "<p>❌ لا توجد نتائج</p>"
|
| 232 |
-
return CUSTOM_CSS + df.to_html(escape=False, index=False, classes="styled-table")
|
| 233 |
-
|
| 234 |
-
# ================== حفظ النتائج إلى ملف Excel ==================
|
| 235 |
-
def save_to_excel(df):
|
| 236 |
-
if df is None or (isinstance(df, pd.DataFrame) and df.empty):
|
| 237 |
-
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx")
|
| 238 |
-
pd.DataFrame().to_excel(tmp.name, index=False)
|
| 239 |
-
return tmp.name
|
| 240 |
-
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx")
|
| 241 |
-
if isinstance(df, pd.DataFrame):
|
| 242 |
-
df.to_excel(tmp.name, index=False)
|
| 243 |
-
else:
|
| 244 |
-
pd.DataFrame({"result_html":[str(df)]}).to_excel(tmp.name, index=False)
|
| 245 |
-
return tmp.name
|
| 246 |
-
|
| 247 |
-
# ================== البحث المحلي ==================
|
| 248 |
-
def local_search_df(query, category, mode):
|
| 249 |
-
if not query or not str(query).strip():
|
| 250 |
-
return "<p>⚠️ اكتب كلمة أو جملة للبحث</p>", pd.DataFrame()
|
| 251 |
-
|
| 252 |
-
if mode == "نصي":
|
| 253 |
-
if category == "Books":
|
| 254 |
-
if "العنوان" in books_df.columns:
|
| 255 |
-
df = books_df[books_df["العنوان"].astype(str).str.contains(query, case=False, na=False)]
|
| 256 |
-
else:
|
| 257 |
-
df = books_df[books_df["Title"].astype(str).str.contains(query, case=False, na=False)]
|
| 258 |
-
else:
|
| 259 |
-
if "العنوان" in theses_df.columns:
|
| 260 |
-
df = theses_df[theses_df["العنوان"].astype(str).str.contains(query, case=False, na=False)]
|
| 261 |
-
else:
|
| 262 |
-
df = theses_df[theses_df["Title"].astype(str).str.contains(query, case=False, na=False)]
|
| 263 |
-
else:
|
| 264 |
-
q_emb = model.encode([query], convert_to_numpy=True)
|
| 265 |
-
if category == "Books":
|
| 266 |
-
scores = util.cos_sim(q_emb, books_embeddings)[0].cpu().numpy()
|
| 267 |
-
idx = np.argsort(-scores)
|
| 268 |
-
df = books_df.iloc[idx]
|
| 269 |
-
else:
|
| 270 |
-
scores = util.cos_sim(q_emb, theses_embeddings)[0].cpu().numpy()
|
| 271 |
-
idx = np.argsort(-scores)
|
| 272 |
-
df = theses_df.iloc[idx]
|
| 273 |
-
|
| 274 |
-
if df is None or df.empty:
|
| 275 |
-
df = pd.DataFrame([{"نتيجة":"❌ لم يتم العثور على نتائج"}])
|
| 276 |
-
else:
|
| 277 |
-
if "Title" in df.columns:
|
| 278 |
-
df = df.drop(columns=["Title"])
|
| 279 |
-
|
| 280 |
-
log_usage("البحث المحلي", query, mode, len(df) if isinstance(df, pd.DataFrame) else 0)
|
| 281 |
-
html_results = results_to_html(df)
|
| 282 |
-
return html_results, df
|
| 283 |
-
|
| 284 |
-
# ================== البحث في PubMed ==================
|
| 285 |
-
def search_pubmed_html(query, max_results=5):
|
| 286 |
-
if not query or not str(query).strip():
|
| 287 |
-
return "<p>⚠️ اكتب كلمة للبحث</p>"
|
| 288 |
-
try:
|
| 289 |
-
handle = Entrez.esearch(db="pubmed", term=query, retmax=max_results)
|
| 290 |
-
record = Entrez.read(handle)
|
| 291 |
-
handle.close()
|
| 292 |
-
ids = record.get("IdList", [])
|
| 293 |
-
if not ids:
|
| 294 |
-
return "<p>❌ لا توجد نتائج</p>"
|
| 295 |
-
|
| 296 |
-
handle = Entrez.efetch(db="pubmed", id=",".join(ids), rettype="xml", retmode="xml")
|
| 297 |
-
records = Entrez.read(handle)
|
| 298 |
-
handle.close()
|
| 299 |
-
|
| 300 |
-
rows = []
|
| 301 |
-
for rec in records.get('PubmedArticle', []):
|
| 302 |
-
try:
|
| 303 |
-
title = rec['MedlineCitation']['Article']['ArticleTitle']
|
| 304 |
-
pmid = rec['MedlineCitation']['PMID']
|
| 305 |
-
link = f"https://pubmed.ncbi.nlm.nih.gov/{pmid}/"
|
| 306 |
-
rows.append({
|
| 307 |
-
"الموقع": "PubMed",
|
| 308 |
-
"الوصف": "قاعدة بيانات PubMed",
|
| 309 |
-
"العنوان": title,
|
| 310 |
-
"الرابط": f"<a href='{link}' target='_blank'>فتح</a>"
|
| 311 |
-
})
|
| 312 |
-
except Exception:
|
| 313 |
-
continue
|
| 314 |
-
|
| 315 |
-
if not rows:
|
| 316 |
-
return "<p>❌ لم يتم العثور على نتائج صالحة.</p>"
|
| 317 |
-
|
| 318 |
-
df = pd.DataFrame(rows)
|
| 319 |
-
log_usage("المصادر الخارجية", query, "PubMed", len(df))
|
| 320 |
-
return CUSTOM_CSS + df.to_html(escape=False, index=False, classes="styled-table")
|
| 321 |
-
|
| 322 |
-
except Exception as e:
|
| 323 |
-
return f"<p>❌ حدث خطأ أثناء جلب البيانات من PubMed:<br>{str(e)}</p>"
|
| 324 |
-
|
| 325 |
-
# ================== البحث في المواقع الخارجية ==================
|
| 326 |
-
EXTERNAL_LINKS = {
|
| 327 |
-
"Google Scholar": {"url": "https://scholar.google.com/scholar?q=", "desc": "محرك بحث للأبحاث"},
|
| 328 |
-
"PubMed": {"url": "https://pubmed.ncbi.nlm.nih.gov/?term=", "desc": "قاعدة بيانات PubMed"},
|
| 329 |
-
"Europe PMC": {"url": "https://europepmc.org/search?query=", "desc": "أبحاث Europe PMC"},
|
| 330 |
-
"ClinicalTrials.gov": {"url": "https://clinicaltrials.gov/search?term=", "desc": "تجارب سريرية"},
|
| 331 |
-
"OpenFDA": {"url": "https://open.fda.gov/", "desc": "بيانات الأدوية FDA"},
|
| 332 |
-
"MedlinePlus": {"url": "https://medlineplus.gov/search/?query=", "desc": "معلومات طبية"},
|
| 333 |
-
"DrugBank": {"url": "https://go.drugbank.com/", "desc": "قاعدة بيانات الأدوية"},
|
| 334 |
-
"WHO GHO": {"url": "https://www.who.int/data/gho/", "desc": "بيانات الصحة العالمية"},
|
| 335 |
-
"ICD-11": {"url": "https://icd.who.int/browse11/l-m/en", "desc": "التصنيف الدولي للأمراض"},
|
| 336 |
-
"ClinicalKey": {"url": "https://www.clinicalkey.com/search?q=", "desc": "مصادر طبية شاملة"},
|
| 337 |
-
"Scimago": {"url": "https://www.scimagojr.com/journalsearch.php?q=", "desc": "تصنيف الدوريات"},
|
| 338 |
-
"EKB": {"url": "https://www.ekb.eg/", "desc": "بنك المعرفة المصري"}
|
| 339 |
-
}
|
| 340 |
-
|
| 341 |
-
def external_search_html(query, site):
|
| 342 |
-
try:
|
| 343 |
-
if not query or not str(query).strip():
|
| 344 |
-
return "<p>⚠️ من فضلك اكتب كلمة للبحث</p>"
|
| 345 |
-
|
| 346 |
-
if not site or site not in EXTERNAL_LINKS:
|
| 347 |
-
return f"<p>⚠️ الموقع المحدد غير معروف أو غير موجود في القائمة.</p>"
|
| 348 |
-
|
| 349 |
-
if site == "PubMed":
|
| 350 |
-
return search_pubmed_html(query)
|
| 351 |
-
|
| 352 |
-
base = EXTERNAL_LINKS[site]["url"]
|
| 353 |
-
desc = EXTERNAL_LINKS[site]["desc"]
|
| 354 |
-
if "?" in base or "=" in base:
|
| 355 |
-
link = f"{base}{query}"
|
| 356 |
-
else:
|
| 357 |
-
link = base
|
| 358 |
-
df = pd.DataFrame([
|
| 359 |
-
{"اسم الموقع": site, "الوصف": desc, "رابط البحث": f"<a href='{link}' target='_blank'>{link}</a>"}
|
| 360 |
-
])
|
| 361 |
-
log_usage("المصادر الخارجية", query, site, 1)
|
| 362 |
-
html_table = df.to_html(escape=False, index=False, classes="styled-table")
|
| 363 |
-
return CUSTOM_CSS + f"<h3>🔗 نتائج البحث في {site}</h3>" + html_table
|
| 364 |
-
|
| 365 |
-
except Exception as e:
|
| 366 |
-
return f"<p>❌ حدث خطأ أثناء تنفيذ البحث:<br>{str(e)}</p>"
|
| 367 |
-
|
| 368 |
-
# ================== البحث في الدوريات ==================
|
| 369 |
-
JOURNALS = {
|
| 370 |
-
"Elsevier Journal Finder": {"url": "https://journalfinder.elsevier.com/", "desc": "اقتراح مجلات النشر"},
|
| 371 |
-
"Springer Journal Suggester": {"url": "https://journalsuggester.springer.com/", "desc": "اقتراح مجلات النشر"},
|
| 372 |
-
"DOAJ": {"url": "https://doaj.org/search/journals?ref=homepage-box&source=", "desc": "مجلات مفتوحة الوصول"},
|
| 373 |
-
"Journal Citation Reports": {"url": "https://jcr.clarivate.com/jcr/browse-journals?query=", "desc": "تقييم الدوريات العلمية"},
|
| 374 |
-
"Scimago": {"url": "https://www.scimagojr.com/journalsearch.php?q=", "desc": "تصنيف الدوريات"},
|
| 375 |
-
"Google Scholar": {"url": "https://scholar.google.com/scholar?q=", "desc": "بحث عام"}
|
| 376 |
-
}
|
| 377 |
-
|
| 378 |
-
def journal_search_html(query, site):
|
| 379 |
-
try:
|
| 380 |
-
if not query or not str(query).strip():
|
| 381 |
-
return "<p>⚠️ من فضلك اكتب كلمة للبحث</p>"
|
| 382 |
-
if not site or site not in JOURNALS:
|
| 383 |
-
return f"<p>⚠️ الموقع المحدد غير معروف أو غير موجود في قائمة الدوريات.</p>"
|
| 384 |
-
base = JOURNALS[site]["url"]
|
| 385 |
-
desc = JOURNALS[site]["desc"]
|
| 386 |
-
if "?" in base or "=" in base:
|
| 387 |
-
link = f"{base}{query}"
|
| 388 |
-
else:
|
| 389 |
-
link = base
|
| 390 |
-
df = pd.DataFrame([{"اسم الموقع": site, "الوصف": desc, "رابط البحث": f"<a href='{link}' target='_blank'>{link}</a>"}])
|
| 391 |
-
log_usage("الدوريات", query, site, 1)
|
| 392 |
-
html_table = df.to_html(escape=False, index=False, classes="styled-table")
|
| 393 |
-
return CUSTOM_CSS + f"<h3>📄 نتائج البحث في {site}</h3>" + html_table
|
| 394 |
-
except Exception as e:
|
| 395 |
-
return f"<p>❌ حدث خطأ أثناء تنفيذ البحث:<br>{str(e)}</p>"
|
| 396 |
-
|
| 397 |
-
# ================== أدوات الذكاء الاصطناعي ==================
|
| 398 |
-
AI_TOOLS = {
|
| 399 |
-
"Semantic Scholar": {"url": "https://www.semanticscholar.org/search?q=", "desc": "بحث أكاديمي يعتمد على الذكاء الاصطناعي"},
|
| 400 |
-
"Connected Papers": {"url": "https://www.connectedpapers.com/search?q=", "desc": "خرائط علاقات بين الأبحاث"},
|
| 401 |
-
"Research Rabbit": {"url": "https://www.researchrabbitapp.com/", "desc": "تتبع شبكات الأبحاث"},
|
| 402 |
-
"Elicit": {"url": "https://elicit.org/", "desc": "مساعد بحث علمي يستخدم AI"},
|
| 403 |
-
"Explainpaper": {"url": "https://www.explainpaper.com/", "desc": "تبسيط الأبحاث العلمية"},
|
| 404 |
-
"Consensus": {"url": "https://consensus.app/search/?q=", "desc": "إجابات سريعة مدعومة بالأدلة"}
|
| 405 |
-
}
|
| 406 |
-
|
| 407 |
-
def ai_search_html(query, site):
|
| 408 |
-
try:
|
| 409 |
-
if not query or not str(query).strip():
|
| 410 |
-
return "<p>⚠️ من فضلك اكتب كلمة للبحث</p>"
|
| 411 |
-
if not site or site not in AI_TOOLS:
|
| 412 |
-
return f"<p>⚠️ الأداة المحددة غير معروفة أو غير موجودة في القائمة.</p>"
|
| 413 |
-
base = AI_TOOLS[site]["url"]
|
| 414 |
-
desc = AI_TOOLS[site]["desc"]
|
| 415 |
-
if "?" in base or "=" in base:
|
| 416 |
-
link = f"{base}{query}"
|
| 417 |
-
else:
|
| 418 |
-
link = base
|
| 419 |
-
df = pd.DataFrame([{"اسم الأداة": site, "الوصف": desc, "رابط البحث": f"<a href='{link}' target='_blank'>{link}</a>"}])
|
| 420 |
-
log_usage("أدوات الذكاء الاصطناعي", query, site, 1)
|
| 421 |
-
html_table = df.to_html(escape=False, index=False, classes="styled-table")
|
| 422 |
-
return CUSTOM_CSS + f"<h3>🤖 نتائج البحث في {site}</h3>" + html_table
|
| 423 |
-
except Exception as e:
|
| 424 |
-
return f"<p>❌ حدث خطأ أثناء تنفيذ البحث:<br>{str(e)}</p>"
|
| 425 |
-
|
| 426 |
-
# ================== وظائف إدارة الأسئلة (CSV) ==================
|
| 427 |
-
def ensure_questions_file():
|
| 428 |
-
if not os.path.exists(QUESTIONS_FILE):
|
| 429 |
-
df = pd.DataFrame(columns=["id","name","question","answer","status","datetime"])
|
| 430 |
-
df.to_csv(QUESTIONS_FILE, index=False, encoding="utf-8-sig")
|
| 431 |
-
|
| 432 |
-
def read_questions_df():
|
| 433 |
-
ensure_questions_file()
|
| 434 |
-
try:
|
| 435 |
-
df = pd.read_csv(QUESTIONS_FILE, encoding="utf-8-sig")
|
| 436 |
-
except Exception:
|
| 437 |
-
df = pd.DataFrame(columns=["id","name","question","answer","status","datetime"])
|
| 438 |
-
return df
|
| 439 |
-
|
| 440 |
-
def save_question_to_csv(name, question):
|
| 441 |
-
ensure_questions_file()
|
| 442 |
-
df = read_questions_df()
|
| 443 |
-
if df.empty:
|
| 444 |
-
next_id = 1
|
| 445 |
-
else:
|
| 446 |
-
try:
|
| 447 |
-
next_id = int(df["id"].max()) + 1
|
| 448 |
-
except Exception:
|
| 449 |
-
next_id = len(df) + 1
|
| 450 |
-
row = {
|
| 451 |
-
"id": next_id,
|
| 452 |
-
"name": name if name and str(name).strip() else "👤 طالب مجهول",
|
| 453 |
-
"question": question,
|
| 454 |
-
"answer": "",
|
| 455 |
-
"status": "لم يتم الرد",
|
| 456 |
-
"datetime": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 457 |
-
}
|
| 458 |
-
df = pd.concat([df, pd.DataFrame([row])], ignore_index=True)
|
| 459 |
-
df.to_csv(QUESTIONS_FILE, index=False, encoding="utf-8-sig")
|
| 460 |
-
return next_id
|
| 461 |
-
|
| 462 |
-
def save_answer_to_csv(qid, answer_text):
|
| 463 |
-
ensure_questions_file()
|
| 464 |
-
df = read_questions_df()
|
| 465 |
-
if df.empty:
|
| 466 |
-
return False, "لا توجد أسئلة."
|
| 467 |
-
try:
|
| 468 |
-
qid = int(qid)
|
| 469 |
-
except Exception:
|
| 470 |
-
return False, "معرّف السؤال غير صالح."
|
| 471 |
-
if qid not in df["id"].values:
|
| 472 |
-
return False, "لم يتم إيجاد السؤال بالمعرّف المحدد."
|
| 473 |
-
df.loc[df["id"] == qid, "answer"] = answer_text
|
| 474 |
-
df.loc[df["id"] == qid, "status"] = "تم الرد"
|
| 475 |
-
df.to_csv(QUESTIONS_FILE, index=False, encoding="utf-8-sig")
|
| 476 |
-
return True, "تم حفظ الرد بنجاح."
|
| 477 |
-
|
| 478 |
-
def questions_to_html(df):
|
| 479 |
-
if df is None or df.empty:
|
| 480 |
-
return "<p>❌ لا توجد أسئلة حتى الآن.</p>"
|
| 481 |
-
html = CUSTOM_CSS + "<div style='direction:rtl;text-align:right;'>"
|
| 482 |
-
df_sorted = df.sort_values(by="id", ascending=False).reset_index(drop=True)
|
| 483 |
-
for _, row in df_sorted.iterrows():
|
| 484 |
-
name = row.get("name","👤 طالب مجهول")
|
| 485 |
-
qtext = row.get("question","")
|
| 486 |
-
answer = row.get("answer","")
|
| 487 |
-
status = row.get("status","لم يتم الرد")
|
| 488 |
-
qid = row.get("id","")
|
| 489 |
-
dt = row.get("datetime","")
|
| 490 |
-
html += f"<div class='question-card'><div class='question-meta'># {qid} — {dt} — <b>{name}</b></div>"
|
| 491 |
-
html += f"<div><b>السؤال:</b> {qtext}</div>"
|
| 492 |
-
if status == "تم الرد" and str(answer).strip():
|
| 493 |
-
html += f"<div class='answer'><b>الرد:</b> {answer} <div class='question-meta'>حالة: {status}</div></div>"
|
| 494 |
-
else:
|
| 495 |
-
html += f"<div class='answer'><i>لم يتم الرد بعد</i> <div class='question-meta'>حالة: {status}</div></div>"
|
| 496 |
-
html += "</div>"
|
| 497 |
-
html += "</div>"
|
| 498 |
-
return html
|
| 499 |
-
|
| 500 |
-
# ================== وظائف إدارة طلبات الاستعارة (أعضاء هيئة التدريس) ==================
|
| 501 |
-
def ensure_faculty_file():
|
| 502 |
-
if not os.path.exists(FACULTY_BORROW_FILE):
|
| 503 |
-
df = pd.DataFrame(columns=["id","name","phone","nid","email","position","birthdate","status","datetime"])
|
| 504 |
-
df.to_csv(FACULTY_BORROW_FILE, index=False, encoding="utf-8-sig")
|
| 505 |
-
|
| 506 |
-
def read_faculty_df():
|
| 507 |
-
ensure_faculty_file()
|
| 508 |
-
try:
|
| 509 |
-
df = pd.read_csv(FACULTY_BORROW_FILE, encoding="utf-8-sig")
|
| 510 |
-
except Exception:
|
| 511 |
-
df = pd.DataFrame(columns=["id","name","phone","nid","email","position","birthdate","status","datetime"])
|
| 512 |
-
return df
|
| 513 |
-
|
| 514 |
-
def save_faculty_request(name, phone, nid, email, position, birthdate):
|
| 515 |
-
ensure_faculty_file()
|
| 516 |
-
df = read_faculty_df()
|
| 517 |
-
if df.empty:
|
| 518 |
-
next_id = 1
|
| 519 |
-
else:
|
| 520 |
-
try:
|
| 521 |
-
next_id = int(df["id"].max()) + 1
|
| 522 |
-
except Exception:
|
| 523 |
-
next_id = len(df) + 1
|
| 524 |
-
row = {
|
| 525 |
-
"id": next_id,
|
| 526 |
-
"name": name,
|
| 527 |
-
"phone": phone,
|
| 528 |
-
"nid": nid,
|
| 529 |
-
"email": email,
|
| 530 |
-
"position": position,
|
| 531 |
-
"birthdate": birthdate,
|
| 532 |
-
"status": "قيد المراجعة",
|
| 533 |
-
"datetime": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 534 |
-
}
|
| 535 |
-
df = pd.concat([df, pd.DataFrame([row])], ignore_index=True)
|
| 536 |
-
df.to_csv(FACULTY_BORROW_FILE, index=False, encoding="utf-8-sig")
|
| 537 |
-
return next_id
|
| 538 |
-
|
| 539 |
-
# ================== واجهة Gradio ==================
|
| 540 |
-
with gr.Blocks() as demo:
|
| 541 |
-
with gr.Tab("📚 عن المكتبة"):
|
| 542 |
-
with gr.Tabs():
|
| 543 |
-
with gr.Tab("🌟 رؤية المكتبة"):
|
| 544 |
-
gr.Markdown("تسعى المكتبة إلى أن تكون مركزًا معرفيًا متميزًا يدعم البحث والتعليم ويُسهم في بناء مجتمع المعرفة.")
|
| 545 |
-
with gr.Tab("🎯 رسالة المكتبة"):
|
| 546 |
-
gr.Markdown("تقديم خدمات معلوماتية متكاملة تُمكّن الباحثين والطلاب من الوصول إلى مصادر المعرفة بسهولة وكفاءة.")
|
| 547 |
-
with gr.Tab("🎯 أهداف المكتبة"):
|
| 548 |
-
gr.Markdown("- دعم العملية التعليمية والبحثية.\n- تيسير الوصول إلى المعلومات والمصادر العلمية.\n- تشجيع استخدام التقنيات الحديثة في البحث.\n- تعزيز ثقافة القراءة والتعلم الذاتي.")
|
| 549 |
-
with gr.Tab("🧩 الخدمات"):
|
| 550 |
-
with gr.Tabs():
|
| 551 |
-
with gr.Tab("📘 الإحاطة الجارية"):
|
| 552 |
-
gr.Markdown("خدمة تتيح للباحثين متابعة أحدث الإصدارات والموضوعات الجديدة في مجالات اهتمامهم.")
|
| 553 |
-
with gr.Tab("🔗 التسجيل في بنك المعرفة"):
|
| 554 |
-
gr.Markdown("يرجى ملء البيانات التالية للتسجيل في بنك المعرفة المصري:")
|
| 555 |
-
|
| 556 |
-
name = gr.Textbox(label="الاسم بالكامل", placeholder="اكتب اسمك الثلاثي هنا")
|
| 557 |
-
nid = gr.Textbox(label="رقم البطاقة", placeholder="14 رقمًا")
|
| 558 |
-
birth = gr.Textbox(label="تاريخ الميلاد", placeholder="مثال: 1999-05-12")
|
| 559 |
-
email = gr.Textbox(label="الإيميل الجامعي", placeholder="example@university.edu.eg")
|
| 560 |
-
phone = gr.Textbox(label="رقم التليفون", placeholder="010XXXXXXXXX")
|
| 561 |
-
submit_btn = gr.Button("إرسال الطلب")
|
| 562 |
-
output_msg = gr.HTML()
|
| 563 |
-
|
| 564 |
-
def save_registration(name, nid, birth, email, phone):
|
| 565 |
-
import csv, os
|
| 566 |
-
from datetime import datetime
|
| 567 |
-
file_path = "bank_requests.csv"
|
| 568 |
-
file_exists = os.path.exists(file_path)
|
| 569 |
-
with open(file_path, mode="a", newline="", encoding="utf-8") as f:
|
| 570 |
-
writer = csv.writer(f)
|
| 571 |
-
if not file_exists:
|
| 572 |
-
writer.writerow(["الاسم", "رقم البطاقة", "تاريخ الميلاد", "الإيميل الجامعي", "رقم التليفون", "تاريخ التسجيل"])
|
| 573 |
-
writer.writerow([name, nid, birth, email, phone, datetime.now().strftime("%Y-%m-%d %H:%M:%S")])
|
| 574 |
-
return "<b style='color:green;'>✅ تم استلام بياناتك بنجاح، يرجى مراجعة بريدك الجامعي خلال 24 ساعة.</b>"
|
| 575 |
-
|
| 576 |
-
submit_btn.click(save_registration, inputs=[name, nid, birth, email, phone], outputs=output_msg)
|
| 577 |
-
|
| 578 |
-
with gr.Tab("🖨️ التصوير"):
|
| 579 |
-
gr.Markdown("توفر المكتبة خدمة تصوير المواد العلمية وفق القواعد المعمول بها داخل المكتبة.")
|
| 580 |
-
with gr.Tab("🔍 البحث الإلكتروني"):
|
| 581 |
-
gr.Markdown("يمكن للباحثين استخدام أجهزة المكتبة للبحث في قواعد البيانات الإلكترونية والمصادر العلمية.")
|
| 582 |
-
with gr.Tab("📖 الاطلاع الداخلي"):
|
| 583 |
-
gr.Markdown("تتيح المكتبة للرواد قراءة الكتب والمراجع داخل القاعات المخصصة دون الحاجة إلى استعارتها خارجًا.")
|
| 584 |
-
# ------------------ تبويب الاستعارة الخارجية (معدّل) ------------------
|
| 585 |
-
with gr.Tab("📚 الاستعارة الخارجية"):
|
| 586 |
-
gr.Markdown("""
|
| 587 |
-
تقدّم المكتبة خدمة الاستعارة الخارجية للكتب تبعًا لعدد النسخ، حيث أنه غير مسموح بالاستعارة الخارجية للكتب والمراجع ذات النسخة الواحدة أو ذات الطابع الخاص أو الدوريات أو الرسائل العلمية.
|
| 588 |
-
""")
|
| 589 |
-
with gr.Tabs():
|
| 590 |
-
with gr.Tab("📌 الاستعارة للطلاب"):
|
| 591 |
-
gr.Markdown("""
|
| 592 |
-
📌 يستخرج الطالب استمارة الاستعارة عن طريق ملء استمارة ضمان يقوم بختمها من شؤون الطلاب،
|
| 593 |
-
مع ختمها بختم النسر الخاص بالجهة الحكومية التابع لها الضامن.
|
| 594 |
-
""")
|
| 595 |
-
# ملفات الـ PDF للتحميل — اسماء الملفات كما أكدتِ: "استمارة 1" و "استمارة2"
|
| 596 |
-
# نتوقع وجود الملفات الفعلية في مجلد المشروع مع الامتداد .pdf
|
| 597 |
-
form1_path = "استمارة 1.pdf"
|
| 598 |
-
form2_path = "استمارة2.pdf"
|
| 599 |
-
|
| 600 |
-
def get_form1():
|
| 601 |
-
if os.path.exists(form1_path):
|
| 602 |
-
return form1_path
|
| 603 |
-
return None
|
| 604 |
-
def get_form2():
|
| 605 |
-
if os.path.exists(form2_path):
|
| 606 |
-
return form2_path
|
| 607 |
-
return None
|
| 608 |
-
|
| 609 |
-
btn_get_form1 = gr.Button("📄 استمارة 1")
|
| 610 |
-
btn_get_form2 = gr.Button("📄 استمارة2")
|
| 611 |
-
file_out_1 = gr.File(label="تحميل استمارة 1", visible=False)
|
| 612 |
-
file_out_2 = gr.File(label="تحميل استمارة2", visible=False)
|
| 613 |
-
|
| 614 |
-
btn_get_form1.click(get_form1, outputs=file_out_1)
|
| 615 |
-
btn_get_form2.click(get_form2, outputs=file_out_2)
|
| 616 |
-
|
| 617 |
-
with gr.Tab("📌 الاستعارة لأعضاء هيئة التدريس"):
|
| 618 |
-
gr.Markdown("أعضاء هيئة التدريس يرجى تعبئة البيانات التالية لطلب الاستعارة:")
|
| 619 |
-
fac_name = gr.Textbox(label="الاسم", placeholder="الاسم الكامل")
|
| 620 |
-
fac_phone = gr.Textbox(label="رقم التليفون", placeholder="010XXXXXXXX")
|
| 621 |
-
fac_nid = gr.Textbox(label="رقم البطاقة", placeholder="14 رقمًا")
|
| 622 |
-
fac_email = gr.Textbox(label="الإيميل الجامعي", placeholder="example@university.edu.eg")
|
| 623 |
-
fac_position = gr.Textbox(label="التوصيف الوظيفي", placeholder="مثال: أستاذ مساعد – قسم الصيدلة")
|
| 624 |
-
fac_birth = gr.Textbox(label="تاريخ الميلاد", placeholder="مثال: 1980-05-12")
|
| 625 |
-
fac_submit = gr.Button("إرسال الطلب")
|
| 626 |
-
fac_msg = gr.Markdown("")
|
| 627 |
-
|
| 628 |
-
def submit_faculty_request(name, phone, nid, email, position, birthdate):
|
| 629 |
-
if not name or not str(name).strip():
|
| 630 |
-
return "<b style='color:red;'>الاسم مطلوب.</b>"
|
| 631 |
-
if not phone or not str(phone).strip():
|
| 632 |
-
return "<b style='color:red;'>رقم التليفون مطلوب.</b>"
|
| 633 |
-
if not nid or not str(nid).strip():
|
| 634 |
-
return "<b style='color:red;'>رقم البطاقة مطلوب.</b>"
|
| 635 |
-
if not email or not str(email).strip():
|
| 636 |
-
return "<b style='color:red;'>الإيميل الجامعي مطلوب.</b>"
|
| 637 |
-
# حفظ البيانات
|
| 638 |
-
qid = save_faculty_request(name, phone, nid, email, position, birthdate)
|
| 639 |
-
return f"✅ تم إرسال طلب الاستعارة (#{qid}) وسيتم مراجعته."
|
| 640 |
-
|
| 641 |
-
fac_submit.click(submit_faculty_request, inputs=[fac_name, fac_phone, fac_nid, fac_email, fac_position, fac_birth], outputs=fac_msg)
|
| 642 |
-
|
| 643 |
-
with gr.Tab("🔎 البحث المحلي"):
|
| 644 |
-
query_local = gr.Textbox(label="اكتب كلمة البحث")
|
| 645 |
-
category = gr.Radio(["Books", "Theses"], label="اختر الفئة")
|
| 646 |
-
mode = gr.Radio(["نصي", "دلالي (Semantic)"], label="نوع البحث")
|
| 647 |
-
btn_local = gr.Button("بحث")
|
| 648 |
-
|
| 649 |
-
df_local_state = gr.State()
|
| 650 |
-
output_local_html = gr.HTML()
|
| 651 |
-
file_local = gr.File(label="⬇️ تحميل النتائج", visible=False)
|
| 652 |
-
|
| 653 |
-
btn_local.click(
|
| 654 |
-
local_search_df,
|
| 655 |
-
inputs=[query_local, category, mode],
|
| 656 |
-
outputs=[output_local_html, df_local_state]
|
| 657 |
-
)
|
| 658 |
-
|
| 659 |
-
btn_save_local = gr.Button("📥 حفظ النتائج")
|
| 660 |
-
btn_save_local.click(
|
| 661 |
-
save_to_excel,
|
| 662 |
-
inputs=df_local_state,
|
| 663 |
-
outputs=file_local
|
| 664 |
-
)
|
| 665 |
-
|
| 666 |
-
file_local.change(lambda x: gr.update(visible=True), inputs=file_local, outputs=file_local)
|
| 667 |
-
|
| 668 |
-
with gr.Tab("🌐 المصادر الخارجية"):
|
| 669 |
-
query_ext = gr.Textbox(label="كلمة البحث")
|
| 670 |
-
site_ext = gr.Dropdown(list(EXTERNAL_LINKS.keys()), label="اختر الموقع")
|
| 671 |
-
btn_ext = gr.Button("بحث")
|
| 672 |
-
output_ext = gr.HTML()
|
| 673 |
-
btn_ext.click(external_search_html, inputs=[query_ext, site_ext], outputs=output_ext)
|
| 674 |
-
|
| 675 |
-
with gr.Tab("📄 الدوريات"):
|
| 676 |
-
query_jour = gr.Textbox(label="كلمة البحث")
|
| 677 |
-
site_jour = gr.Dropdown(list(JOURNALS.keys()), label="اختر الموقع")
|
| 678 |
-
btn_jour = gr.Button("بحث")
|
| 679 |
-
output_jour = gr.HTML()
|
| 680 |
-
btn_jour.click(journal_search_html, inputs=[query_jour, site_jour], outputs=output_jour)
|
| 681 |
-
|
| 682 |
-
with gr.Tab("🤖 أدوات الذكاء الاصطناعي"):
|
| 683 |
-
query_ai = gr.Textbox(label="كلمة البحث")
|
| 684 |
-
site_ai = gr.Dropdown(list(AI_TOOLS.keys()), label="اختر الأداة")
|
| 685 |
-
btn_ai = gr.Button("بحث")
|
| 686 |
-
output_ai = gr.HTML()
|
| 687 |
-
btn_ai.click(ai_search_html, inputs=[query_ai, site_ai], outputs=output_ai)
|
| 688 |
-
|
| 689 |
-
with gr.Tab("📑 برامج إدارة المراجع"):
|
| 690 |
-
gr.Markdown("ℹ️ **تنويه:** هذه البرامج تحتاج تنزيل أو تثبيت الإضافات الخاصة بها.")
|
| 691 |
-
gr.Markdown("### • **Mendeley** \n🔗 [زيارة الموقع](https://www.mendeley.com/)")
|
| 692 |
-
gr.Markdown("### • **Zotero** \n🔗 [زيارة الموقع](https://www.zotero.org/)")
|
| 693 |
-
gr.Markdown("### • **EndNote** \n🔗 [زيارة الموقع](https://endnote.com/)")
|
| 694 |
-
|
| 695 |
-
with gr.Tab("💬 المساعد الذكي"):
|
| 696 |
-
q_faq = gr.Textbox(label="اسأل مساعد المكتبة")
|
| 697 |
-
ans_faq = gr.HTML()
|
| 698 |
-
btn_faq = gr.Button("إجابة")
|
| 699 |
-
btn_faq.click(library_assistant_smart, inputs=q_faq, outputs=ans_faq)
|
| 700 |
-
|
| 701 |
-
with gr.Tab("📊 الإحصاءات"):
|
| 702 |
-
stats_html = gr.HTML()
|
| 703 |
-
btn_stats = gr.Button("عرض الإحصاءات")
|
| 704 |
-
btn_stats.click(lambda: show_usage_stats(), outputs=stats_html)
|
| 705 |
-
|
| 706 |
-
# -------------------- تبويب "📞 تواصل معنا" المضاف سابقًا --------------------
|
| 707 |
-
with gr.Tab("📞 تواصل معنا"):
|
| 708 |
-
|
| 709 |
-
gr.Markdown("""
|
| 710 |
-
## 📞 تواصل معنا
|
| 711 |
-
|
| 712 |
-
يسعدنا تواصلك مع **مكتبة كلية الصيدلة – جامعة المنصورة** عبر القنوات التالية:
|
| 713 |
-
|
| 714 |
-
📍 **العنوان:** الدور الرابع – المبنى الإداري – كلية الصيدلة – جامعة المنصورة
|
| 715 |
-
📧 **البريد الإلكتروني:** [phrlib1@mans.edu.eg](mailto:phrlib1@mans.edu.eg)
|
| 716 |
-
📞 **الهاتف:** 01066937446
|
| 717 |
-
""")
|
| 718 |
-
|
| 719 |
-
fb_link = "https://www.facebook.com/people/%D9%85%D9%83%D8%AA%D8%A8%D8%A9-%D9%83%D9%84%D9%8A%D8%A9-%D8%A7%D9%84%D8%B5%D9%8A%D8%AF%D9%84%D8%A9-%D8%AC%D8%A7%D9%85%D8%B9%D8%A9-%D8%A7%D9%84%D9%85%D9%86%D8%B5%D9%88%D8%B1%D8%A9/61554318849433/"
|
| 720 |
-
whatsapp_link = "https://wa.me/201066937446"
|
| 721 |
-
email_link = "mailto:phrlib1@mans.edu.eg"
|
| 722 |
-
|
| 723 |
-
gr.Markdown("### 🌐 قنوات التواصل السريعة:")
|
| 724 |
-
|
| 725 |
-
gr.HTML(f"""
|
| 726 |
-
<div style='display:flex; gap:10px; flex-wrap:wrap;'>
|
| 727 |
-
<a href='{fb_link}' target='_blank'>
|
| 728 |
-
<button style='background-color:#1877f2;color:white;padding:10px 18px;border:none;border-radius:8px;font-size:16px;cursor:pointer;'>Facebook</button>
|
| 729 |
-
</a>
|
| 730 |
-
<a href='{whatsapp_link}' target='_blank'>
|
| 731 |
-
<button style='background-color:#25d366;color:white;padding:10px 18px;border:none;border-radius:8px;font-size:16px;cursor:pointer;'>WhatsApp</button>
|
| 732 |
-
</a>
|
| 733 |
-
<a href='{email_link}' target='_blank'>
|
| 734 |
-
<button style='background-color:#444;color:white;padding:10px 18px;border:none;border-radius:8px;font-size:16px;cursor:pointer;'>Email</button>
|
| 735 |
-
</a>
|
| 736 |
-
</div>
|
| 737 |
-
""")
|
| 738 |
-
|
| 739 |
-
gr.Markdown("### 💬 أرسل رسالة إلى المكتبة:")
|
| 740 |
-
|
| 741 |
-
name_c = gr.Textbox(label="الاسم الكامل", placeholder="اكتب اسمك هنا")
|
| 742 |
-
email_c = gr.Textbox(label="البريد الإلكتروني", placeholder="example@domain.com")
|
| 743 |
-
message_c = gr.Textbox(label="الرسالة", lines=4, placeholder="اكتب رسالتك هنا...")
|
| 744 |
-
send_btn = gr.Button("📨 إرسال الرسالة")
|
| 745 |
-
result_msg = gr.Markdown("")
|
| 746 |
-
|
| 747 |
-
def save_contact(name, email, message):
|
| 748 |
-
import csv, os
|
| 749 |
-
file_path = "contact_messages.csv"
|
| 750 |
-
file_exists = os.path.exists(file_path)
|
| 751 |
-
with open(file_path, mode="a", newline="", encoding="utf-8") as f:
|
| 752 |
-
writer = csv.writer(f)
|
| 753 |
-
if not file_exists:
|
| 754 |
-
writer.writerow(["الاسم", "البريد الإلكتروني", "الرسالة"])
|
| 755 |
-
writer.writerow([name, email, message])
|
| 756 |
-
return "✅ تم إرسال رسالتك بنجاح، شكرًا لتواصلك معنا."
|
| 757 |
-
|
| 758 |
-
send_btn.click(save_contact, inputs=[name_c, email_c, message_c], outputs=result_msg)
|
| 759 |
-
|
| 760 |
-
# -------------------- تبويب "❓ اسأل أخصائي المكتبة" (التبويب الجديد للطلاب) --------------------
|
| 761 |
-
with gr.Tab("❓ اسأل أخصائي المكتبة"):
|
| 762 |
-
gr.Markdown("### اسأل أخصائي المكتبة\nاكتب سؤالك وسيظهر في نظام المكتبة ليرد عليه الأخصائي لاحقًا.")
|
| 763 |
-
student_name = gr.Textbox(label="الاسم (اختياري)", placeholder="يمكن تركه فارغًا")
|
| 764 |
-
student_question = gr.Textbox(label="السؤال", lines=4, placeholder="اكتب سؤالك هنا...", interactive=True)
|
| 765 |
-
student_send = gr.Button("إرسال السؤال")
|
| 766 |
-
student_result = gr.Markdown("")
|
| 767 |
-
student_questions_html = gr.HTML()
|
| 768 |
-
|
| 769 |
-
def load_questions_html():
|
| 770 |
-
df = read_questions_df()
|
| 771 |
-
return questions_to_html(df)
|
| 772 |
-
|
| 773 |
-
def student_submit_question(name, question):
|
| 774 |
-
if not question or not str(question).strip():
|
| 775 |
-
return "⚠️ اكتب سؤالك قبل الإرسال.", questions_to_html(read_questions_df())
|
| 776 |
-
qid = save_question_to_csv(name, question)
|
| 777 |
-
df = read_questions_df()
|
| 778 |
-
return f"✅ تم إرسال سؤالك (#{qid})، سنقوم بالرد في أقرب وقت ممكن.", questions_to_html(df)
|
| 779 |
-
|
| 780 |
-
student_send.click(student_submit_question, inputs=[student_name, student_question], outputs=[student_result, student_questions_html])
|
| 781 |
-
btn_load_questions = gr.Button("تحديث عرض الأسئلة")
|
| 782 |
-
btn_load_questions.click(lambda: load_questions_html(), outputs=student_questions_html)
|
| 783 |
-
|
| 784 |
-
# -------------------- 📂 تبويب إدارة خدمات المكتبة --------------------
|
| 785 |
-
with gr.Tab("📂 إدارة خدمات المكتبة"):
|
| 786 |
-
gr.Markdown("### 🔐 تسجيل الدخول لإدارة خدمات المكتبة")
|
| 787 |
-
|
| 788 |
-
password = gr.Textbox(label="كلمة المرور", type="password", placeholder="أدخل كلمة المرور هنا")
|
| 789 |
-
login_btn = gr.Button("دخول")
|
| 790 |
-
login_msg = gr.Markdown("")
|
| 791 |
-
admin_area = gr.Group(visible=False)
|
| 792 |
-
|
| 793 |
-
with admin_area:
|
| 794 |
-
gr.Markdown("### عرض طلبات التسجيل في بنك المعرفة")
|
| 795 |
-
|
| 796 |
-
refresh_btn = gr.Button("🔄 تحديث البيانات")
|
| 797 |
-
data_table = gr.Dataframe(headers=["الاسم", "رقم البطاقة", "تاريخ الميلاد", "الإيميل الجامعي", "رقم التليفون", "تاريخ التسجيل"], interactive=False)
|
| 798 |
-
download_btn = gr.Button("⬇️ تنزيل الطلبات كملف Excel")
|
| 799 |
-
download_file = gr.File(label="ملف Excel", visible=False)
|
| 800 |
-
|
| 801 |
-
import pandas as pd, os, tempfile
|
| 802 |
-
|
| 803 |
-
def check_password(pw):
|
| 804 |
-
correct_pw = "admin123" # ← يمكنك تغييرها إلى أي كلمة مرور تريدينها
|
| 805 |
-
if pw == correct_pw:
|
| 806 |
-
return gr.update(visible=True), "✅ تم تسجيل الدخول بنجاح."
|
| 807 |
-
else:
|
| 808 |
-
return gr.update(visible=False), "❌ كلمة المرور غير صحيحة."
|
| 809 |
-
|
| 810 |
-
login_btn.click(check_password, inputs=password, outputs=[admin_area, login_msg])
|
| 811 |
-
|
| 812 |
-
def load_requests():
|
| 813 |
-
file_path = "bank_requests.csv"
|
| 814 |
-
if not os.path.exists(file_path):
|
| 815 |
-
return pd.DataFrame(columns=["الاسم", "رقم البطاقة", "تاريخ الميلاد", "الإيميل الجامعي", "رقم التليفون", "تاريخ التسجيل"])
|
| 816 |
-
df = pd.read_csv(file_path)
|
| 817 |
-
return df
|
| 818 |
-
|
| 819 |
-
def export_excel(df):
|
| 820 |
-
if df is None or df.empty:
|
| 821 |
-
return gr.update(visible=False)
|
| 822 |
-
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx")
|
| 823 |
-
df.to_excel(tmp.name, index=False)
|
| 824 |
-
return gr.update(value=tmp.name, visible=True)
|
| 825 |
-
|
| 826 |
-
refresh_btn.click(load_requests, outputs=data_table)
|
| 827 |
-
download_btn.click(export_excel, inputs=data_table, outputs=download_file)
|
| 828 |
-
|
| 829 |
-
# -------------------- قسم إدارة الأسئلة داخل منطقة الإدارة --------------------
|
| 830 |
-
with admin_area:
|
| 831 |
-
gr.Markdown("### 🛠️ إدارة الأسئلة")
|
| 832 |
-
admin_refresh_q = gr.Button("🔄 تحديث الأسئلة")
|
| 833 |
-
admin_questions_df = gr.Dataframe(headers=["id","name","question","answer","status","datetime"], interactive=False)
|
| 834 |
-
admin_select_q = gr.Dropdown(choices=[], label="اختر رقم السؤال للرد عليه (ID)", value=None)
|
| 835 |
-
admin_answer_box = gr.Textbox(label="اكتب الرد هنا", lines=3, placeholder="أدخل رد الأخصائي...")
|
| 836 |
-
admin_save_answer_btn = gr.Button("حفظ الرد")
|
| 837 |
-
admin_msg = gr.Markdown("")
|
| 838 |
-
admin_export_btn = gr.Button("⬇️ تنزيل الأسئلة كملف Excel")
|
| 839 |
-
admin_export_file = gr.File(label="ملف الأسئلة", visible=False)
|
| 840 |
-
|
| 841 |
-
def admin_load_questions():
|
| 842 |
-
df = read_questions_df()
|
| 843 |
-
if df is None or df.empty:
|
| 844 |
-
df_show = pd.DataFrame(columns=["id","name","question","answer","status","datetime"])
|
| 845 |
-
else:
|
| 846 |
-
df_show = df.sort_values(by="id", ascending=False)
|
| 847 |
-
choices = df_show["id"].astype(str).tolist() if not df_show.empty else []
|
| 848 |
-
return df_show, gr.update(choices=choices, value=choices[0] if choices else None)
|
| 849 |
-
|
| 850 |
-
def admin_save_answer(qid, answer_text):
|
| 851 |
-
success, msg = save_answer_to_csv(qid, answer_text)
|
| 852 |
-
if not success:
|
| 853 |
-
return "❌ " + msg, admin_load_questions()[0]
|
| 854 |
-
df_show, dd_update = admin_load_questions()
|
| 855 |
-
return "✅ تم حفظ الرد.", df_show
|
| 856 |
-
|
| 857 |
-
def admin_export_questions():
|
| 858 |
-
df = read_questions_df()
|
| 859 |
-
if df is None or df.empty:
|
| 860 |
-
return gr.update(visible=False)
|
| 861 |
-
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx")
|
| 862 |
-
df.to_excel(tmp.name, index=False)
|
| 863 |
-
return gr.update(value=tmp.name, visible=True)
|
| 864 |
-
|
| 865 |
-
admin_refresh_q.click(lambda: admin_load_questions()[0], outputs=admin_questions_df)
|
| 866 |
-
admin_refresh_q.click(lambda: admin_load_questions()[1], outputs=admin_select_q)
|
| 867 |
-
admin_save_answer_btn.click(admin_save_answer, inputs=[admin_select_q, admin_answer_box], outputs=[admin_msg, admin_questions_df])
|
| 868 |
-
admin_export_btn.click(admin_export_questions, outputs=admin_export_file)
|
| 869 |
-
|
| 870 |
-
# -------------------- قسم إدارة طلبات الاستعارة لأعضاء هيئة التدريس --------------------
|
| 871 |
-
with admin_area:
|
| 872 |
-
gr.Markdown("### 🗂️ إدارة طلبات الاستعارة (أعضاء هيئة التدريس)")
|
| 873 |
-
admin_refresh_fac = gr.Button("🔄 تحديث طلبات الاستعارة")
|
| 874 |
-
admin_fac_df = gr.Dataframe(headers=["id","name","phone","nid","email","position","birthdate","status","datetime"], interactive=False)
|
| 875 |
-
admin_export_fac_btn = gr.Button("⬇️ تنزيل طلبات الاستعارة كملف Excel")
|
| 876 |
-
admin_export_fac_file = gr.File(label="ملف طلبات الاستعارة", visible=False)
|
| 877 |
-
|
| 878 |
-
def admin_load_faculty():
|
| 879 |
-
df = read_faculty_df()
|
| 880 |
-
if df is None or df.empty:
|
| 881 |
-
df_show = pd.DataFrame(columns=["id","name","phone","nid","email","position","birthdate","status","datetime"])
|
| 882 |
-
else:
|
| 883 |
-
df_show = df.sort_values(by="id", ascending=False)
|
| 884 |
-
return df_show
|
| 885 |
-
|
| 886 |
-
def admin_export_faculty():
|
| 887 |
-
df = read_faculty_df()
|
| 888 |
-
if df is None or df.empty:
|
| 889 |
-
return gr.update(visible=False)
|
| 890 |
-
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx")
|
| 891 |
-
df.to_excel(tmp.name, index=False)
|
| 892 |
-
return gr.update(value=tmp.name, visible=True)
|
| 893 |
-
|
| 894 |
-
admin_refresh_fac.click(lambda: admin_load_faculty(), outputs=admin_fac_df)
|
| 895 |
-
admin_export_fac_btn.click(admin_export_faculty, outputs=admin_export_fac_file)
|
| 896 |
-
|
| 897 |
-
gr.Markdown("---\n📌 *المشروع أعدته eman anter*")
|
| 898 |
-
|
| 899 |
-
# تشغيل التطبيق
|
| 900 |
-
if __name__ == "__main__":
|
| 901 |
-
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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