Spaces:
Sleeping
Sleeping
Update app_interface.py
Browse files- app_interface.py +101 -0
app_interface.py
CHANGED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from Summary import Summary
|
3 |
+
from NamedEntity import NER
|
4 |
+
|
5 |
+
text2 = ("UK law presumes the author of a copyright work to be the first owner. The law "
|
6 |
+
"also recognises that copyright works may be the product of joint authors and "
|
7 |
+
"co-authors. This means that as soon as the work is created, copyright in the work "
|
8 |
+
"belongs to the person or persons who created it. This is true even if the author "
|
9 |
+
"was hired to make the copyright work under a contract for services, such as a "
|
10 |
+
"wedding photographer. In the absence of an assignment of copyright via contract, "
|
11 |
+
"the wedding photographer retains copyright in the photographs, and the happy couple "
|
12 |
+
"merely gains physical prints of the pictures, and a right to privacy preventing the "
|
13 |
+
"issue, communication or exhibition of copies of the pictures to the public. There "
|
14 |
+
"are two exceptions to the presumption of first ownership: 1. The owner of copyright "
|
15 |
+
"in a work created by an employee in the course of his employment will be the "
|
16 |
+
"employer, unless there is an agreement to the contrary. This applies to literary, "
|
17 |
+
"dramatic, musical or artistic works, and films. It is not sufficient for the work "
|
18 |
+
"to have been created during working hours by an employee for the employer to own the "
|
19 |
+
"work, it must have been created as part of the job that employee was hired to do. "
|
20 |
+
"However, the employer may be able to make some claim to the work if the employee should "
|
21 |
+
"have been working for the employer at the time when he created the work, or if the "
|
22 |
+
"nature or subject matter of the work is so closely related to the type of employment "
|
23 |
+
"that the line between employment and private time becomes blurred. For these reasons "
|
24 |
+
"it is important to address copyright in employment contracts where employees are likely "
|
25 |
+
"to be creating copyright works. 2. Her Majesty the Queen is the first owner of any "
|
26 |
+
"copyright in works created by officers or servants of the Crown. This includes any "
|
27 |
+
"copyright works created by civil servants, such as this copyright notice."
|
28 |
+
)
|
29 |
+
|
30 |
+
text = ("Mr Roberts had taken his dog for a walk in Hyde Park at around 9pm. "
|
31 |
+
"He saw a group of people shouting at Stephen - a guy who would shortly "
|
32 |
+
"have his Rolex watch and iPhone stolen by the same group of people "
|
33 |
+
"that had surrounded him. A lady named Fiona Walker was crossing the High "
|
34 |
+
"Street that runs alongside the park. She heard Mr Roberts shout for help "
|
35 |
+
"and called the police to assist.\n\n Constable Robbins arrived after about "
|
36 |
+
"20 minutes by which time the group had dispersed. Mr Roberts was able to "
|
37 |
+
"give a description of the people who had stolen Stephen's Rolex watch and iPhone. "
|
38 |
+
"He said that one of the people was wearing a blue Adidas t-shirt and another "
|
39 |
+
"was wearing a red Arsenal football cap. "
|
40 |
+
"It turned out the gang members hailed from Paddington and Mayfair and used Uber to "
|
41 |
+
"move around the area.\n\n"
|
42 |
+
"The gang leader had to appear at "
|
43 |
+
"the Old Bailey on 1st January 2021. He was sentenced to 3 years in prison "
|
44 |
+
"for robbery and assault by Judge Jennifer Sanderson."
|
45 |
+
)
|
46 |
+
|
47 |
+
entity_desc = ("This demo uses the [DSLIM BERT model](https://huggingface.co/dslim/bert-base-NER) "
|
48 |
+
"to identify named entities in a piece of text. It has been trained to recognise "
|
49 |
+
"four types of entities: location (LOC), organisations (ORG), person (PER) and "
|
50 |
+
"Miscellaneous (MISC). The model size is approximately 430Mb. \n\n"
|
51 |
+
"This model is free for commercial use. \n\n"
|
52 |
+
"A [larger model](https://huggingface.co/dslim/bert-large-NER) is also available (~1.3Gb)."
|
53 |
+
)
|
54 |
+
|
55 |
+
summary_desc = ("This demo uses the "
|
56 |
+
"[legal-bert-base-uncased model](https://huggingface.co/nlpaueb/legal-bert-base-uncased) "
|
57 |
+
"intended to assist legal NLP research, computational law, and legal technology "
|
58 |
+
"applications. The model size is approximately 500Mb. \n\n "
|
59 |
+
"The model was trained using 12Gb of diverse English legal text across a number of fields. "
|
60 |
+
"This model is free for commercial use. \n\n"
|
61 |
+
)
|
62 |
+
|
63 |
+
|
64 |
+
def process_entities(txt_data):
|
65 |
+
ner = NER(txt_data)
|
66 |
+
ner.entity_markdown()
|
67 |
+
|
68 |
+
entity_list = '\n'.join(ner.unique_entities)
|
69 |
+
|
70 |
+
heading = 'Entities highlighted in the original text'
|
71 |
+
output = f'## {heading} \n\n {ner.markdown}'
|
72 |
+
|
73 |
+
return entity_list, output
|
74 |
+
|
75 |
+
|
76 |
+
def process_summary(txt_data):
|
77 |
+
summary = Summary(txt_data)
|
78 |
+
result = summary.result
|
79 |
+
|
80 |
+
return 'The Summary'
|
81 |
+
|
82 |
+
|
83 |
+
with gr.Blocks() as demo:
|
84 |
+
with gr.Tab('Entities'):
|
85 |
+
gr.Markdown("# Named Entity Recognition")
|
86 |
+
with gr.Accordion("See Details", open=False):
|
87 |
+
gr.Markdown(entity_desc)
|
88 |
+
text_source = gr.Textbox(label="Text to analyse", value=text, lines=10)
|
89 |
+
text_entities = gr.Textbox(label="Unique entities", lines=3)
|
90 |
+
mk_output = gr.Markdown(label="Entities Highlighted", value='Highlighted entities appear here')
|
91 |
+
with gr.Row():
|
92 |
+
btn_sample_entity = gr.Button("Load Sample Text")
|
93 |
+
btn_clear_entity = gr.Button("Clear Data")
|
94 |
+
btn_entities = gr.Button("Get Entities", variant='primary')
|
95 |
+
|
96 |
+
# Event Handlers
|
97 |
+
btn_sample_entity.click(fn=lambda: text, outputs=[text_source])
|
98 |
+
btn_entities.click(fn=process_entities, inputs=[text_source], outputs=[text_entities, mk_output])
|
99 |
+
btn_clear_entity.click(fn=lambda: ('', '', ''), outputs=[text_source, text_entities, mk_output])
|
100 |
+
|
101 |
+
demo.launch()
|