Spaces:
Runtime error
Runtime error
Format results as table
Browse files- models/space_er.py +4 -6
models/space_er.py
CHANGED
|
@@ -30,7 +30,7 @@ except Exception as e:
|
|
| 30 |
# Entity labels to extract
|
| 31 |
LABELS = ["MEDICATION", "DOSAGE", "DURATION"]
|
| 32 |
|
| 33 |
-
def extract_entities(text: str)
|
| 34 |
"""
|
| 35 |
Extract named entities from Arabic text using GLiNER.
|
| 36 |
|
|
@@ -38,7 +38,7 @@ def extract_entities(text: str) -> str:
|
|
| 38 |
text (str): Input Arabic text.
|
| 39 |
|
| 40 |
Returns:
|
| 41 |
-
str:
|
| 42 |
"""
|
| 43 |
if not text.strip():
|
| 44 |
return "ูุฑุฌู ุฅุฏุฎุงู ูุต ููุชุญููู / Please enter text to analyze"
|
|
@@ -48,10 +48,8 @@ def extract_entities(text: str) -> str:
|
|
| 48 |
if not entities:
|
| 49 |
return "ูู
ูุชู
ุงูุนุซูุฑ ุนูู ุฃู ููุงูุงุช / No entities found"
|
| 50 |
|
| 51 |
-
|
| 52 |
-
for ent in entities
|
| 53 |
-
result += f"{ent['text']} => {ent['label']}\n"
|
| 54 |
-
return result
|
| 55 |
|
| 56 |
except Exception as e:
|
| 57 |
return f"ุฎุทุฃ ูู ุงูุชุญููู / Analysis Error: {str(e)}"
|
|
|
|
| 30 |
# Entity labels to extract
|
| 31 |
LABELS = ["MEDICATION", "DOSAGE", "DURATION"]
|
| 32 |
|
| 33 |
+
def extract_entities(text: str):
|
| 34 |
"""
|
| 35 |
Extract named entities from Arabic text using GLiNER.
|
| 36 |
|
|
|
|
| 38 |
text (str): Input Arabic text.
|
| 39 |
|
| 40 |
Returns:
|
| 41 |
+
list[dict] | str: List of extracted entities (as table rows) or error message.
|
| 42 |
"""
|
| 43 |
if not text.strip():
|
| 44 |
return "ูุฑุฌู ุฅุฏุฎุงู ูุต ููุชุญููู / Please enter text to analyze"
|
|
|
|
| 48 |
if not entities:
|
| 49 |
return "ูู
ูุชู
ุงูุนุซูุฑ ุนูู ุฃู ููุงูุงุช / No entities found"
|
| 50 |
|
| 51 |
+
# Return as list of dicts for Gradio Dataframe
|
| 52 |
+
return [{"ุงููุต": ent["text"], "ุงูุชุตููู": ent["label"]} for ent in entities]
|
|
|
|
|
|
|
| 53 |
|
| 54 |
except Exception as e:
|
| 55 |
return f"ุฎุทุฃ ูู ุงูุชุญููู / Analysis Error: {str(e)}"
|