Spaces:
Sleeping
Sleeping
Update app.py
Browse files3 unmodified lines4567891024 unmodified lines3536373839404142434445464748495051415253545556445758596061626364656667686970717273747576777879808182838485868788899046474849505152535455919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131575813260133134135136137651381391401417014214314414514614714814915015115215315477155156157808182831581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272283 unmodified linesfrom datetime import datetimeimport osimport jsonimport random
# 1. إعداد الواجهة (كودك الأصلي)st.set_page_config(page_title="تطبيق فرصة عمل", layout="centered")24 unmodified lines
if 'account_created' not in st.session_state: st.session_state.account_created = Falseif 'otp_sent' not in st.session_state: st.session_state.otp_sent = Falseif 'otp_code' not in st.session_state: st.session_state.otp_code = Noneif 'contact' not in st.session_state: st.session_state.contact = ""if 'submitted' not in st.session_state: st.session_state.submitted = Falseif 'user_profile' not in st.session_state: st.session_state.user_profile = {}
def main(): if not st.session_state.account_created: show_signup_page() else: elif not st.session_state.submitted: show_questions_page() else: show_jobs_page()
# --- الصفحة الأولى: إنشاء حساب جديد (مباشرة) ---# --- قاعدة بيانات وهمية لفرص العمل ---JOB_DATABASE = [ {"title": "مطور برمجيات", "type": "خريج", "major": "تقنية معلومات", "location": "الرياض"}, {"title": "مهندس مدني", "type": "خريج", "major": "هندسة", "location": "جدة"}, {"title": "محاسب", "type": "خريج", "major": "إدارة وأقتصاد", "location": "الرياض"}, {"title": "مستشار قانوني", "type": "خريج", "major": "قانون", "location": "الدمام"}, {"title": "مترجم", "type": "خريج", "major": "لغات", "location": "الرياض"}, {"title": "موظف إداري", "type": "خريج", "major": "أخرى", "location": "جدة"}, {"title": "حلاق", "type": "عامل", "work_type": "حلاق", "location": "الرياض"}, {"title": "كاشير", "type": "عامل", "work_type": "كاشير", "location": "جدة"}, {"title": "عامل بناء", "type": "عامل", "work_type": "عامل بناء", "location": "الدمام"}, {"title": "خباز", "type": "عامل", "work_type": "خباز", "location": "الرياض"}, {"title": "نجار", "type": "عامل", "work_type": "نجار", "location": "جدة"}, {"title": "عامل عام", "type": "عامل", "work_type": "عامل", "location": "الرياض"},]
def find_matching_jobs(profile): matches = [] for job in JOB_DATABASE: if job["type"] != profile.get("job_status"): continue if profile.get("job_status") == "خريج": if job.get("major") == profile.get("major") or job.get("major") == "أخرى": matches.append(job) else: if job.get("work_type") == profile.get("work_type") or job.get("work_type") == "عامل": matches.append(job) # إذا لم يوجد تطابق دقيق، أعد كل وظائف نفس النوع if not matches: matches = [j for j in JOB_DATABASE if j["type"] == profile.get("job_status")] return matches[:5]
# --- الصفحة الأولى: ابحث عن وظيفتك (مع OTP) ---def show_signup_page(): st.markdown("<h1 style='text-align: center;'>إنشاء حساب جديد</h1>", unsafe_allow_html=True) email = st.text_input("البريد الإلكتروني / الرقم") password = st.text_input("كلمة المرور", type="password") if st.button("إنشاء الحساب والانتقال للأسئلة"): if email and password: # خزن الحساب في Firebase db.collection("users").add({"email": email, "password": password, "date": datetime.now()}) st.session_state.account_created = True st.markdown("<h1 style='text-align: center;'>ابحث عن وظيفتك</h1>", unsafe_allow_html=True)
contact = st.text_input("البريد الإلكتروني / رقم الجوال", value=st.session_state.contact)
if not st.session_state.otp_sent: if st.button("إرسال كود التحقق"): if contact: st.session_state.contact = contact code = str(random.randint(1000, 9999)) st.session_state.otp_code = code st.session_state.otp_sent = True # في التطبيق الحقيقي: أرسل الكود عبر SMS أو Email # هنا نعرضه مؤقتاً للاختبار st.info(f"📨 تم إرسال كود التحقق (للاختبار: **{code}**)") st.rerun() else: st.warning("رجاءً أدخل البريد الإلكتروني أو رقم الجوال") else: st.info(f"📨 تم إرسال كود التحقق إلى: {st.session_state.contact}") st.caption(f"(للاختبار، الكود هو: {st.session_state.otp_code})")
otp_input = st.text_input("أدخل كود التحقق")
if st.button("تأكيد الكود والمتابعة"): if otp_input == st.session_state.otp_code: try: db.collection("users").add({ "contact": st.session_state.contact, "date": datetime.now() }) except Exception: pass st.session_state.account_created = True st.rerun() else: st.error("الكود غير صحيح، يرجى المحاولة مرة أخرى")
if st.button("تغيير رقم الجوال / البريد"): st.session_state.otp_sent = False st.session_state.otp_code = None st.rerun() else: st.warning("رجاءً أدخل المعلومات المطلوبة")
# --- الصفحة الثانية: الأسئلة المطلوبة ---# --- الصفحة الثانية: الأسئلة ---def show_questions_page(): st.markdown("<h2 style='text-align: center;'>إكمال معلومات التقديم</h2>", unsafe_allow_html=True)
with st.form("info_form"): # الأسئلة اللي طلبتها بالضبط name = st.text_input("الاسم") gender = st.radio("الجنس", ["ذكر", "أنثى"], horizontal=True) age = st.number_input("العمر", min_value=18, max_value=65) job_status = st.radio("الحالة", ["خريج", "عامل"], horizontal=True)
# --- إصلاح مشكلة ظهور الحقول --- job_title = "" major = "" edu = "" work_type = ""
if job_status == "خريج": job_title = st.text_input("المسمى الوظيفي") major = st.selectbox("التخصص", ["إدارة وأقتصاد", "هندسة", "تقنية معلومات", "قانون", "لغات", "أخرى"]) else: edu = st.selectbox("التحصيل الدراسي", ["امي", "ابتدائيه", "متوسطه", "اعداديه"]) work_type = st.selectbox("المهنة", ["عامل", "حلاق", "كاشير", "عامل بناء", "خباز", "نجار", "أخرى"])
location = st.text_input("الموقع (السكن)") st.write("📍 سيتم توصيلك بأقرب فرص العمل المتوفرة لموقعك.") if st.form_submit_button("إرسال التقديم"): st.success("تم إرسال معلوماتك بنجاح! التطبيق الآن متصل أونلاين لجلب الإعلانات.") st.balloons()
submitted = st.form_submit_button("إرسال التقديم")
if submitted: if not name or not location: st.warning("رجاءً أكمل جميع الحقول المطلوبة") else: profile = { "name": name, "gender": gender, "age": int(age), "job_status": job_status, "location": location, } if job_status == "خريج": profile["job_title"] = job_title profile["major"] = major else: profile["edu"] = edu profile["work_type"] = work_type
try: db.collection("applications").add({**profile, "date": datetime.now()}) except Exception: pass
st.session_state.user_profile = profile st.session_state.submitted = True st.rerun()
if st.button("رجوع"): st.session_state.account_created = False st.session_state.otp_sent = False st.session_state.otp_code = None st.rerun()
# --- الصفحة الثالثة: فرص العمل المناسبة ---def show_jobs_page(): profile = st.session_state.user_profile st.success("✅ تم إرسال معلوماتك بنجاح!") st.balloons()
st.markdown(f"<h2 style='text-align: center;'>فرص العمل المتاحة لك يا {profile.get('name', '')}</h2>", unsafe_allow_html=True) st.markdown(f"**موقعك:** {profile.get('location', '')} | **حالتك:** {profile.get('job_status', '')}") st.markdown("---")
jobs = find_matching_jobs(profile)
if jobs: for i, job in enumerate(jobs, 1): st.markdown(f""" <div style="background-color:#EBF5FB; border-right: 5px solid #2E86C1; border-radius:10px; padding:15px; margin-bottom:15px;"> <h4>🏢 {job['title']}</h4> <p>📍 الموقع: {job['location']}</p> </div> """, unsafe_allow_html=True) else: st.info("لا توجد فرص عمل متاحة حالياً، سنتواصل معك قريباً.")
if st.button("تقديم جديد"): for key in ['account_created', 'otp_sent', 'otp_code', 'contact', 'submitted', 'user_profile']: st.session_state[key] = False if isinstance(st.session_state.get(key), bool) else (None if key in ['otp_code'] else ("" if key in ['contact'] else {})) st.session_state.account_created = False st.session_state.otp_sent = False st.session_state.otp_code = None st.session_state.contact = "" st.session_state.submitted = False st.session_state.user_profile = {} st.rerun()
if __name__ == "__main__":app.py+161-22