Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Upload 26 files
Browse files- app.py +15 -0
- gradio_cached_examples/16/log.csv +4 -0
- gradio_cached_examples/25/log.csv +4 -0
- gradio_cached_examples/35/log.csv +3 -0
- gradio_cached_examples/45/log.csv +2 -0
- gradio_cached_examples/56/log.csv +4 -0
- gradio_cached_examples/60/log.csv +4 -0
- gradio_cached_examples/7/log.csv +3 -0
- interfaces/__init__.py +7 -0
- interfaces/__pycache__/__init__.cpython-310.pyc +0 -0
- interfaces/__pycache__/landing.cpython-310.pyc +0 -0
- interfaces/__pycache__/ner.cpython-310.pyc +0 -0
- interfaces/__pycache__/open_ie.cpython-310.pyc +0 -0
- interfaces/__pycache__/qa.cpython-310.pyc +0 -0
- interfaces/__pycache__/relation_e.cpython-310.pyc +0 -0
- interfaces/__pycache__/summ.cpython-310.pyc +0 -0
- interfaces/__pycache__/universal.cpython-310.pyc +0 -0
- interfaces/gradio_cached_examples/8/log.csv +3 -0
- interfaces/landing.py +32 -0
- interfaces/ner.py +114 -0
- interfaces/open_ie.py +106 -0
- interfaces/qa.py +89 -0
- interfaces/relation_e.py +107 -0
- interfaces/summarization.py +102 -0
- interfaces/universal.py +111 -0
- materials/introduction.html +73 -0
app.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
subprocess.run(["pip", "uninstall", "gradio"])
|
3 |
+
subprocess.run(["pip", "install", "utca>=0.1.0"])
|
4 |
+
subprocess.run(["pip", "install", "gradio==4.31.5"])
|
5 |
+
|
6 |
+
import gradio as gr
|
7 |
+
from interfaces import ner_interface, qa_interface, open_ie_interface, summarization_interface, landing_interface, relation_e_interface, universal_interface
|
8 |
+
|
9 |
+
demo = gr.TabbedInterface([landing_interface, ner_interface, qa_interface, open_ie_interface, summarization_interface, relation_e_interface, universal_interface],
|
10 |
+
["Introduction", "NER", "Question Answering", "Open Information Extracting", "Summarization", "Relation Extracting", "Universal Task"],
|
11 |
+
title="GLiNER HandyLab",
|
12 |
+
theme=gr.themes.Base())
|
13 |
+
|
14 |
+
demo.queue()
|
15 |
+
demo.launch(debug=True, share=True)
|
gradio_cached_examples/16/log.csv
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Predicted Entities,flag,username,timestamp
|
2 |
+
"[{""token"": ""\nDr. "", ""class_or_confidence"": null}, {""token"": ""Paul Hammond"", ""class_or_confidence"": ""neurologist""}, {""token"": "", a renowned neurologist at "", ""class_or_confidence"": null}, {""token"": ""Johns Hopkins University"", ""class_or_confidence"": ""university""}, {""token"": "", has recently published a paper in the prestigious journal \"""", ""class_or_confidence"": null}, {""token"": ""Nature Neuroscience"", ""class_or_confidence"": ""journal""}, {""token"": ""\"". His research focuses on a rare "", ""class_or_confidence"": null}, {""token"": ""genetic mutation"", ""class_or_confidence"": ""biological process""}, {""token"": "", found in less than 0.01% of the population, that appears to prevent the development of "", ""class_or_confidence"": null}, {""token"": ""Alzheimer's disease"", ""class_or_confidence"": ""disease""}, {""token"": "". Collaborating with researchers at the "", ""class_or_confidence"": null}, {""token"": ""University of California"", ""class_or_confidence"": ""university""}, {""token"": "", "", ""class_or_confidence"": null}, {""token"": ""San Francisco"", ""class_or_confidence"": ""city""}, {""token"": "", the team is now working to understand the mechanism by which this mutation confers its protective effect. Funded by the "", ""class_or_confidence"": null}, {""token"": ""National Institutes of Health"", ""class_or_confidence"": ""university""}, {""token"": "", their research could potentially open new avenues for Alzheimer's treatment.\n"", ""class_or_confidence"": null}]",,,2024-05-31 21:19:47.389544
|
3 |
+
"[{""token"": ""\n\""I recently purchased the "", ""class_or_confidence"": null}, {""token"": ""Sony WH-1000XM4 Wireless Noise-Canceling Headphones"", ""class_or_confidence"": ""product""}, {""token"": "" from "", ""class_or_confidence"": null}, {""token"": ""Amazon"", ""class_or_confidence"": ""brand""}, {""token"": "" and I must say, I'm thoroughly impressed. The package arrived in "", ""class_or_confidence"": null}, {""token"": ""New York"", ""class_or_confidence"": ""location""}, {""token"": "" within 2 days, thanks to "", ""class_or_confidence"": null}, {""token"": ""Amazon"", ""class_or_confidence"": ""brand""}, {""token"": "" Prime's expedited shipping.\n\nThe headphones themselves are remarkable. The "", ""class_or_confidence"": null}, {""token"": ""noise-canceling feature"", ""class_or_confidence"": ""features""}, {""token"": "" works like a charm in the bustling city environment, and the "", ""class_or_confidence"": null}, {""token"": ""30-hour battery life"", ""class_or_confidence"": ""features""}, {""token"": "" means I don't have to charge them every day. Connecting them to my "", ""class_or_confidence"": null}, {""token"": ""Samsung Galaxy S21"", ""class_or_confidence"": ""product""}, {""token"": "" was a breeze, and the sound quality is second to none.\n\nI also appreciated the customer service from "", ""class_or_confidence"": null}, {""token"": ""Amazon"", ""class_or_confidence"": ""brand""}, {""token"": "" when I had a question about the warranty. They responded within an hour and provided all the information I needed.\n\nHowever, the "", ""class_or_confidence"": null}, {""token"": ""headphones"", ""class_or_confidence"": ""product""}, {""token"": "" did not come with a hard case, which was listed in the product description. I contacted "", ""class_or_confidence"": null}, {""token"": ""Amazon"", ""class_or_confidence"": ""brand""}, {""token"": "", and they offered a 10% discount on my next purchase as an apology.\n\nOverall, I'd give these headphones a "", ""class_or_confidence"": null}, {""token"": ""4.5/5"", ""class_or_confidence"": ""rating""}, {""token"": "" rating and highly recommend them to anyone looking for top-notch quality in both product and service."", ""class_or_confidence"": null}]",,,2024-05-31 21:19:49.044543
|
4 |
+
"[{""token"": ""\nSeveral studies have reported its pharmacological activities, including anti-inflammatory, antimicrobial, and antitumoral effects.\nThe effect of E-anethole was studied in the osteosarcoma "", ""class_or_confidence"": null}, {""token"": ""MG-63 cell line"", ""class_or_confidence"": ""cell line""}, {""token"": "", and the antiproliferative activity was evaluated by an MTT assay.\nIt showed a "", ""class_or_confidence"": null}, {""token"": ""GI50"", ""class_or_confidence"": ""metric""}, {""token"": "" value of 60.25 \u03bcM 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.\nMoreover, the antitumoral activity of anethole was assessed against oral tumor "", ""class_or_confidence"": null}, {""token"": ""Ca9-22 cells"", ""class_or_confidence"": ""cell line""}, {""token"": "", and the cytotoxic effects were evaluated by MTT and LDH assays.\nIt demonstrated a "", ""class_or_confidence"": null}, {""token"": ""LD50"", ""class_or_confidence"": ""metric""}, {""token"": "" value of 8 \u03bcM, and cellular proliferation was 42.7% and 5.2% at anethole "", ""class_or_confidence"": null}, {""token"": ""concentrations"", ""class_or_confidence"": ""metric""}, {""token"": "" of 3 \u03bcM and 30 \u03bcM, respectively.\nIt 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 "", ""class_or_confidence"": null}, {""token"": ""p21WAF1"", ""class_or_confidence"": ""protein""}, {""token"": "", up-regulated p53 expression, and inhibited the EMT markers.\n"", ""class_or_confidence"": null}]",,,2024-05-31 21:19:51.221542
|
gradio_cached_examples/25/log.csv
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Predicted Entities,flag,username,timestamp
|
2 |
+
"[{""token"": ""Extract all positive aspects of the product:\n\n\""I recently purchased the Sony WH-1000XM4 Wireless Noise-Canceling Headphones from Amazon and I must say, I'm thoroughly impressed. "", ""class_or_confidence"": null}, {""token"": ""The package arrived in New York within 2 days"", ""class_or_confidence"": ""match""}, {""token"": "", thanks to Amazon Prime's expedited shipping.\n\nThe headphones themselves are remarkable. The "", ""class_or_confidence"": null}, {""token"": ""noise-canceling feature works like a charm in the bustling city environment"", ""class_or_confidence"": ""match""}, {""token"": "", and the "", ""class_or_confidence"": null}, {""token"": ""30-hour battery life"", ""class_or_confidence"": ""match""}, {""token"": "" means I don't have to charge them every day. "", ""class_or_confidence"": null}, {""token"": ""Connecting them to my Samsung Galaxy S21 was a breeze"", ""class_or_confidence"": ""match""}, {""token"": "", and the "", ""class_or_confidence"": null}, {""token"": ""sound quality is second to none"", ""class_or_confidence"": ""match""}, {""token"": "".\n\nI 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.\n\nHowever, 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.\n\nOverall, 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."", ""class_or_confidence"": null}]",,,2024-05-31 21:19:59.970805
|
3 |
+
"[{""token"": ""Extract all negative aspects of the product:\n\n\""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.\n\nThe 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.\n\nI 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.\n\nHowever, "", ""class_or_confidence"": null}, {""token"": ""the headphones did not come with a hard case"", ""class_or_confidence"": ""match""}, {""token"": "", which was listed in the product description. I contacted Amazon, and they offered a 10% discount on my next purchase as an apology.\n\nOverall, 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."", ""class_or_confidence"": null}]",,,2024-05-31 21:20:01.535806
|
4 |
+
"[{""token"": ""Find the name of the computer for which the first Microsoft product was developed:\n\nApple 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\u00a02023, 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.\nMicrosoft was founded by Bill Gates and Paul Allen on April 4, 1975 to develop and sell BASIC interpreters for the "", ""class_or_confidence"": null}, {""token"": ""Altair 8800"", ""class_or_confidence"": ""match""}, {""token"": "". 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.\nApple was founded as Apple Computer Company on April 1, 1976, by Steve Wozniak, Steve Jobs (1955\u20132011) 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.\n"", ""class_or_confidence"": null}]",,,2024-05-31 21:20:04.006805
|
gradio_cached_examples/35/log.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
Summary,Predicted Entities,flag,username,timestamp
|
2 |
+
"The package arrived in New York within 2 days, thanks to Amazon Prime's expedited shipping. 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. 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.","[{""token"": ""Summarize the given text, highlighting the most important information:\n\n\""I recently purchased the Sony WH-1000XM4 Wireless Noise-Canceling Headphones from Amazon and I must say, I'm thoroughly impressed. "", ""class_or_confidence"": null}, {""token"": ""The package arrived in New York within 2 days, thanks to Amazon Prime's expedited shipping."", ""class_or_confidence"": ""summary""}, {""token"": ""\n\nThe headphones themselves are remarkable. "", ""class_or_confidence"": null}, {""token"": ""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."", ""class_or_confidence"": ""summary""}, {""token"": "" Connecting them to my Samsung Galaxy S21 was a breeze, and the sound quality is second to none.\n\nI 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.\n\nHowever, 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.\n\n"", ""class_or_confidence"": null}, {""token"": ""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."", ""class_or_confidence"": ""summary""}, {""token"": """", ""class_or_confidence"": null}]",,,2024-05-31 21:20:12.667603
|
3 |
+
"Apple is the world's largest technology company by revenue, with US$394.3 billion in 2022 revenue. 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.","[{""token"": ""Summarize the given text, highlighting the most important information:\n\nApple Inc. is an American multinational technology company headquartered in Cupertino, California. "", ""class_or_confidence"": null}, {""token"": ""Apple is the world's largest technology company by revenue, with US$394.3 billion in 2022 revenue."", ""class_or_confidence"": ""summary""}, {""token"": "" As of March\u00a02023, Apple is the world's biggest company by market capitalization. "", ""class_or_confidence"": null}, {""token"": ""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."", ""class_or_confidence"": ""summary""}, {""token"": "" It is considered one of the Big Five American information technology companies, alongside Alphabet (parent company of Google), Amazon, Meta Platforms, and Microsoft.\nMicrosoft 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.\nApple was founded as Apple Computer Company on April 1, 1976, by Steve Wozniak, Steve Jobs (1955\u20132011) 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.\n"", ""class_or_confidence"": null}]",,,2024-05-31 21:20:15.170601
|
gradio_cached_examples/45/log.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
Predicted Relation,flag,username,timestamp
|
2 |
+
"[{'source': {'start': 5, 'end': 17, 'span': 'Paul Hammond', 'score': 0.9541130065917969, 'entity': 'scientist'}, 'relation': 'worked at', 'target': {'start': 45, 'end': 69, 'span': 'Johns Hopkins University', 'score': 0.9601001143455505, 'entity': 'university'}, 'score': 0.8696132302284241}]",,,2024-05-31 21:20:27.796814
|
gradio_cached_examples/56/log.csv
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Predicted Entities,flag,username,timestamp
|
2 |
+
"[{""token"": ""Extract all positive aspects of the product:\n\n\""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.\n\nThe 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.\n\nI 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.\n\nHowever, 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.\n\nOverall, 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."", ""class_or_confidence"": null}]",,,2024-05-31 21:20:41.275340
|
3 |
+
"[{""token"": ""Extract all negative aspects of the product:\n\n\""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.\n\nThe 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.\n\nI 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.\n\nHowever, "", ""class_or_confidence"": null}, {""token"": ""the headphones did not come with a hard case"", ""class_or_confidence"": ""match""}, {""token"": "", which was listed in the product description. I contacted Amazon, and they offered a 10% discount on my next purchase as an apology.\n\nOverall, 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."", ""class_or_confidence"": null}]",,,2024-05-31 21:20:42.941340
|
4 |
+
"[{""token"": ""Find the name of the computer for which the first Microsoft product was developed:\n\nApple 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\u00a02023, 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.\nMicrosoft was founded by Bill Gates and Paul Allen on April 4, 1975 to develop and sell BASIC interpreters for the "", ""class_or_confidence"": null}, {""token"": ""Altair 8800"", ""class_or_confidence"": ""match""}, {""token"": "". 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.\nApple was founded as Apple Computer Company on April 1, 1976, by Steve Wozniak, Steve Jobs (1955\u20132011) 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.\n"", ""class_or_confidence"": null}]",,,2024-05-31 21:20:45.506342
|
gradio_cached_examples/60/log.csv
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Predicted Entities,flag,username,timestamp
|
2 |
+
"[{""token"": ""Extract all positive aspects of the product:\n\n\""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.\n\nThe 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.\n\nI 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.\n\nHowever, 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.\n\nOverall, 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."", ""class_or_confidence"": null}]",,,2024-05-31 23:27:58.157081
|
3 |
+
"[{""token"": ""Extract all negative aspects of the product:\n\n\""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.\n\nThe 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.\n\nI 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.\n\nHowever, "", ""class_or_confidence"": null}, {""token"": ""the headphones did not come with a hard case"", ""class_or_confidence"": ""match""}, {""token"": "", which was listed in the product description. I contacted Amazon, and they offered a 10% discount on my next purchase as an apology.\n\nOverall, 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."", ""class_or_confidence"": null}]",,,2024-05-31 23:27:59.833082
|
4 |
+
"[{""token"": ""Find the name of the computer for which the first Microsoft product was developed:\n\nApple 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\u00a02023, 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.\nMicrosoft was founded by Bill Gates and Paul Allen on April 4, 1975 to develop and sell BASIC interpreters for the "", ""class_or_confidence"": null}, {""token"": ""Altair 8800"", ""class_or_confidence"": ""match""}, {""token"": "". 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.\nApple was founded as Apple Computer Company on April 1, 1976, by Steve Wozniak, Steve Jobs (1955\u20132011) 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.\n"", ""class_or_confidence"": null}]",,,2024-05-31 23:28:02.396082
|
gradio_cached_examples/7/log.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
Predicted Entities,flag,username,timestamp
|
2 |
+
"[{""token"": ""Who are the founders of Microsoft:\n\nApple 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\u00a02023, 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.\nMicrosoft was founded by "", ""class_or_confidence"": null}, {""token"": ""Bill Gates"", ""class_or_confidence"": ""answer""}, {""token"": "" and "", ""class_or_confidence"": null}, {""token"": ""Paul Allen"", ""class_or_confidence"": ""answer""}, {""token"": "" 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.\nApple was founded as Apple Computer Company on April 1, 1976, by Steve Wozniak, Steve Jobs (1955\u20132011) 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.\n"", ""class_or_confidence"": null}]",,,2024-05-31 21:19:36.728538
|
3 |
+
"[{""token"": ""Who are the founders of Apple?:\n\nApple 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\u00a02023, 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.\nMicrosoft 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.\nApple was founded as Apple Computer Company on April 1, 1976, by "", ""class_or_confidence"": null}, {""token"": ""Steve Wozniak"", ""class_or_confidence"": ""answer""}, {""token"": "", "", ""class_or_confidence"": null}, {""token"": ""Steve Jobs"", ""class_or_confidence"": ""answer""}, {""token"": "" (1955\u20132011) and "", ""class_or_confidence"": null}, {""token"": ""Ronald Wayne"", ""class_or_confidence"": ""answer""}, {""token"": "" 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.\n"", ""class_or_confidence"": null}]",,,2024-05-31 21:19:39.407538
|
interfaces/__init__.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
interfaces/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (478 Bytes). View file
|
|
interfaces/__pycache__/landing.cpython-310.pyc
ADDED
Binary file (1.33 kB). View file
|
|
interfaces/__pycache__/ner.cpython-310.pyc
ADDED
Binary file (5.74 kB). View file
|
|
interfaces/__pycache__/open_ie.cpython-310.pyc
ADDED
Binary file (5.44 kB). View file
|
|
interfaces/__pycache__/qa.cpython-310.pyc
ADDED
Binary file (4.27 kB). View file
|
|
interfaces/__pycache__/relation_e.cpython-310.pyc
ADDED
Binary file (3.75 kB). View file
|
|
interfaces/__pycache__/summ.cpython-310.pyc
ADDED
Binary file (5.52 kB). View file
|
|
interfaces/__pycache__/universal.cpython-310.pyc
ADDED
Binary file (5.7 kB). View file
|
|
interfaces/gradio_cached_examples/8/log.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
Summary,Predicted Entities,flag,username,timestamp
|
2 |
+
"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. 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. 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.","[{""token"": ""Summarize the given text, highlighting the most important information:\n\n\"""", ""class_or_confidence"": null}, {""token"": ""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."", ""class_or_confidence"": ""summary""}, {""token"": ""\n\nThe headphones themselves are remarkable. "", ""class_or_confidence"": null}, {""token"": ""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."", ""class_or_confidence"": ""summary""}, {""token"": "" Connecting them to my Samsung Galaxy S21 was a breeze, and the sound quality is second to none.\n\nI 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.\n\nHowever, 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.\n\n"", ""class_or_confidence"": null}, {""token"": ""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."", ""class_or_confidence"": ""summary""}, {""token"": """", ""class_or_confidence"": null}]",,,2024-05-31 20:59:50.572164
|
3 |
+
"Apple is the world's largest technology company by revenue, with US$394.3 billion in 2022 revenue. 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.","[{""token"": ""Summarize the given text, highlighting the most important information:\n\nApple Inc. is an American multinational technology company headquartered in Cupertino, California. "", ""class_or_confidence"": null}, {""token"": ""Apple is the world's largest technology company by revenue, with US$394.3 billion in 2022 revenue."", ""class_or_confidence"": ""summary""}, {""token"": "" As of March\u00a02023, Apple is the world's biggest company by market capitalization. "", ""class_or_confidence"": null}, {""token"": ""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."", ""class_or_confidence"": ""summary""}, {""token"": "" It is considered one of the Big Five American information technology companies, alongside Alphabet (parent company of Google), Amazon, Meta Platforms, and Microsoft.\nMicrosoft 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.\nApple was founded as Apple Computer Company on April 1, 1976, by Steve Wozniak, Steve Jobs (1955\u20132011) 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.\n"", ""class_or_confidence"": null}]",,,2024-05-31 20:59:53.095162
|
interfaces/landing.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-large-v0.5")
|
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
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-large-v0.5").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 |
+
text5,
|
35 |
+
"neurologist, scientist, gene, disease, biological process, city, journal, university",
|
36 |
+
0.5,
|
37 |
+
False
|
38 |
+
],
|
39 |
+
[
|
40 |
+
text1,
|
41 |
+
"product, brand, location, features, rating",
|
42 |
+
0.5,
|
43 |
+
False
|
44 |
+
],
|
45 |
+
[
|
46 |
+
text3,
|
47 |
+
"cell line, protein, metric, substance",
|
48 |
+
0.5,
|
49 |
+
False
|
50 |
+
]]
|
51 |
+
|
52 |
+
def merge_entities(entities):
|
53 |
+
if not entities:
|
54 |
+
return []
|
55 |
+
merged = []
|
56 |
+
current = entities[0]
|
57 |
+
for next_entity in entities[1:]:
|
58 |
+
if next_entity['entity'] == current['entity'] and (next_entity['start'] == current['end'] + 1 or next_entity['start'] == current['end']):
|
59 |
+
current['word'] += ' ' + next_entity['word']
|
60 |
+
current['end'] = next_entity['end']
|
61 |
+
else:
|
62 |
+
merged.append(current)
|
63 |
+
current = next_entity
|
64 |
+
merged.append(current)
|
65 |
+
return merged
|
66 |
+
|
67 |
+
def process(
|
68 |
+
text, labels: str, threshold: float, nested_ner: bool
|
69 |
+
) -> Dict[str, Union[str, int, float]]:
|
70 |
+
labels = [label.strip() for label in labels.split(",")]
|
71 |
+
r = {
|
72 |
+
"text": text,
|
73 |
+
"entities": [
|
74 |
+
{
|
75 |
+
"entity": entity["label"],
|
76 |
+
"word": entity["text"],
|
77 |
+
"start": entity["start"],
|
78 |
+
"end": entity["end"],
|
79 |
+
"score": 0,
|
80 |
+
}
|
81 |
+
for entity in model.predict_entities(
|
82 |
+
text, labels, flat_ner=not nested_ner, threshold=threshold
|
83 |
+
)
|
84 |
+
],
|
85 |
+
}
|
86 |
+
r["entities"] = merge_entities(r["entities"])
|
87 |
+
return r
|
88 |
+
|
89 |
+
with gr.Blocks(title="NER Task") as ner_interface:
|
90 |
+
input_text = gr.Textbox(label="Text input", placeholder="Enter your text here")
|
91 |
+
labels = gr.Textbox(label="Labels", placeholder="Enter your labels here (comma separated)", scale=2)
|
92 |
+
threshold = gr.Slider(0, 1, value=0.3, step=0.01, label="Threshold", info="Lower the threshold to increase how many entities get predicted.")
|
93 |
+
nested_ner = gr.Checkbox(label="Nested NER", info="Allow for nested NER?")
|
94 |
+
output = gr.HighlightedText(label="Predicted Entities")
|
95 |
+
submit_btn = gr.Button("Submit")
|
96 |
+
examples = gr.Examples(
|
97 |
+
ner_examples,
|
98 |
+
fn=process,
|
99 |
+
inputs=[input_text, labels, threshold, nested_ner],
|
100 |
+
outputs=output,
|
101 |
+
cache_examples=True
|
102 |
+
)
|
103 |
+
theme=gr.themes.Base()
|
104 |
+
|
105 |
+
input_text.submit(fn=process, inputs=[input_text, labels, threshold, nested_ner], outputs=output)
|
106 |
+
labels.submit(fn=process, inputs=[input_text, labels, threshold, nested_ner], outputs=output)
|
107 |
+
threshold.release(fn=process, inputs=[input_text, labels, threshold, nested_ner], outputs=output)
|
108 |
+
submit_btn.click(fn=process, inputs=[input_text, labels, threshold, nested_ner], outputs=output)
|
109 |
+
nested_ner.change(fn=process, inputs=[input_text, labels, threshold, nested_ner], outputs=output)
|
110 |
+
|
111 |
+
|
112 |
+
if __name__ == "__main__":
|
113 |
+
|
114 |
+
ner_interface.launch()
|
interfaces/open_ie.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-large-v0.5").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/qa.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-large-v0.5").to('cpu')
|
6 |
+
|
7 |
+
text2 = """
|
8 |
+
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.
|
9 |
+
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.
|
10 |
+
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.
|
11 |
+
"""
|
12 |
+
|
13 |
+
qa_examples = [
|
14 |
+
[
|
15 |
+
f"Who are the founders of Microsoft:",
|
16 |
+
text2,
|
17 |
+
0.1,
|
18 |
+
False
|
19 |
+
],
|
20 |
+
[
|
21 |
+
f"Who are the founders of Apple?:",
|
22 |
+
text2,
|
23 |
+
0.5,
|
24 |
+
False
|
25 |
+
]]
|
26 |
+
|
27 |
+
def merge_entities(entities):
|
28 |
+
if not entities:
|
29 |
+
return []
|
30 |
+
merged = []
|
31 |
+
current = entities[0]
|
32 |
+
for next_entity in entities[1:]:
|
33 |
+
if next_entity['entity'] == current['entity'] and (next_entity['start'] == current['end'] + 1 or next_entity['start'] == current['end']):
|
34 |
+
current['word'] += ' ' + next_entity['word']
|
35 |
+
current['end'] = next_entity['end']
|
36 |
+
else:
|
37 |
+
merged.append(current)
|
38 |
+
current = next_entity
|
39 |
+
merged.append(current)
|
40 |
+
return merged
|
41 |
+
|
42 |
+
def process(
|
43 |
+
question:str, text, threshold: float, nested_ner: bool, labels: str = ["answer"]
|
44 |
+
) -> Dict[str, Union[str, int, float]]:
|
45 |
+
text = question + "\n" + text
|
46 |
+
r = {
|
47 |
+
"text": text,
|
48 |
+
"entities": [
|
49 |
+
{
|
50 |
+
"entity": entity["label"],
|
51 |
+
"word": entity["text"],
|
52 |
+
"start": entity["start"],
|
53 |
+
"end": entity["end"],
|
54 |
+
"score": 0,
|
55 |
+
}
|
56 |
+
for entity in model.predict_entities(
|
57 |
+
text, labels, flat_ner=not nested_ner, threshold=threshold
|
58 |
+
)
|
59 |
+
],
|
60 |
+
}
|
61 |
+
r["entities"] = merge_entities(r["entities"])
|
62 |
+
return r
|
63 |
+
|
64 |
+
with gr.Blocks(title="Question Answering Task") as qa_interface:
|
65 |
+
question = gr.Textbox(label="Question", placeholder="Enter your question here")
|
66 |
+
input_text = gr.Textbox(label="Text input", placeholder="Enter your text here")
|
67 |
+
threshold = gr.Slider(0, 1, value=0.3, step=0.01, label="Threshold", info="Lower the threshold to increase how many entities get predicted.")
|
68 |
+
nested_ner = gr.Checkbox(label="Nested NER", info="Allow for nested NER?")
|
69 |
+
output = gr.HighlightedText(label="Predicted Entities")
|
70 |
+
submit_btn = gr.Button("Submit")
|
71 |
+
examples = gr.Examples(
|
72 |
+
qa_examples,
|
73 |
+
fn=process,
|
74 |
+
inputs=[question, input_text, threshold, nested_ner],
|
75 |
+
outputs=output,
|
76 |
+
cache_examples=True
|
77 |
+
)
|
78 |
+
theme=gr.themes.Base()
|
79 |
+
|
80 |
+
input_text.submit(fn=process, inputs=[question, input_text, threshold, nested_ner], outputs=output)
|
81 |
+
question.submit(fn=process, inputs=[question, input_text, threshold, nested_ner], outputs=output)
|
82 |
+
threshold.release(fn=process, inputs=[question, input_text, threshold, nested_ner], outputs=output)
|
83 |
+
submit_btn.click(fn=process, inputs=[question, input_text, threshold, nested_ner], outputs=output)
|
84 |
+
nested_ner.change(fn=process, inputs=[question, input_text, threshold, nested_ner], outputs=output)
|
85 |
+
|
86 |
+
|
87 |
+
if __name__ == "__main__":
|
88 |
+
|
89 |
+
qa_interface.launch()
|
interfaces/relation_e.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-large-v0.5", # 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
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-large-v0.5").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.5,
|
29 |
+
False
|
30 |
+
],
|
31 |
+
[
|
32 |
+
f"Summarize the given text, highlighting the most important information:",
|
33 |
+
text2,
|
34 |
+
0.5,
|
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
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-large-v0.5").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 |
+
"answer"
|
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()
|
materials/introduction.html
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>GLiNER HandyLab App Description</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
font-family: Arial, sans-serif;
|
10 |
+
margin: 10px;
|
11 |
+
line-height: 1.6;
|
12 |
+
}
|
13 |
+
.link-button {
|
14 |
+
display: inline-flex;
|
15 |
+
align-items: center; /* Center content vertically */
|
16 |
+
justify-content: center; /* Center content horizontally */
|
17 |
+
margin: 5px; /* Consistent margin around buttons */
|
18 |
+
padding: 8px 10px; /* Slightly reduced vertical padding */
|
19 |
+
background-color: white;
|
20 |
+
border: 1px solid grey;
|
21 |
+
color: #007bff;
|
22 |
+
text-decoration: none;
|
23 |
+
border-radius: 10px;
|
24 |
+
box-sizing: border-box;
|
25 |
+
height: 40px; /* Fixed height for uniformity */
|
26 |
+
flex: 0 0 auto; /* No grow, no shrink, automatic basis */
|
27 |
+
}
|
28 |
+
.link-button img {
|
29 |
+
max-height: 30px; /* Maximum height for images */
|
30 |
+
margin: 0; /* Remove any default margin */
|
31 |
+
padding: 0; /* Remove any default padding */
|
32 |
+
}
|
33 |
+
.links-container {
|
34 |
+
display: flex;
|
35 |
+
justify-content: center;
|
36 |
+
flex-wrap: nowrap; /* Prevent wrapping */
|
37 |
+
align-items: center; /* This should ensure vertical alignment */
|
38 |
+
width: 100%; /* Full width to accommodate all items */
|
39 |
+
margin-top: 10px; /* Some space above the container */
|
40 |
+
}
|
41 |
+
.discord-adjust {
|
42 |
+
transform: translateY(-2px); /* Moves the button slightly upwards */
|
43 |
+
}
|
44 |
+
</style>
|
45 |
+
</head>
|
46 |
+
<body>
|
47 |
+
<h2>Welcome to GLiNER HandyLab!</h2>
|
48 |
+
<h3>With GLiNER HandyLab, you can effortlessly handle following tasks:</h3>
|
49 |
+
<ol>
|
50 |
+
<li><b>Named Entity Recognition (NER):</b> Identifies and categorizes entities such as names, organizations, dates, and other specific items in the text.</li>
|
51 |
+
<li><b>Relation Extraction:</b> Detects and classifies relationships between entities within the text.</li>
|
52 |
+
<li><b>Summarization:</b> Extract the most important sentences that summarize the input text, capturing the essential information.</li>
|
53 |
+
<li><b>Sentiment Extraction:</b> Identify parts of the text that signalize a positive, negative, or neutral sentiment.</li>
|
54 |
+
<li><b>Key-Phrase Extraction:</b> Identifies and extracts important phrases and keywords from the text.</li>
|
55 |
+
<li><b>Question-answering:</b> Finding an answer in the text given a question.</li>
|
56 |
+
<li><b>Open Information Extraction:</b> Extracts pieces of text given an open prompt from a user, for example, product description extraction.</li>
|
57 |
+
</ol>
|
58 |
+
<h3>What is <a href="https://github.com/urchade/GLiNER">GLiNER</a> HandyLab?</h3>
|
59 |
+
<p>GLiNER HandyLab serves as a foundational showcase of our technological capabilities within the universal information extraction. It enployes the model <a href="https://huggingface.co/knowledgator/gliner-multitask-large-v0.5">"knowledgator/gliner-multitask-large-v0.5"</a>. GLiNER-Multitask is a model designed to extract various pieces of information from plain text based on a user-provided custom prompt. This versatile model leverages a bidirectional transformer encoder, similar to BERT, which ensures both high generalization and compute efficiency despite its compact size.<p>
|
60 |
+
<h3>Remember, information extraction is not just about data; it's about insights. Let's uncover those insights together!💫</h3>
|
61 |
+
<!-- Links Section -->
|
62 |
+
<div class="links-container">
|
63 |
+
<a href="https://www.knowledgator.com/" class="link-button" target="_blank"><img src="https://assets-global.website-files.com/65902be8ba48a05dfdb73331/6590476fcc8e8f35b2332781_Group%201000002504%20(1).png" alt="Visit our website"></a>
|
64 |
+
<a href="https://www.linkedin.com/company/knowledgator/" class="link-button" target="_blank"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/01/LinkedIn_Logo.svg/1280px-LinkedIn_Logo.svg.png" alt="Follow on LinkedIn"></a>
|
65 |
+
<a href="https://huggingface.co/knowledgator/" class="link-button" target="_blank"><img src="https://vectorseek.com/wp-content/uploads/2023/12/Hugging-Face-Logo-Vector.svg-.png" alt="Hugging Face Profile"></a>
|
66 |
+
<a href="https://twitter.com/knowledgator" class="link-button" target="_blank"><img src="https://freepnglogo.com/images/all_img/1691832278twitter-x-logo-png.png" alt="Follow on X"></a>
|
67 |
+
<a href="https://blog.knowledgator.com/" class="link-button" target="_blank"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Medium_%28website%29_logo.svg/2560px-Medium_%28website%29_logo.svg.png" alt="Follow on Medium"></a>
|
68 |
+
<a href="https://discord.com/invite/dkyeAgs9DG" class="link-button discord-adjust" target="_blank">
|
69 |
+
<img src="https://assets-global.website-files.com/6257adef93867e50d84d30e2/636e0b52aa9e99b832574a53_full_logo_blurple_RGB.png" alt="Join our Discord">
|
70 |
+
</a>
|
71 |
+
</div>
|
72 |
+
</body>
|
73 |
+
</html>
|