qanastek commited on
Commit
049266b
1 Parent(s): d407670
Files changed (2) hide show
  1. app.py +75 -29
  2. gradio_app.py +29 -0
app.py CHANGED
@@ -1,29 +1,75 @@
1
- import gradio as gr
2
-
3
- from flair.data import Sentence
4
- from flair.models import SequenceTagger
5
-
6
- # Load the model
7
- model = SequenceTagger.load("qanastek/pos-french")
8
-
9
- def getPartOfSpeechFR(content):
10
-
11
- # George Washington est allé à Washington
12
-
13
- sentence = Sentence(content)
14
-
15
- # predict tags
16
- model.predict(sentence)
17
-
18
- # print predicted pos tags
19
- res = sentence.to_tagged_string()
20
-
21
- return res
22
-
23
- iface = gr.Interface(
24
- title="🥖 French Part Of Speech Tagging",
25
- fn=getPartOfSpeechFR,
26
- inputs="textbox",
27
- outputs="textbox",
28
- )
29
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+
3
+ import errant
4
+ import streamlit as st
5
+
6
+ from flair.data import Sentence
7
+ from flair.models import SequenceTagger
8
+
9
+ from highlighter import show_highlights
10
+
11
+ checkpoints = [
12
+ "qanastek/pos-french",
13
+ ]
14
+
15
+ @st.cache(suppress_st_warning=True, allow_output_mutation=True)
16
+ def get_model(model_name):
17
+
18
+ # Load the model
19
+ return SequenceTagger.load(model_name)
20
+
21
+ @st.cache(suppress_st_warning=True, allow_output_mutation=True)
22
+ def get_annotator(lang: str):
23
+ return errant.load(lang)
24
+
25
+
26
+ def main():
27
+
28
+ st.title("🥖 French-Part-Of-Speech-Tagging")
29
+
30
+ annotator = get_annotator("fr")
31
+ checkpoint = st.selectbox("Choose model", checkpoints)
32
+ model = get_model(checkpoint)
33
+
34
+ default_text = "George Washington est allé à Washington"
35
+ input_text = st.text_area(
36
+ label="Original text",
37
+ value=default_text,
38
+ )
39
+
40
+ start = None
41
+ if st.button("🧠 Compute"):
42
+ start = time.time()
43
+ with st.spinner("Search for Part-Of-Speech Tags 🔍"):
44
+
45
+ # Build Sentence
46
+ sentence = Sentence(input_text)
47
+
48
+ # predict tags
49
+ model.predict(sentence)
50
+
51
+ # print predicted pos tags
52
+ result = sentence.to_tagged_string()
53
+
54
+ try:
55
+ show_highlights(annotator, input_text, result)
56
+ st.write("")
57
+ st.success(result)
58
+ except Exception as e:
59
+ st.error("Some error occured!" + str(e))
60
+ st.stop()
61
+
62
+ st.write("---")
63
+ st.markdown(
64
+ "Built by [Yanis Labrak](https://www.linkedin.com/in/yanis-labrak-8a7412145/) 🚀"
65
+ )
66
+ st.markdown(
67
+ "_Source code made with [FlairNLP](https://github.com/flairNLP/flair)_"
68
+ )
69
+
70
+ if start is not None:
71
+ st.text(f"prediction took {time.time() - start:.2f}s")
72
+
73
+
74
+ if __name__ == "__main__":
75
+ main()
gradio_app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from flair.data import Sentence
4
+ from flair.models import SequenceTagger
5
+
6
+ # Load the model
7
+ model = SequenceTagger.load("qanastek/pos-french")
8
+
9
+ def getPartOfSpeechFR(content):
10
+
11
+ # George Washington est allé à Washington
12
+
13
+ sentence = Sentence(content)
14
+
15
+ # predict tags
16
+ model.predict(sentence)
17
+
18
+ # print predicted pos tags
19
+ res = sentence.to_tagged_string()
20
+
21
+ return res
22
+
23
+ iface = gr.Interface(
24
+ title="🥖 French Part Of Speech Tagging",
25
+ fn=getPartOfSpeechFR,
26
+ inputs="textbox",
27
+ outputs="textbox",
28
+ )
29
+ iface.launch()