Jacobo commited on
Commit
0a30cc1
1 Parent(s): 72aaba6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -33
app.py CHANGED
@@ -1,13 +1,14 @@
1
- from typing import List, Sequence, Tuple, Optional, Dict, Union, Callable
2
  import spacy
3
  from spacy import displacy
4
  from spacy.language import Language
5
  import streamlit as st
6
  from spacy_streamlit import visualize_parser
 
7
  import base64
8
  from PIL import Image
9
  import deplacy
10
- import graphviz
11
 
12
 
13
 
@@ -15,16 +16,16 @@ import graphviz
15
 
16
  st.set_page_config(layout="wide")
17
 
18
- st.title("Ancient Greek Analyzer")
19
 
20
- st.markdown("Here you'll find four spaCy models for processing ancient Greek. They have been trained with the Universal Dependencies datasets *Perseus* and *Proiel*. We provide two types of models for each dataset. The '_lg' models were built with tok2vec pretrained embeddings and fasttext vectors, while the '_tfr' models have a transfomers layer. You can choose among models to compare their performance. More information about the models can be found in the [Huggingface Models Hub] (https://huggingface.co/Jacobo).")
21
 
22
- st.sidebar.image("logo.png", use_column_width=False, width=150, caption="\n provided by Diogenet")
23
 
24
- st.sidebar.title("Choose model:")
25
- spacy_model = st.sidebar.selectbox("", ["grc_ud_perseus_lg", "grc_ud_proiel_lg","grc_ud_perseus_trf"])
26
 
27
- st.header("Text to analyze:")
28
  text = st.text_area("", "Πλάτων ὁ Περικτιόνης τὸ γένος ἀνέφερεν εἰς Σόλωνα.")
29
 
30
 
@@ -47,7 +48,7 @@ def get_svg(svg: str, style: str = "", wrap: bool = True):
47
  def visualize_parser(
48
  doc: spacy.tokens.Doc,
49
  *,
50
- title: Optional[str] = "Dependency parse & part of speech",
51
  key: Optional[str] = None,
52
  ) -> None:
53
  """Visualizer for dependency parses."""
@@ -61,7 +62,7 @@ def visualize_parser(
61
  "collapse_punct": cols[1].checkbox(
62
  "Collapse punct", value=True, key=f"{key}_parser_collapse_punct"
63
  ),
64
- "compact": cols[3].checkbox("Compact mode", value=True, key=f"{key}_parser_compact"),
65
  }
66
  docs = [span.as_doc() for span in doc.sents] if split_sents else [doc]
67
  for sent in docs:
@@ -75,32 +76,11 @@ def visualize_parser(
75
 
76
  visualize_parser(doc)
77
 
78
- #graph_r = deplacy.render(doc)
79
-
80
- #st.graphviz_chart(graph_r)
81
 
 
82
 
83
  graph_dot = deplacy.dot(doc)
84
 
85
- #graphviz.Source(deplacy.dot(doc))
86
-
87
  st.graphviz_chart(graph_dot)
88
 
89
-
90
-
91
-
92
-
93
- #st.sidebar.title("Model 2")
94
- #spacy_model2 = st.sidebar.selectbox("Model 2", ["grc_ud_perseus_lg", "grc_ud_proiel_lg"])
95
-
96
- #st.header("Text to analyze:")
97
- #text = st.text_area("", "Πλάτων ὁ Περικτιόνης τὸ γένος ἀνέφερεν εἰς Σόλωνα.")
98
-
99
-
100
- #nlp = spacy.load(spacy_model2)
101
- #doc2 = nlp(text)
102
-
103
- #visualize_parser(doc2)
104
-
105
- #visualizers = ["pos", "dep"]
106
- #spacy_streamlit.visualize(models, default_text,visualizers)
 
1
+ from typing import Optional
2
  import spacy
3
  from spacy import displacy
4
  from spacy.language import Language
5
  import streamlit as st
6
  from spacy_streamlit import visualize_parser
7
+ from spacy_streamlit import visualize_tokens
8
  import base64
9
  from PIL import Image
10
  import deplacy
11
+ #import graphviz
12
 
13
 
14
 
 
16
 
17
  st.set_page_config(layout="wide")
18
 
19
+ st.image("logo.png", use_column_width=False, width=150)
20
 
21
+ st.title("Diogenet's Ancient Greek Syntax Analyzer")
22
 
23
+ st.markdown("Here you'll find four spaCy models for processing ancient Greek. They have been trained with the Universal Dependencies datasets *Perseus* and *Proiel*. We provide two types of models for each dataset. The '_lg' models were built with tok2vec pretrained embeddings and fasttext vectors, while the '_tfr' models have a transfomers layer. You can choose among models to compare their performance. More information about the models can be found in the [Huggingface Models Hub] (https://huggingface.co/Jacobo).")
24
 
25
+ st.header("Select a model:")
26
+ spacy_model = st.selectbox("", ["grc_ud_perseus_lg", "grc_ud_proiel_lg","grc_ud_perseus_trf"])
27
 
28
+ st.header("Enter text:")
29
  text = st.text_area("", "Πλάτων ὁ Περικτιόνης τὸ γένος ἀνέφερεν εἰς Σόλωνα.")
30
 
31
 
 
48
  def visualize_parser(
49
  doc: spacy.tokens.Doc,
50
  *,
51
+ title: Optional[str] = "Dependency parse & part of speech:",
52
  key: Optional[str] = None,
53
  ) -> None:
54
  """Visualizer for dependency parses."""
 
62
  "collapse_punct": cols[1].checkbox(
63
  "Collapse punct", value=True, key=f"{key}_parser_collapse_punct"
64
  ),
65
+ "compact": cols[3].checkbox("Compact mode", value=False, key=f"{key}_parser_compact"),
66
  }
67
  docs = [span.as_doc() for span in doc.sents] if split_sents else [doc]
68
  for sent in docs:
 
76
 
77
  visualize_parser(doc)
78
 
 
 
 
79
 
80
+ st.header("Tree View:")
81
 
82
  graph_dot = deplacy.dot(doc)
83
 
 
 
84
  st.graphviz_chart(graph_dot)
85
 
86
+ visualize_tokens(doc, attrs=["text", "lemma_", "pos_", "dep_"], title="Table View:")