Spaces:
Runtime error
Runtime error
Go back to Dr.Hassan's model + add question classify
Browse files- models/space_classify.py +36 -14
models/space_classify.py
CHANGED
|
@@ -1,33 +1,55 @@
|
|
| 1 |
-
# space_classify.py
|
| 2 |
-
|
| 3 |
from transformers import pipeline
|
| 4 |
|
|
|
|
| 5 |
def classifyA(text):
|
| 6 |
"""
|
| 7 |
Extracts labels and scores from the input data,
|
| 8 |
maps the labels using the provided mapping dictionary,
|
| 9 |
and returns a list of formatted label-score strings.
|
| 10 |
"""
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
model="asafaya/bert-base-arabic",
|
| 14 |
-
return_all_scores=True
|
| 15 |
-
)
|
| 16 |
-
|
| 17 |
result = []
|
| 18 |
-
|
| 19 |
mapping = {
|
| 20 |
-
'
|
| 21 |
-
'
|
| 22 |
-
'
|
| 23 |
}
|
| 24 |
-
|
| 25 |
output = classification(text)
|
| 26 |
-
for item in output[0]:
|
| 27 |
label = item['label']
|
| 28 |
label = mapping.get(label)
|
| 29 |
score = item['score']
|
| 30 |
if score > 0.5:
|
| 31 |
result.append(label)
|
|
|
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
return ', '.join(result)
|
|
|
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
|
| 3 |
+
|
| 4 |
def classifyA(text):
|
| 5 |
"""
|
| 6 |
Extracts labels and scores from the input data,
|
| 7 |
maps the labels using the provided mapping dictionary,
|
| 8 |
and returns a list of formatted label-score strings.
|
| 9 |
"""
|
| 10 |
+
from transformers import pipeline
|
| 11 |
+
classification = pipeline(task="text-classification", model="Hashuz/AS_MentalQAU", return_all_scores=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
result = []
|
| 13 |
+
|
| 14 |
mapping = {
|
| 15 |
+
'info': 'ุชูุฏูู
ู
ุนููู
ุฉ',
|
| 16 |
+
'guid': 'ุชูุฌูู ุฃู ุงุฑุดุงุฏ',
|
| 17 |
+
'support': 'ุฏุนู
ููุณู'
|
| 18 |
}
|
|
|
|
| 19 |
output = classification(text)
|
| 20 |
+
for item in output[0]:
|
| 21 |
label = item['label']
|
| 22 |
label = mapping.get(label)
|
| 23 |
score = item['score']
|
| 24 |
if score > 0.5:
|
| 25 |
result.append(label)
|
| 26 |
+
return ', '.join(result)
|
| 27 |
|
| 28 |
+
|
| 29 |
+
def classifyQ(text):
|
| 30 |
+
"""
|
| 31 |
+
Extracts labels and scores from the input data,
|
| 32 |
+
maps the labels using the provided mapping dictionary,
|
| 33 |
+
and returns a list of formatted label-score strings.
|
| 34 |
+
"""
|
| 35 |
+
from transformers import pipeline
|
| 36 |
+
classification = pipeline(task="text-classification", model="Hashuz/QT_MentalQA", return_all_scores=True)
|
| 37 |
+
result = []
|
| 38 |
+
|
| 39 |
+
mapping = {
|
| 40 |
+
'diagnosis': 'ูุญุต',
|
| 41 |
+
'treatment': 'ุนูุงุฌ',
|
| 42 |
+
'anatomy': 'ุงูุชุดุฑูุญ',
|
| 43 |
+
'epidemiology': 'ุงูุฃูุจุฆุฉ',
|
| 44 |
+
'lifestyle': 'ูู
ุท ุงูุญูุงุฉ',
|
| 45 |
+
'provider': 'ู
ูุฏู
ุงูุฎุฏู
ุฉ',
|
| 46 |
+
'other': 'ุบูุฑ ู
ุญุฏุฏ'
|
| 47 |
+
}
|
| 48 |
+
output = classification(text)
|
| 49 |
+
for item in output[0]:
|
| 50 |
+
label = item['label']
|
| 51 |
+
label = mapping.get(label)
|
| 52 |
+
score = item['score']
|
| 53 |
+
if score > 0.5:
|
| 54 |
+
result.append(label)
|
| 55 |
return ', '.join(result)
|