BioMike commited on
Commit
f362709
·
verified ·
1 Parent(s): 5bf08e5

Delete interfaces

Browse files
interfaces/__init__.py DELETED
@@ -1,8 +0,0 @@
1
- from .qa import qa_interface
2
- from .ner import ner_interface
3
- from .open_ie import open_ie_interface
4
- from .summarization import summarization_interface
5
- from .relation_e import relation_e_interface
6
- from .landing import landing_interface
7
- from .universal import universal_interface
8
- from .classification import classification_interface
 
 
 
 
 
 
 
 
 
interfaces/landing.py DELETED
@@ -1,32 +0,0 @@
1
- import gradio as gr
2
-
3
- with open('materials/introduction.html', 'r', encoding='utf-8') as file:
4
- html_description = file.read()
5
-
6
- with gr.Blocks() as landing_interface:
7
- gr.HTML(html_description)
8
-
9
- with gr.Accordion("How to run this model locally", open=False):
10
- gr.Markdown(
11
- """
12
- ## Installation
13
- To use this model, you must install the GLiNER Python library:
14
- ```
15
- pip install gliner
16
- ```
17
- ## Usage
18
- Once you've downloaded the GLiNER library, you can import the GLiNER class. You can then load this model using `GLiNER.from_pretrained` and predict entities with `predict_entities`.
19
- """
20
- )
21
- gr.Code(
22
- '''
23
- from gliner import GLiNER
24
- model = GLiNER.from_pretrained("knowledgator/gliner-multitask-v1.0")
25
- text = "Your text here"
26
- labels = ["person", "award", "date", "competitions", "teams"]
27
- entities = model.predict_entities(text, labels)
28
- for entity in entities:
29
- print(entity["text"], "=>", entity["label"])
30
- ''',
31
- language="python",
32
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
interfaces/ner.py DELETED
@@ -1,183 +0,0 @@
1
- from typing import Dict, Union
2
- from gliner import GLiNER
3
- import gradio as gr
4
-
5
- model = GLiNER.from_pretrained("knowledgator/gliner-multitask-v1.0").to("cpu")
6
-
7
- text1 = """
8
- "I recently purchased the Sony WH-1000XM4 Wireless Noise-Canceling Headphones from Amazon and I must say, I'm thoroughly impressed. The package arrived in New York within 2 days, thanks to Amazon Prime's expedited shipping.
9
-
10
- The headphones themselves are remarkable. The noise-canceling feature works like a charm in the bustling city environment, and the 30-hour battery life means I don't have to charge them every day. Connecting them to my Samsung Galaxy S21 was a breeze, and the sound quality is second to none.
11
-
12
- I also appreciated the customer service from Amazon when I had a question about the warranty. They responded within an hour and provided all the information I needed.
13
-
14
- However, the headphones did not come with a hard case, which was listed in the product description. I contacted Amazon, and they offered a 10% discount on my next purchase as an apology.
15
-
16
- Overall, I'd give these headphones a 4.5/5 rating and highly recommend them to anyone looking for top-notch quality in both product and service."""
17
-
18
-
19
- text3 = """
20
- Several studies have reported its pharmacological activities, including anti-inflammatory, antimicrobial, and antitumoral effects.
21
- The effect of E-anethole was studied in the osteosarcoma MG-63 cell line, and the antiproliferative activity was evaluated by an MTT assay.
22
- It showed a GI50 value of 60.25 μM with apoptosis induction through the mitochondrial-mediated pathway. Additionally, it induced cell cycle arrest at the G0/G1 phase, up-regulated the expression of p53, caspase-3, and caspase-9, and down-regulated Bcl-xL expression.
23
- Moreover, the antitumoral activity of anethole was assessed against oral tumor Ca9-22 cells, and the cytotoxic effects were evaluated by MTT and LDH assays.
24
- It demonstrated a LD50 value of 8 μM, and cellular proliferation was 42.7% and 5.2% at anethole concentrations of 3 μM and 30 μM, respectively.
25
- It was reported that it could selectively and in a dose-dependent manner decrease cell proliferation and induce apoptosis, as well as induce autophagy, decrease ROS production, and increase glutathione activity. The cytotoxic effect was mediated through NF-kB, MAP kinases, Wnt, caspase-3 and -9, and PARP1 pathways. Additionally, treatment with anethole inhibited cyclin D1 oncogene expression, increased cyclin-dependent kinase inhibitor p21WAF1, up-regulated p53 expression, and inhibited the EMT markers.
26
- """
27
-
28
- text5 = """
29
- Dr. Paul Hammond, a renowned neurologist at Johns Hopkins University, has recently published a paper in the prestigious journal "Nature Neuroscience". His research focuses on a rare genetic mutation, found in less than 0.01% of the population, that appears to prevent the development of Alzheimer's disease. Collaborating with researchers at the University of California, San Francisco, the team is now working to understand the mechanism by which this mutation confers its protective effect. Funded by the National Institutes of Health, their research could potentially open new avenues for Alzheimer's treatment.
30
- """
31
-
32
- ner_examples = [
33
-
34
- [
35
- text5,
36
- "neurologist, scientist, gene, disease, biological process, city, journal, university",
37
- 0.4,
38
- True
39
- ],
40
- [
41
- text1,
42
- "product, brand, location, features, rating",
43
- 0.5,
44
- False
45
- ],
46
- [
47
- text3,
48
- "cell line, protein, metric, substance",
49
- 0.5,
50
- False
51
- ],
52
- [
53
- """
54
- * Data Scientist, Data Analyst, or Data Engineer with 1+ years of experience.
55
- * Experience with technologies such as Docker, Kubernetes, or Kubeflow
56
- * Machine Learning experience preferred
57
- * Experience with programming languages such as Python, C++, or SQL preferred
58
- * Experience with technologies such as Databricks, Qlik, TensorFlow, PyTorch, Python, Dash, Pandas, or NumPy preferred
59
- * BA or BS degree
60
- * Active Secret OR Active Top Secret or Active TS/SCI clearance
61
- """,
62
- "software package, programing language, software tool, degree, job title",
63
- 0.3,
64
- False,
65
- ],
66
- [
67
- "However, both models lack other frequent DM symptoms including the fibre-type dependent atrophy, myotonia, cataract and male-infertility.",
68
- "disease, symptom",
69
- 0.3,
70
- False,
71
- ],
72
- [
73
- "Synergy between signal transduction pathways is obligatory for expression of c-fos in B and T cell lines: implication for c-fos control via surface immunoglobulin and T cell antigen receptors.",
74
- "DNA, RNA, cell line, cell type, protein",
75
- 0.3,
76
- False,
77
- ],
78
- [
79
- "The choice of the encoder and decoder modules of dnpg can be quite flexible, for instance long short term memory networks (lstm) or convolutional neural network (cnn).",
80
- "short acronym, long acronym",
81
- 0.3,
82
- False,
83
- ],
84
- [
85
- "Amelia Earhart flew her single engine Lockheed Vega 5B across the Atlantic to Paris.",
86
- "person, company, location, airplane",
87
- 0.3,
88
- True,
89
- ],
90
- [
91
- "Feldman is a contributor to NBC Sports Boston's ``State of the Revs`` and ``Revolution Postgame Live`` programs as well as to 98.5 the SportsHub, SiriusXM FC's MLS coverage and to other New England and national radio outlets and podcasts.",
92
- "person, company, location",
93
- 0.3,
94
- False,
95
- ],
96
- [
97
- "On 25 July 1948, on the 39th anniversary of Bleriot's crossing of the English Channel, the Type 618 Nene-Viking flew Heathrow to Paris (Villacoublay) in the morning carrying letters to Bleriot's widow and son (secretary of the FAI), who met it at the airport.",
98
- "date, location, person, organization",
99
- 0.3,
100
- False,
101
- ],
102
- [
103
- "Leo & Ian won the 1962 Bathurst Six Hour Classic at Mount Panorama driving a Daimler SP250 sports car, (that year the 500 mile race for touring cars were held at Phillip Island)",
104
- "person, date, location, organization, competition",
105
- 0.3,
106
- False,
107
- ],
108
- [
109
- "The Shore Line route of the CNS & M until 1955 served, from south to north, the Illinois communities of Chicago, Evanston, Wilmette, Kenilworth, Winnetka, Glencoe, Highland Park, Highwood, Fort Sheridan, Lake Forest, Lake Bluff, North Chicago, Waukegan, Zion, and Winthrop Harbor as well as Kenosha, Racine, and Milwaukee (the ``KRM'') in Wisconsin.",
110
- "location, organization, date",
111
- 0.3,
112
- False,
113
- ],
114
- [
115
- "Comet C/2006 M4 (SWAN) is a non-periodic comet discovered in late June 2006 by Robert D. Matson of Irvine, California and Michael Mattiazzo of Adelaide, South Australia in publicly available images of the Solar and Heliospheric Observatory (SOHO).",
116
- "person, organization, date, location",
117
- 0.3,
118
- False,
119
- ]]
120
-
121
- def merge_entities(entities):
122
- if not entities:
123
- return []
124
- merged = []
125
- current = entities[0]
126
- for next_entity in entities[1:]:
127
- if next_entity['entity'] == current['entity'] and (next_entity['start'] == current['end'] + 1 or next_entity['start'] == current['end']):
128
- current['word'] += ' ' + next_entity['word']
129
- current['end'] = next_entity['end']
130
- else:
131
- merged.append(current)
132
- current = next_entity
133
- merged.append(current)
134
- return merged
135
-
136
- def process(
137
- text, labels: str, threshold: float, nested_ner: bool
138
- ) -> Dict[str, Union[str, int, float]]:
139
- labels = [label.strip() for label in labels.split(",")]
140
- r = {
141
- "text": text,
142
- "entities": [
143
- {
144
- "entity": entity["label"],
145
- "word": entity["text"],
146
- "start": entity["start"],
147
- "end": entity["end"],
148
- "score": 0,
149
- }
150
- for entity in model.predict_entities(
151
- text, labels, flat_ner=not nested_ner, threshold=threshold
152
- )
153
- ],
154
- }
155
- r["entities"] = merge_entities(r["entities"])
156
- return r
157
-
158
- with gr.Blocks(title="NER Task") as ner_interface:
159
- input_text = gr.Textbox(label="Text input", placeholder="Enter your text here")
160
- labels = gr.Textbox(label="Labels", placeholder="Enter your labels here (comma separated)", scale=2)
161
- threshold = gr.Slider(0, 1, value=0.3, step=0.01, label="Threshold", info="Lower the threshold to increase how many entities get predicted.")
162
- nested_ner = gr.Checkbox(label="Nested NER", info="Allow for nested NER?")
163
- output = gr.HighlightedText(label="Predicted Entities")
164
- submit_btn = gr.Button("Submit")
165
- examples = gr.Examples(
166
- ner_examples,
167
- fn=process,
168
- inputs=[input_text, labels, threshold, nested_ner],
169
- outputs=output,
170
- cache_examples=True
171
- )
172
- theme=gr.themes.Base()
173
-
174
- input_text.submit(fn=process, inputs=[input_text, labels, threshold, nested_ner], outputs=output)
175
- labels.submit(fn=process, inputs=[input_text, labels, threshold, nested_ner], outputs=output)
176
- threshold.release(fn=process, inputs=[input_text, labels, threshold, nested_ner], outputs=output)
177
- submit_btn.click(fn=process, inputs=[input_text, labels, threshold, nested_ner], outputs=output)
178
- nested_ner.change(fn=process, inputs=[input_text, labels, threshold, nested_ner], outputs=output)
179
-
180
-
181
- if __name__ == "__main__":
182
-
183
- ner_interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
interfaces/open_ie.py DELETED
@@ -1,106 +0,0 @@
1
- from typing import Dict, Union
2
- from gliner import GLiNER
3
- import gradio as gr
4
-
5
- model = GLiNER.from_pretrained("knowledgator/gliner-multitask-v1.0").to("cpu")
6
-
7
- text1 = """
8
- "I recently purchased the Sony WH-1000XM4 Wireless Noise-Canceling Headphones from Amazon and I must say, I'm thoroughly impressed. The package arrived in New York within 2 days, thanks to Amazon Prime's expedited shipping.
9
-
10
- The headphones themselves are remarkable. The noise-canceling feature works like a charm in the bustling city environment, and the 30-hour battery life means I don't have to charge them every day. Connecting them to my Samsung Galaxy S21 was a breeze, and the sound quality is second to none.
11
-
12
- I also appreciated the customer service from Amazon when I had a question about the warranty. They responded within an hour and provided all the information I needed.
13
-
14
- However, the headphones did not come with a hard case, which was listed in the product description. I contacted Amazon, and they offered a 10% discount on my next purchase as an apology.
15
-
16
- Overall, I'd give these headphones a 4.5/5 rating and highly recommend them to anyone looking for top-notch quality in both product and service."""
17
-
18
- text2 = """
19
- Apple Inc. is an American multinational technology company headquartered in Cupertino, California. Apple is the world's largest technology company by revenue, with US$394.3 billion in 2022 revenue. As of March 2023, Apple is the world's biggest company by market capitalization. As of June 2022, Apple is the fourth-largest personal computer vendor by unit sales and the second-largest mobile phone manufacturer in the world. It is considered one of the Big Five American information technology companies, alongside Alphabet (parent company of Google), Amazon, Meta Platforms, and Microsoft.
20
- Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975 to develop and sell BASIC interpreters for the Altair 8800. During his career at Microsoft, Gates held the positions of chairman, chief executive officer, president and chief software architect, while also being the largest individual shareholder until May 2014.
21
- Apple was founded as Apple Computer Company on April 1, 1976, by Steve Wozniak, Steve Jobs (1955–2011) and Ronald Wayne to develop and sell Wozniak's Apple I personal computer. It was incorporated by Jobs and Wozniak as Apple Computer, Inc. in 1977. The company's second computer, the Apple II, became a best seller and one of the first mass-produced microcomputers. Apple went public in 1980 to instant financial success. The company developed computers featuring innovative graphical user interfaces, including the 1984 original Macintosh, announced that year in a critically acclaimed advertisement called "1984". By 1985, the high cost of its products, and power struggles between executives, caused problems. Wozniak stepped back from Apple and pursued other ventures, while Jobs resigned and founded NeXT, taking some Apple employees with him.
22
- """
23
-
24
- open_ie_examples = [
25
- [
26
- f"Extract all positive aspects of the product:",
27
- text1,
28
- 0.5,
29
- False
30
- ],
31
- [
32
- f"Extract all negative aspects of the product:",
33
- text1,
34
- 0.5,
35
- False
36
- ],
37
- [
38
- f"Find the name of the computer for which the first Microsoft product was developed:",
39
- text2,
40
- 0.5,
41
- False
42
- ]]
43
-
44
- def merge_entities(entities):
45
- if not entities:
46
- return []
47
- merged = []
48
- current = entities[0]
49
- for next_entity in entities[1:]:
50
- if next_entity['entity'] == current['entity'] and (next_entity['start'] == current['end'] + 1 or next_entity['start'] == current['end']):
51
- current['word'] += ' ' + next_entity['word']
52
- current['end'] = next_entity['end']
53
- else:
54
- merged.append(current)
55
- current = next_entity
56
- merged.append(current)
57
- return merged
58
-
59
- def process(
60
- prompt:str, text, threshold: float, nested_ner: bool, labels: str = ["match"]
61
- ) -> Dict[str, Union[str, int, float]]:
62
- text = prompt + "\n" + text
63
- r = {
64
- "text": text,
65
- "entities": [
66
- {
67
- "entity": entity["label"],
68
- "word": entity["text"],
69
- "start": entity["start"],
70
- "end": entity["end"],
71
- "score": 0,
72
- }
73
- for entity in model.predict_entities(
74
- text, labels, flat_ner=not nested_ner, threshold=threshold
75
- )
76
- ],
77
- }
78
- r["entities"] = merge_entities(r["entities"])
79
- return r
80
-
81
- with gr.Blocks(title="Open Information Extracting") as open_ie_interface:
82
- prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here")
83
- input_text = gr.Textbox(label="Text input", placeholder="Enter your text here")
84
- threshold = gr.Slider(0, 1, value=0.3, step=0.01, label="Threshold", info="Lower the threshold to increase how many entities get predicted.")
85
- nested_ner = gr.Checkbox(label="Nested NER", info="Allow for nested NER?")
86
- output = gr.HighlightedText(label="Predicted Entities")
87
- submit_btn = gr.Button("Submit")
88
- examples = gr.Examples(
89
- open_ie_examples,
90
- fn=process,
91
- inputs=[prompt, input_text, threshold, nested_ner],
92
- outputs=output,
93
- cache_examples=True
94
- )
95
- theme=gr.themes.Base()
96
-
97
- input_text.submit(fn=process, inputs=[prompt, input_text, threshold, nested_ner], outputs=output)
98
- prompt.submit(fn=process, inputs=[prompt, input_text, threshold, nested_ner], outputs=output)
99
- threshold.release(fn=process, inputs=[prompt, input_text, threshold, nested_ner], outputs=output)
100
- submit_btn.click(fn=process, inputs=[prompt, input_text, threshold, nested_ner], outputs=output)
101
- nested_ner.change(fn=process, inputs=[prompt, input_text, threshold, nested_ner], outputs=output)
102
-
103
-
104
- if __name__ == "__main__":
105
-
106
- open_ie_interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
interfaces/relation_e.py DELETED
@@ -1,107 +0,0 @@
1
- from utca.core import RenameAttribute
2
- from utca.implementation.predictors import (
3
- GLiNERPredictor,
4
- GLiNERPredictorConfig
5
- )
6
- from utca.implementation.tasks import (
7
- GLiNER,
8
- GLiNERPreprocessor,
9
- GLiNERRelationExtraction,
10
- GLiNERRelationExtractionPreprocessor,
11
- )
12
- from typing import Dict, Union
13
- import gradio as gr
14
-
15
- text = """
16
- Dr. Paul Hammond, a renowned neurologist at Johns Hopkins University, has recently published a paper in the prestigious journal \"Nature Neuroscience\".
17
- His research focuses on a rare genetic mutation, found in less than 0.01% of the population, that appears to prevent the development of Alzheimer's disease.
18
- Collaborating with researchers at the University of California, San Francisco, the team is now working to understand the mechanism by which this mutation confers its protective effect.
19
- Funded by the National Institutes of Health, their research could potentially open new avenues for Alzheimer's treatment.
20
- """
21
-
22
- predictor = GLiNERPredictor( # Predictor manages the model that will be used by tasks
23
- GLiNERPredictorConfig(
24
- model_name = "knowledgator/gliner-multitask-v1.0", # Model to use
25
- device = "cpu", # Device to use
26
- )
27
- )
28
-
29
- pipe = (
30
- GLiNER( # GLiNER task produces classified entities that will be at the "output" key.
31
- predictor=predictor,
32
- preprocess=GLiNERPreprocessor(threshold=0.7) # Entities threshold
33
- )
34
- | RenameAttribute("output", "entities") # Rename output entities from GLiNER task to use them as inputs in GLiNERRelationExtraction
35
- | GLiNERRelationExtraction( # GLiNERRelationExtraction is used for relation extraction.
36
- predictor=predictor,
37
- preprocess=(
38
- GLiNERPreprocessor(threshold=0.7) # Relations threshold
39
- | GLiNERRelationExtractionPreprocessor()
40
- )
41
- )
42
- )
43
-
44
-
45
- def process(
46
- relation: str, text, distance_threshold: str, pairs_filter: str, labels: str
47
- ) -> Dict[str, Union[str, int, float]]:
48
- pairs_filter = [tuple(pair.strip() for pair in pair.split("->")) for pair in pairs_filter.split(",")]
49
-
50
- if len(distance_threshold) < 1 or not distance_threshold or not distance_threshold.strip().isdigit():
51
- r = pipe.run({
52
- "text": text,
53
- "labels": [label.strip() for label in labels.split(",")],
54
- "relations": [{
55
- "relation": relation,
56
- "pairs_filter": pairs_filter
57
- }]
58
- })
59
- elif int(distance_threshold.strip()):
60
- r = pipe.run({
61
- "text": text,
62
- "labels": [label.strip() for label in labels.split(",")],
63
- "relations": [{
64
- "relation": relation,
65
- "pairs_filter": pairs_filter,
66
- "distance_threshold": int(distance_threshold.replace(" ", ""))
67
- }]
68
- })
69
-
70
- return r["output"]
71
-
72
- relation_e_examples = [
73
- [
74
- "worked at",
75
- text,
76
- "None",
77
- "scientist -> university, scientist -> other",
78
- "scientist, university, city, research, journal"]
79
- ]
80
-
81
- with gr.Blocks(title="Open Information Extracting") as relation_e_interface:
82
- relation = gr.Textbox(label="Relation", placeholder="Enter relation you want to extract here")
83
- input_text = gr.Textbox(label="Text input", placeholder="Enter your text here")
84
- labels = gr.Textbox(label="Labels", placeholder="Enter your labels here (comma separated)", scale=2)
85
- pairs_filter = gr.Textbox(label="Pairs Filter", placeholder="It specifies possible members of relations by their entity labels. Write as: source -> target,..")
86
- distance_threshold = gr.Textbox(label="Distance Threshold", placeholder="It specifies the max distance in characters between spans in the text")
87
- output = gr.Textbox(label="Predicted Relation")
88
- submit_btn = gr.Button("Submit")
89
- examples = gr.Examples(
90
- relation_e_examples,
91
- fn=process,
92
- inputs=[relation, input_text, distance_threshold, pairs_filter, labels],
93
- outputs=output,
94
- cache_examples=True
95
- )
96
- theme=gr.themes.Base()
97
-
98
- input_text.submit(fn=process, inputs=[relation, input_text, distance_threshold, pairs_filter, labels], outputs=output)
99
- labels.submit(fn=process, inputs=[relation, input_text, distance_threshold, pairs_filter, labels], outputs=output)
100
- pairs_filter.submit(fn=process, inputs=[relation, input_text, distance_threshold, pairs_filter, labels], outputs=output)
101
- submit_btn.click(fn=process, inputs=[relation, input_text, distance_threshold, pairs_filter, labels], outputs=output)
102
- distance_threshold.submit(fn=process, inputs=[relation, input_text, distance_threshold, pairs_filter, labels], outputs=output)
103
-
104
-
105
- if __name__ == "__main__":
106
-
107
- relation_e_interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
interfaces/summarization.py DELETED
@@ -1,102 +0,0 @@
1
- from typing import Dict, Union
2
- from gliner import GLiNER
3
- import gradio as gr
4
-
5
- model = GLiNER.from_pretrained("knowledgator/gliner-multitask-v1.0").to('cpu')
6
-
7
- text1 = """
8
- "I recently purchased the Sony WH-1000XM4 Wireless Noise-Canceling Headphones from Amazon and I must say, I'm thoroughly impressed. The package arrived in New York within 2 days, thanks to Amazon Prime's expedited shipping.
9
-
10
- The headphones themselves are remarkable. The noise-canceling feature works like a charm in the bustling city environment, and the 30-hour battery life means I don't have to charge them every day. Connecting them to my Samsung Galaxy S21 was a breeze, and the sound quality is second to none.
11
-
12
- I also appreciated the customer service from Amazon when I had a question about the warranty. They responded within an hour and provided all the information I needed.
13
-
14
- However, the headphones did not come with a hard case, which was listed in the product description. I contacted Amazon, and they offered a 10% discount on my next purchase as an apology.
15
-
16
- Overall, I'd give these headphones a 4.5/5 rating and highly recommend them to anyone looking for top-notch quality in both product and service."""
17
-
18
- text2 = """
19
- Apple Inc. is an American multinational technology company headquartered in Cupertino, California. Apple is the world's largest technology company by revenue, with US$394.3 billion in 2022 revenue. As of March 2023, Apple is the world's biggest company by market capitalization. As of June 2022, Apple is the fourth-largest personal computer vendor by unit sales and the second-largest mobile phone manufacturer in the world. It is considered one of the Big Five American information technology companies, alongside Alphabet (parent company of Google), Amazon, Meta Platforms, and Microsoft.
20
- Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975 to develop and sell BASIC interpreters for the Altair 8800. During his career at Microsoft, Gates held the positions of chairman, chief executive officer, president and chief software architect, while also being the largest individual shareholder until May 2014.
21
- Apple was founded as Apple Computer Company on April 1, 1976, by Steve Wozniak, Steve Jobs (1955–2011) and Ronald Wayne to develop and sell Wozniak's Apple I personal computer. It was incorporated by Jobs and Wozniak as Apple Computer, Inc. in 1977. The company's second computer, the Apple II, became a best seller and one of the first mass-produced microcomputers. Apple went public in 1980 to instant financial success. The company developed computers featuring innovative graphical user interfaces, including the 1984 original Macintosh, announced that year in a critically acclaimed advertisement called "1984". By 1985, the high cost of its products, and power struggles between executives, caused problems. Wozniak stepped back from Apple and pursued other ventures, while Jobs resigned and founded NeXT, taking some Apple employees with him.
22
- """
23
-
24
- open_ie_examples = [
25
- [
26
- f"Summarize the given text, highlighting the most important information:",
27
- text1,
28
- 0.25,
29
- False
30
- ],
31
- [
32
- f"Summarize the given text, highlighting the most important information:",
33
- text2,
34
- 0.4,
35
- False
36
- ]]
37
-
38
- def merge_entities(entities):
39
- if not entities:
40
- return []
41
- merged = []
42
- current = entities[0]
43
- for next_entity in entities[1:]:
44
- if next_entity['entity'] == current['entity'] and (next_entity['start'] == current['end'] + 1 or next_entity['start'] == current['end']):
45
- current['word'] += ' ' + next_entity['word']
46
- current['end'] = next_entity['end']
47
- else:
48
- merged.append(current)
49
- current = next_entity
50
- merged.append(current)
51
- return merged
52
-
53
- def process(
54
- question:str, text, threshold: float, nested_ner: bool, labels: str = ["summary"]
55
- ) -> Dict[str, Union[str, int, float]]:
56
- text = question + "\n" + text
57
-
58
- r = {
59
- "text": text,
60
- "entities": [
61
- {
62
- "entity": entity["label"],
63
- "word": entity["text"],
64
- "start": entity["start"],
65
- "end": entity["end"],
66
- "score": 0,
67
- }
68
- for entity in model.predict_entities(
69
- text, labels, flat_ner=not nested_ner, threshold=threshold
70
- )
71
- ],
72
- }
73
- r["entities"] = merge_entities(r["entities"])
74
- summary = " ".join(entity["word"] for entity in r["entities"])
75
- return summary, r
76
-
77
- with gr.Blocks(title="Open Information Extracting") as summarization_interface:
78
- prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here")
79
- input_text = gr.Textbox(label="Text input", placeholder="Enter your text here")
80
- threshold = gr.Slider(0, 1, value=0.3, step=0.01, label="Threshold", info="Lower the threshold to increase how many entities get predicted.")
81
- nested_ner = gr.Checkbox(label="Nested NER", info="Allow for nested NER?")
82
- output = [gr.Textbox(label="Summary"), gr.HighlightedText(label="Predicted Entities")]
83
- submit_btn = gr.Button("Submit")
84
- examples = gr.Examples(
85
- open_ie_examples,
86
- fn=process,
87
- inputs=[prompt, input_text, threshold, nested_ner],
88
- outputs=output,
89
- cache_examples=True
90
- )
91
- theme=gr.themes.Base()
92
-
93
- input_text.submit(fn=process, inputs=[prompt, input_text, threshold, nested_ner], outputs=output)
94
- prompt.submit(fn=process, inputs=[prompt, input_text, threshold, nested_ner], outputs=output)
95
- threshold.release(fn=process, inputs=[prompt, input_text, threshold, nested_ner], outputs=output)
96
- submit_btn.click(fn=process, inputs=[prompt, input_text, threshold, nested_ner], outputs=output)
97
- nested_ner.change(fn=process, inputs=[prompt, input_text, threshold, nested_ner], outputs=output)
98
-
99
-
100
- if __name__ == "__main__":
101
-
102
- summarization_interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
interfaces/universal.py DELETED
@@ -1,111 +0,0 @@
1
- from typing import Dict, Union
2
- from gliner import GLiNER
3
- import gradio as gr
4
-
5
- model = GLiNER.from_pretrained("knowledgator/gliner-multitask-v1.0").to('cpu')
6
-
7
- text1 = """
8
- "I recently purchased the Sony WH-1000XM4 Wireless Noise-Canceling Headphones from Amazon and I must say, I'm thoroughly impressed. The package arrived in New York within 2 days, thanks to Amazon Prime's expedited shipping.
9
-
10
- The headphones themselves are remarkable. The noise-canceling feature works like a charm in the bustling city environment, and the 30-hour battery life means I don't have to charge them every day. Connecting them to my Samsung Galaxy S21 was a breeze, and the sound quality is second to none.
11
-
12
- I also appreciated the customer service from Amazon when I had a question about the warranty. They responded within an hour and provided all the information I needed.
13
-
14
- However, the headphones did not come with a hard case, which was listed in the product description. I contacted Amazon, and they offered a 10% discount on my next purchase as an apology.
15
-
16
- Overall, I'd give these headphones a 4.5/5 rating and highly recommend them to anyone looking for top-notch quality in both product and service."""
17
-
18
- text2 = """
19
- Apple Inc. is an American multinational technology company headquartered in Cupertino, California. Apple is the world's largest technology company by revenue, with US$394.3 billion in 2022 revenue. As of March 2023, Apple is the world's biggest company by market capitalization. As of June 2022, Apple is the fourth-largest personal computer vendor by unit sales and the second-largest mobile phone manufacturer in the world. It is considered one of the Big Five American information technology companies, alongside Alphabet (parent company of Google), Amazon, Meta Platforms, and Microsoft.
20
- Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975 to develop and sell BASIC interpreters for the Altair 8800. During his career at Microsoft, Gates held the positions of chairman, chief executive officer, president and chief software architect, while also being the largest individual shareholder until May 2014.
21
- Apple was founded as Apple Computer Company on April 1, 1976, by Steve Wozniak, Steve Jobs (1955–2011) and Ronald Wayne to develop and sell Wozniak's Apple I personal computer. It was incorporated by Jobs and Wozniak as Apple Computer, Inc. in 1977. The company's second computer, the Apple II, became a best seller and one of the first mass-produced microcomputers. Apple went public in 1980 to instant financial success. The company developed computers featuring innovative graphical user interfaces, including the 1984 original Macintosh, announced that year in a critically acclaimed advertisement called "1984". By 1985, the high cost of its products, and power struggles between executives, caused problems. Wozniak stepped back from Apple and pursued other ventures, while Jobs resigned and founded NeXT, taking some Apple employees with him.
22
- """
23
-
24
- open_ie_examples = [
25
- [
26
- f"Extract all positive aspects of the product:",
27
- text1,
28
- 0.5,
29
- False,
30
- "match"
31
- ],
32
- [
33
- f"Extract all negative aspects of the product:",
34
- text1,
35
- 0.5,
36
- False,
37
- "match"
38
- ],
39
- [
40
- f"Find the name of the computer for which the first Microsoft product was developed:",
41
- text2,
42
- 0.5,
43
- False,
44
- "match"
45
- ]]
46
-
47
- def merge_entities(entities):
48
- if not entities:
49
- return []
50
- merged = []
51
- current = entities[0]
52
- for next_entity in entities[1:]:
53
- if next_entity['entity'] == current['entity'] and (next_entity['start'] == current['end'] + 1 or next_entity['start'] == current['end']):
54
- current['word'] += ' ' + next_entity['word']
55
- current['end'] = next_entity['end']
56
- else:
57
- merged.append(current)
58
- current = next_entity
59
- merged.append(current)
60
- return merged
61
-
62
- def process(
63
- prompt:str, text, threshold: float, nested_ner: bool, labels: str
64
- ) -> Dict[str, Union[str, int, float]]:
65
- text = prompt + "\n" + text
66
- labels = [label.strip() for label in labels.split(",")]
67
- r = {
68
- "text": text,
69
- "entities": [
70
- {
71
- "entity": entity["label"],
72
- "word": entity["text"],
73
- "start": entity["start"],
74
- "end": entity["end"],
75
- "score": 0,
76
- }
77
- for entity in model.predict_entities(
78
- text, labels, flat_ner=not nested_ner, threshold=threshold
79
- )
80
- ],
81
- }
82
- r["entities"] = merge_entities(r["entities"])
83
- return r
84
-
85
- with gr.Blocks(title="Open Information Extracting") as universal_interface:
86
- prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here")
87
- labels = gr.Textbox(label="Labels", placeholder="Enter your labels here (comma separated)", scale=2)
88
- input_text = gr.Textbox(label="Text input", placeholder="Enter your text here")
89
- threshold = gr.Slider(0, 1, value=0.3, step=0.01, label="Threshold", info="Lower the threshold to increase how many entities get predicted.")
90
- nested_ner = gr.Checkbox(label="Nested NER", info="Allow for nested NER?")
91
- output = gr.HighlightedText(label="Predicted Entities")
92
- submit_btn = gr.Button("Submit")
93
- examples = gr.Examples(
94
- open_ie_examples,
95
- fn=process,
96
- inputs=[prompt, input_text, threshold, nested_ner, labels],
97
- outputs=output,
98
- cache_examples=True
99
- )
100
- theme=gr.themes.Base()
101
-
102
- input_text.submit(fn=process, inputs=[prompt, input_text, threshold, nested_ner, labels], outputs=output)
103
- prompt.submit(fn=process, inputs=[prompt, input_text, threshold, nested_ner, labels], outputs=output)
104
- threshold.release(fn=process, inputs=[prompt, input_text, threshold, nested_ner, labels], outputs=output)
105
- submit_btn.click(fn=process, inputs=[prompt, input_text, threshold, nested_ner, labels], outputs=output)
106
- nested_ner.change(fn=process, inputs=[prompt, input_text, threshold, nested_ner, labels], outputs=output)
107
-
108
-
109
- if __name__ == "__main__":
110
-
111
- universal_interface.launch()