Update app.py
Browse files
app.py
CHANGED
@@ -3,14 +3,9 @@ from gliner import GLiNER
|
|
3 |
import gradio as gr
|
4 |
|
5 |
model = GLiNER.from_pretrained("urchade/gliner_medium-v2.1")
|
|
|
6 |
|
7 |
examples = [
|
8 |
-
[
|
9 |
-
"Libretto by Marius Petipa, based on the 1822 novella ``Trilby, ou Le Lutin d'Argail`` by Charles Nodier, first presented by the Ballet of the Moscow Imperial Bolshoi Theatre on January 25/February 6 (Julian/Gregorian calendar dates), 1870, in Moscow with Polina Karpakova as Trilby and Ludiia Geiten as Miranda and restaged by Petipa for the Imperial Ballet at the Imperial Bolshoi Kamenny Theatre on January 17–29, 1871 in St. Petersburg with Adèle Grantzow as Trilby and Lev Ivanov as Count Leopold.",
|
10 |
-
"person, book, location, date, actor, character",
|
11 |
-
0.3,
|
12 |
-
True,
|
13 |
-
],
|
14 |
[
|
15 |
"""
|
16 |
* Data Scientist, Data Analyst, or Data Engineer with 1+ years of experience.
|
@@ -21,6 +16,12 @@ examples = [
|
|
21 |
* BA or BS degree
|
22 |
* Active Secret OR Active Top Secret or Active TS/SCI clearance
|
23 |
""",
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
"software package, programing language, software tool, degree, job title",
|
25 |
0.3,
|
26 |
False,
|
@@ -102,21 +103,17 @@ examples = [
|
|
102 |
|
103 |
def ner(text: str, labels: str, threshold: float, nested_ner: bool) -> Dict[str, Union[str, int, float]]:
|
104 |
labels = labels.split(",")
|
105 |
-
return
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
text, labels, flat_ner=not nested_ner, threshold=threshold
|
117 |
-
)
|
118 |
-
],
|
119 |
-
}
|
120 |
|
121 |
|
122 |
demo = gr.Interface(
|
@@ -126,7 +123,6 @@ demo = gr.Interface(
|
|
126 |
gr.Textbox(
|
127 |
label="Labels",
|
128 |
placeholder="Enter your labels here (comma separated)",
|
129 |
-
scale=2,
|
130 |
),
|
131 |
gr.Slider(
|
132 |
0,
|
@@ -145,5 +141,5 @@ demo = gr.Interface(
|
|
145 |
outputs=[gr.JSON()],
|
146 |
examples=examples
|
147 |
)
|
148 |
-
|
149 |
demo.launch()
|
|
|
3 |
import gradio as gr
|
4 |
|
5 |
model = GLiNER.from_pretrained("urchade/gliner_medium-v2.1")
|
6 |
+
model.eval()
|
7 |
|
8 |
examples = [
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
[
|
10 |
"""
|
11 |
* Data Scientist, Data Analyst, or Data Engineer with 1+ years of experience.
|
|
|
16 |
* BA or BS degree
|
17 |
* Active Secret OR Active Top Secret or Active TS/SCI clearance
|
18 |
""",
|
19 |
+
[
|
20 |
+
"Libretto by Marius Petipa, based on the 1822 novella ``Trilby, ou Le Lutin d'Argail`` by Charles Nodier, first presented by the Ballet of the Moscow Imperial Bolshoi Theatre on January 25/February 6 (Julian/Gregorian calendar dates), 1870, in Moscow with Polina Karpakova as Trilby and Ludiia Geiten as Miranda and restaged by Petipa for the Imperial Ballet at the Imperial Bolshoi Kamenny Theatre on January 17–29, 1871 in St. Petersburg with Adèle Grantzow as Trilby and Lev Ivanov as Count Leopold.",
|
21 |
+
"person, book, location, date, actor, character",
|
22 |
+
0.3,
|
23 |
+
True,
|
24 |
+
],
|
25 |
"software package, programing language, software tool, degree, job title",
|
26 |
0.3,
|
27 |
False,
|
|
|
103 |
|
104 |
def ner(text: str, labels: str, threshold: float, nested_ner: bool) -> Dict[str, Union[str, int, float]]:
|
105 |
labels = labels.split(",")
|
106 |
+
return [
|
107 |
+
{
|
108 |
+
"entity": entity["label"],
|
109 |
+
"word": entity["text"],
|
110 |
+
"start": entity["start"],
|
111 |
+
"end": entity["end"],
|
112 |
+
}
|
113 |
+
for entity in model.predict_entities(
|
114 |
+
text, labels, flat_ner=not nested_ner, threshold=threshold
|
115 |
+
)
|
116 |
+
]
|
|
|
|
|
|
|
|
|
117 |
|
118 |
|
119 |
demo = gr.Interface(
|
|
|
123 |
gr.Textbox(
|
124 |
label="Labels",
|
125 |
placeholder="Enter your labels here (comma separated)",
|
|
|
126 |
),
|
127 |
gr.Slider(
|
128 |
0,
|
|
|
141 |
outputs=[gr.JSON()],
|
142 |
examples=examples
|
143 |
)
|
144 |
+
demo.queue(max_size=4)
|
145 |
demo.launch()
|