Spaces:
Sleeping
Sleeping
Update app.py
Browse files5 unmodified lines67891011127 unmodified lines202122232425266 unmodified lines3334353637383940414243444546474849503 unmodified lines5455565758596061626364656667686970717273747576777879808182838485868788899091926 unmodified lines9910010110210310410510623 unmodified lines1301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641 unmodified line1661671681691701711721731741751761771781791801811821831841851864 unmodified lines1911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282295 unmodified linesimport jsonimport random# 1. إعداد الواجهة (كودك الأصلي)st.set_page_config(page_title="تطبيق فرصة عمل", layout="centered")st.markdown("""7 unmodified lines</style>""", unsafe_allow_html=True)# 2. تهيئة Firebase (كودك الأصلي)if not firebase_admin._apps:try:firebase_json = os.environ.get("FIREBASE")6 unmodified linesdb = firestore.client()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:3 unmodified lineselse: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"):continueif 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)6 unmodified linescode = str(random.randint(1000, 9999))st.session_state.otp_code = codest.session_state.otp_sent = True# في التطبيق الحقيقي: أرسل الكود عبر SMS أو Email# هنا نعرضه مؤقتاً للاختبارst.info(f"📨 تم إرسال كود التحقق (للاختبار: **{code}**)")st.rerun()else:23 unmodified linesst.session_state.otp_code = Nonest.rerun()# --- الصفحة الثانية: الأسئلة ---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("📍 سيتم توصيلك بأقرب فرص العمل المتوفرة لموقعك.")submitted = st.form_submit_button("إرسال التقديم")if submitted:if not name or not location:st.warning("رجاءً أكمل جميع الحقول المطلوبة")else:1 unmodified line"name": name,"gender": gender,"age": int(age),"job_status": job_status,"location": location,}if job_status == "خريج":profile["job_title"] = job_titleprofile["major"] = majorelse:profile["edu"] = eduprofile["work_type"] = work_typetry:db.collection("applications").add({**profile, "date": datetime.now()})except Exception:passst.session_state.user_profile = profilest.session_state.submitted = Truest.rerun()4 unmodified linesst.session_state.otp_code = Nonest.rerun()# --- الصفحة الثالثة: فرص العمل المناسبة ---def show_jobs_page():profile = st.session_state.user_profilest.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 = Falsest.session_state.otp_sent = Falsest.session_state.otp_code = Nonest.session_state.contact = ""st.session_state.submitted = Falsest.session_state.user_profile = {}st.rerun()if __name__ == "__main__":main()5 unmodified lines67891011127 unmodified lines202122232425266 unmodified lines333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586873 unmodified lines9192939495969798991006 unmodified lines10710810911011111223 unmodified lines1361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791 unmodified line1811821831841851861871881891901911921931941951961974 unmodified lines2022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472485 unmodified linesimport jsonimport random# 1. إعداد الواجهةst.set_page_config(page_title="تطبيق فرصة عمل", layout="centered")st.markdown("""7 unmodified lines</style>""", unsafe_allow_html=True)# 2. تهيئة Firebaseif not firebase_admin._apps:try:firebase_json = os.environ.get("FIREBASE")6 unmodified linesdb = firestore.client()# session statesfor key, default in {"account_created": False,"otp_sent": False,"otp_code": None,"contact": "","submitted": False,"user_profile": {},"category_choice": "خريج"}.items():if key not in st.session_state:st.session_state[key] = default# ==========================================# دالة جلب ومطابقة الوظائف من Firestore# ==========================================def find_matching_jobs(profile):try:all_ads = db.collection("vacancies").stream()except Exception:return []matches = []user_category = profile.get("job_status", "")user_spec = profile.get("major") or profile.get("work_type", "")user_gender = profile.get("gender", "")for ad in all_ads:data = ad.to_dict()# 1. مطابقة الفئة (إلزامية)if data.get("category", "") != user_category:continue# 2. مطابقة التخصص/المهنة (أو "أخرى" تقبل الجميع)ad_spec = data.get("spec", "")if ad_spec not in (user_spec, "أخرى"):continue# 3. مطابقة الجنس ("كلاهما" يقبل الجميع)ad_gender = data.get("gender", "كلاهما")if ad_gender != "كلاهما" and ad_gender != user_gender:continuematches.append(data)return matchesdef main():if not st.session_state.account_created:3 unmodified lineselse:show_jobs_page()# ==========================================# الصفحة الأولى: ابحث عن وظيفتك + OTP# ==========================================def show_signup_page():st.markdown("<h1 style='text-align: center;'>ابحث عن وظيفتك</h1>", unsafe_allow_html=True)6 unmodified linescode = str(random.randint(1000, 9999))st.session_state.otp_code = codest.session_state.otp_sent = Truest.info(f"📨 تم إرسال كود التحقق (للاختبار: **{code}**)")st.rerun()else:23 unmodified linesst.session_state.otp_code = Nonest.rerun()# ==========================================# الصفحة الثانية: الأسئلة (إصلاح مشكلة الفئة)# ==========================================def show_questions_page():st.markdown("<h2 style='text-align: center;'>إكمال معلومات التقديم</h2>", unsafe_allow_html=True)# ✅ الحل: radio وselectbox خارج الفورم حتى يتغير فوراً عند الاختيارst.session_state.category_choice = st.radio("الحالة",["خريج", "عامل"],horizontal=True,index=0 if st.session_state.category_choice == "خريج" else 1)if st.session_state.category_choice == "خريج":major = st.selectbox("التخصص", ["إدارة وأقتصاد", "هندسة", "تقنية معلومات", "قانون", "لغات", "أخرى"])work_type = ""edu = ""else:edu = st.selectbox("التحصيل الدراسي", ["امي", "ابتدائيه", "متوسطه", "اعداديه"])work_type = st.selectbox("المهنة", ["عامل", "حلاق", "كاشير", "عامل بناء", "خباز", "نجار", "أخرى"])major = ""with st.form("info_form"):name = st.text_input("الاسم")gender = st.radio("الجنس", ["ذكر", "أنثى"], horizontal=True)age = st.number_input("العمر", min_value=18, max_value=65)if st.session_state.category_choice == "خريج":job_title = st.text_input("المسمى الوظيفي")else:job_title = ""location = st.text_input("الموقع (السكن)")st.write("📍 سيتم توصيلك بأقرب فرص العمل المتوفرة لموقعك.")if st.form_submit_button("إرسال التقديم"):if not name or not location:st.warning("رجاءً أكمل جميع الحقول المطلوبة")else:1 unmodified line"name": name,"gender": gender,"age": int(age),"job_status": st.session_state.category_choice,"location": location,"major": major,"work_type": work_type,"edu": edu,"job_title": job_title,}try:db.collection("applications").add({**profile, "date": datetime.now()})except Exception:passst.session_state.user_profile = profilest.session_state.submitted = Truest.rerun()4 unmodified linesst.session_state.otp_code = Nonest.rerun()# ==========================================# الصفحة الثالثة: فرص العمل من Firestore# ==========================================def show_jobs_page():profile = st.session_state.user_profilest.success("✅ تم إرسال معلوماتك بنجاح!")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("---")with st.spinner("جاري البحث عن فرص العمل المناسبة..."):jobs = find_matching_jobs(profile)if jobs:st.markdown(f"### 🎯 وجدنا {len(jobs)} فرصة عمل تناسب مؤهلاتك!")for job in jobs:st.markdown(f"""<div style="background-color:#EBF5FB; border-right: 5px solid #2E86C1; border-radius:10px; padding:15px; margin-bottom:15px;"><h4>🏢 {job.get('job', '')} — {job.get('shop', '')}</h4><p>📍 الموقع: {job.get('location', 'غير محدد')}</p><p>💰 الراتب: {job.get('salary', 'غير محدد')}</p><p>📞 للتواصل: <b>{job.get('phone', 'غير متاح')}</b></p><p>📝 {job.get('details', '')}</p></div>""", unsafe_allow_html=True)else:st.info("⏳ لا توجد فرص عمل مطابقة حالياً، سنتواصل معك عند توفر فرصة تناسبك.")st.balloons()if st.button("تقديم جديد"):st.session_state.account_created = Falsest.session_state.otp_sent = Falsest.session_state.otp_code = Nonest.session_state.contact = ""st.session_state.submitted = Falsest.session_state.user_profile = {}st.session_state.category_choice = "خريج"st.rerun()if __name__ == "__main__":main()
app.py+101-82