File size: 1,978 Bytes
c410028
 
 
3271809
c410028
3271809
 
c410028
3271809
c410028
3271809
 
 
 
c410028
3271809
 
 
 
 
 
c410028
3271809
c410028
3271809
 
 
 
 
c410028
3271809
 
 
c410028
 
3271809
 
 
 
 
 
 
c410028
3271809
dcbccdd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import gradio as gr
from transformers import pipeline

# تحميل النماذج بشكل آمن متوافق مع السيرفر السحابي
try:
    classifier_en = pipeline("text-classification", model="distilbert-base-uncased")
    classifier_ar = pipeline("text-classification", model="CAMeL-Lab/bert-base-arabic-camelbert-mix")
except Exception as e:
    print(f"Error loading models: {e}")

# الدالة الأساسية لمعالجة النصوص وتوقع الإجهاد
def predict_stress(text):
    if not text.strip():
        return "الرجاء إدخال نص للتحليل."
    
    # تحديد لغة النص المسلمة (عربي أم إنجليزي) بشكل مبسط
    is_arabic = any("\u0600" <= char <= "\u06FF" for char in text)
    
    try:
        if is_arabic:
            res = classifier_ar(text)[0]
        else:
            res = classifier_en(text)[0]
        
        label = res['label']
        score = res['score'] * 100
        return f"النتيجة: {label} (نسبة التأكد: {score:.2f}%)"
    except Exception as e:
        return f"حدث خطأ أثناء التحليل: {str(e)}"

# بناء واجهة المستخدم باستخدام Gradio
with gr.Blocks() as demo:
    gr.Markdown("# 🧠 نظام التنبؤ بمستويات الإجهاد النفسي باستخدام الذكاء الاصطناعي")
    
    with gr.Row():
        input_text = gr.Textbox(label="أدخل النص المراد تحليله (يدعم العربية والإنجليزية)", placeholder="اكتب شعورك هنا...")
    
    with gr.Row():
        output_text = gr.Textbox(label="تحليل النظام")
        
    submit_btn = gr.Button("تحليل النص")
    submit_btn.click(fn=predict_stress, inputs=input_text, outputs=output_text)

# تشغيل الواجهة (يجب تركها فارغة تماماً لتعمل على السيرفر)
demo.launch()