File size: 1,707 Bytes
a0bc165
 
01e1ed6
a0bc165
 
 
 
 
 
01e1ed6
 
a0bc165
01e1ed6
a0bc165
01e1ed6
 
 
a0bc165
 
01e1ed6
a0bc165
 
 
 
 
01e1ed6
a0bc165
01e1ed6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0bc165
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
from transformers import pipeline


def classifyA(text):
    """
    Extracts labels and scores from the input data,
    maps the labels using the provided mapping dictionary,
    and returns a list of formatted label-score strings.
    """
    from transformers import pipeline
    classification = pipeline(task="text-classification", model="Hashuz/AS_MentalQAU", return_all_scores=True)
    result = []

    mapping = {
        'info': 'تقديم معلومة',
        'guid': 'توجيه أو ارشاد',
        'support': 'دعم نفسي'
    }
    output = classification(text)
    for item in output[0]:  
        label = item['label']
        label = mapping.get(label)
        score = item['score']
        if score > 0.5:
            result.append(label)
    return ', '.join(result)


def classifyQ(text):
    """
    Extracts labels and scores from the input data,
    maps the labels using the provided mapping dictionary,
    and returns a list of formatted label-score strings.
    """
    from transformers import pipeline
    classification = pipeline(task="text-classification", model="Hashuz/QT_MentalQA", return_all_scores=True)
    result = []
    
    mapping = {
        'diagnosis': 'فحص',
        'treatment': 'علاج',
        'anatomy': 'التشريح',
        'epidemiology': 'الأوبئة',
        'lifestyle': 'نمط الحياة',
        'provider': 'مقدم الخدمة',
        'other': 'غير محدد'
    }
    output = classification(text)
    for item in output[0]: 
        label = item['label']
        label = mapping.get(label)
        score = item['score']
        if score > 0.5:
            result.append(label)
    return ', '.join(result)