File size: 2,579 Bytes
f291881
 
 
6887849
de5713b
 
0ae0889
 
 
 
 
 
 
de5713b
0ae0889
 
 
 
 
 
 
 
 
 
de5713b
f291881
 
 
 
 
 
 
 
de5713b
 
f291881
 
de5713b
 
f291881
de5713b
f291881
 
 
de5713b
 
f291881
de5713b
f291881
 
 
 
 
6887849
f291881
de5713b
 
 
f291881
de5713b
 
 
 
 
f291881
 
de5713b
f291881
 
 
 
 
 
de5713b
 
 
 
f291881
de5713b
f291881
 
 
de5713b
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import gradio as gr
from models.space_a import summarize_question
from models.space_b import generate_mentalqa_answer
from models.space_er import extract_entities

# CSS styling for RTL layout
css = """
body {
  direction: rtl;
  text-align: right;
}

.container-box {
  padding-top: 20px !important;
  margin-top: 0 !important;
  text-align: right;
}

.output-box {
  text-align: right;
  direction: rtl;
}
"""

# Task handler
def analyze_text(text, task, classification_type):
    if not text.strip():
        return "الرجاء إدخال نص للتحليل."
    try:
        if task == "classification":
            return generate_mentalqa_answer(text)
        elif task == "summarization":
            return summarize_question(text)
        elif task == "entity_recognition":
            return extract_entities(text)
        else:
            return "❌ المهمة غير مدعومة حالياً."
    except Exception as e:
        return f"❌ حدث خطأ أثناء المعالجة: {str(e)}"

# Dynamic UI visibility for classification type dropdown
def update_ui(task):
    return gr.update(visible=(task == "classification"))

# Gradio interface
with gr.Blocks(css=css, title="منصة الصحة النفسية") as demo:
    with gr.Column(elem_classes=["container-box"]):
        gr.Markdown("## 🧠 تجربة منصة الصحة النفسية")

        task_selector = gr.Dropdown(
            choices=[
                ("تصنيف الأسئلة والأجوبة", "classification"),
                ("تلخيص النصوص", "summarization"),
                ("التعرف على الكيانات", "entity_recognition")
            ],
            label="اختيار نوع المهمة",
            value="classification"
        )

        user_input = gr.Textbox(
            placeholder="أدخل النص هنا لتحليله...",
            lines=4,
            show_label=False
        )

        classification_dropdown = gr.Dropdown(
            choices=["تصنيف سؤال", "تصنيف إجابة"],
            label="نوع التصنيف",
            visible=True
        )

        submit_btn = gr.Button("ابدأ التحليل")

        output = gr.Textbox(
            label="النتيجة",
            elem_classes=["output-box"]
        )

    # Events
    task_selector.change(fn=update_ui, inputs=task_selector, outputs=classification_dropdown)
    submit_btn.click(fn=analyze_text, inputs=[user_input, task_selector, classification_dropdown], outputs=output)

if __name__ == "__main__":
    demo.launch()