NLPAlhuzali commited on
Commit
ae77d9c
ยท
verified ยท
1 Parent(s): 13a4b1a

Format results as table

Browse files
Files changed (1) hide show
  1. 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) -> 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: Formatted entity extraction result or error message.
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
- result = "ุงู„ูƒูŠุงู†ุงุช ุงู„ู…ุณุชุฎุฑุฌุฉ:\n\n"
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)}"