import gradio as gr from NamedEntity import NER text2 = ("UK law presumes the author of a copyright work to be the first owner. The law " "also recognises that copyright works may be the product of joint authors and " "co-authors. This means that as soon as the work is created, copyright in the work " "belongs to the person or persons who created it. This is true even if the author " "was hired to make the copyright work under a contract for services, such as a " "wedding photographer. In the absence of an assignment of copyright via contract, " "the wedding photographer retains copyright in the photographs, and the happy couple " "merely gains physical prints of the pictures, and a right to privacy preventing the " "issue, communication or exhibition of copies of the pictures to the public. There " "are two exceptions to the presumption of first ownership: 1. The owner of copyright " "in a work created by an employee in the course of his employment will be the " "employer, unless there is an agreement to the contrary. This applies to literary, " "dramatic, musical or artistic works, and films. It is not sufficient for the work " "to have been created during working hours by an employee for the employer to own the " "work, it must have been created as part of the job that employee was hired to do. " "However, the employer may be able to make some claim to the work if the employee should " "have been working for the employer at the time when he created the work, or if the " "nature or subject matter of the work is so closely related to the type of employment " "that the line between employment and private time becomes blurred. For these reasons " "it is important to address copyright in employment contracts where employees are likely " "to be creating copyright works. 2. Her Majesty the Queen is the first owner of any " "copyright in works created by officers or servants of the Crown. This includes any " "copyright works created by civil servants, such as this copyright notice." ) text = ("Mr Roberts had taken his dog for a walk in Hyde Park at around 9pm. " "He saw a group of people shouting at Stephen - a guy who would shortly " "have his Rolex watch and iPhone stolen by the same group of people " "that had surrounded him. A lady named Fiona Walker was crossing the High " "Street that runs alongside the park. She heard Mr Roberts shout for help " "and called the police to assist.\n\n Constable Robbins arrived after about " "20 minutes by which time the group had dispersed. Mr Roberts was able to " "give a description of the people who had stolen Stephen's Rolex watch and iPhone. " "He said that one of the people was wearing a blue Adidas t-shirt and another " "was wearing a red Arsenal football cap. " "It turned out the gang members hailed from Paddington and Mayfair and used Uber to " "move around the area.\n\n" "The gang leader had to appear at " "the Old Bailey on 1st January 2021. He was sentenced to 3 years in prison " "for robbery and assault by Judge Jennifer Sanderson." ) entity_desc = ("This demo uses the [DSLIM BERT model](https://huggingface.co/dslim/bert-base-NER) " "to identify named entities in a piece of text. It has been trained to recognise " "four types of entities: location (LOC), organisations (ORG), person (PER) and " "Miscellaneous (MISC). The model size is approximately 430Mb. \n\n" "This model is free for commercial use. \n\n" "A [larger model](https://huggingface.co/dslim/bert-large-NER) is also available (~1.3Gb)." ) summary_desc = ("This demo uses the " "[legal-bert-base-uncased model](https://huggingface.co/nlpaueb/legal-bert-base-uncased) " "intended to assist legal NLP research, computational law, and legal technology " "applications. The model size is approximately 500Mb. \n\n " "The model was trained using 12Gb of diverse English legal text across a number of fields. " "This model is free for commercial use. \n\n" ) def process_entities(txt_data): ner = NER(txt_data) ner.entity_markdown() entity_list = '\n'.join(ner.unique_entities) heading = 'Entities highlighted in the original text' output = f'## {heading} \n\n {ner.markdown}' return entity_list, output def process_summary(txt_data): return 'The Summary' with gr.Blocks() as demo: with gr.Tab('Entities'): gr.Markdown("# Named Entity Recognition") with gr.Accordion("See Details", open=False): gr.Markdown(entity_desc) text_source = gr.Textbox(label="Text to analyse", value=text, lines=10) text_entities = gr.Textbox(label="Unique entities", lines=3) mk_output = gr.Markdown(label="Entities Highlighted", value='Highlighted entities appear here') with gr.Row(): btn_sample_entity = gr.Button("Load Sample Text") btn_clear_entity = gr.Button("Clear Data") btn_entities = gr.Button("Get Entities", variant='primary') # Event Handlers btn_sample_entity.click(fn=lambda: text, outputs=[text_source]) btn_entities.click(fn=process_entities, inputs=[text_source], outputs=[text_entities, mk_output]) btn_clear_entity.click(fn=lambda: ('', '', ''), outputs=[text_source, text_entities, mk_output]) demo.launch()