AniseF commited on
Commit
00304f9
·
verified ·
1 Parent(s): d7a652e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -23
app.py CHANGED
@@ -15,36 +15,39 @@ import gradio as gr
15
 
16
  import stanza
17
 
18
- # baixa modelo uma vez (HF-friendly)
19
- try:
20
- stanza.download(
21
- "grc",
22
- processors="tokenize,pos,lemma,morph",
23
- verbose=False
24
- )
25
- except Exception:
26
- pass
27
-
28
  ud_nlp = None
29
  UD_AVAILABLE = False
30
 
31
- try:
32
- ud_nlp = stanza.Pipeline(
33
- lang="grc",
34
- processors="tokenize,pos,lemma,morph",
35
- tokenize_no_ssplit=True,
36
- use_gpu=False
37
- )
38
- UD_AVAILABLE = True
39
- except Exception:
40
- UD_AVAILABLE = False
41
-
42
 
43
  def morph_ud_analyze(sentence: str):
44
- """Morph_Raw UD: frase -> lista de tokens com lema, UPOS e feats."""
45
- if not UD_AVAILABLE or not sentence.strip():
 
46
  return None
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  doc = ud_nlp(sentence)
49
  results = []
50
 
@@ -56,9 +59,11 @@ def morph_ud_analyze(sentence: str):
56
  "upos": w.upos,
57
  "feats": w.feats
58
  })
 
59
  return results
60
 
61
 
 
62
  # ============================================================
63
  # DDGP — UTILITÁRIOS
64
  # ============================================================
 
15
 
16
  import stanza
17
 
 
 
 
 
 
 
 
 
 
 
18
  ud_nlp = None
19
  UD_AVAILABLE = False
20
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  def morph_ud_analyze(sentence: str):
23
+ global ud_nlp, UD_AVAILABLE
24
+
25
+ if not sentence or not sentence.strip():
26
  return None
27
 
28
+ # inicializa o UD SOMENTE na primeira chamada
29
+ if ud_nlp is None:
30
+ try:
31
+ stanza.download(
32
+ "grc",
33
+ processors="tokenize,pos,lemma,morph",
34
+ verbose=False
35
+ )
36
+
37
+ ud_nlp = stanza.Pipeline(
38
+ lang="grc",
39
+ processors="tokenize,pos,lemma,morph",
40
+ tokenize_no_ssplit=True,
41
+ use_gpu=False
42
+ )
43
+
44
+ UD_AVAILABLE = True
45
+
46
+ except Exception:
47
+ UD_AVAILABLE = False
48
+ return None
49
+
50
+ # análise propriamente dita
51
  doc = ud_nlp(sentence)
52
  results = []
53
 
 
59
  "upos": w.upos,
60
  "feats": w.feats
61
  })
62
+
63
  return results
64
 
65
 
66
+
67
  # ============================================================
68
  # DDGP — UTILITÁRIOS
69
  # ============================================================